~srpablo/fleaswallow

97369a4c0ab8f76c422fb2d1d5175fb5aa9fd0b3 — Pablo Meier 10 months ago 799ac84 master
FFS Jane Street quit fucking with me
M src/dune => src/dune +1 -1
@@ 1,5 1,5 @@
(executable
 (name fleaswallow)
 (libraries fleaswallow_lib)
 (libraries fleaswallow_lib core_unix.command_unix)
 (preprocess
  (pps ppx_let ppx_jane)))

M src/fleaswallow.ml => src/fleaswallow.ml +1 -1
@@ 51,4 51,4 @@ Below are the files it expects.
      toplevel title should_build should_debug]


let () = Command.run ~version:"1.0" ~build_info:"P4BLO" command
let () = Command_unix.run ~version:"1.0" ~build_info:"P4BLO" command

M src/fleaswallow_lib/builder.ml => src/fleaswallow_lib/builder.ml +4 -4
@@ 1,5 1,5 @@
open Core
open Unix
open Core_unix
open Jingoo

(** TODOs:


@@ 85,7 85,7 @@ let index_post_model model post =
  let id = generate_urn [Model.hostname model; url] in
  let datestring = Post.datetime post |> Utils.format_date_index in
  let publish_date_iso =
    Post.datetime post |> Unix.mktime |> Utils.fst |> ISO8601.Permissive.string_of_datetime
    Post.datetime post |> Core_unix.mktime |> Utils.fst |> ISO8601.Permissive.string_of_datetime
  in
  let description = Post.og_description post |> or_string ~default:(Utils.get_desc content_md) in
  let content = content_md |> Utils.add_newlines |> Utils.cmark_from_string in


@@ 150,7 150,7 @@ let generate_index_pages model =
(** Generates the blog's individual post pages **)
let generate_post_pages model =
  let () = Logs.info (fun m -> m "Building post pages…") in
  let today_now = Unix.time () |> Unix.gmtime in
  let today_now = Core_unix.time () |> Core_unix.gmtime in
  let is_old x = today_now.tm_year - x.tm_year > 1 in
  let prev_next_url = function
    | None -> Jg_types.Tnull


@@ 339,7 339,7 @@ let generate_sitemap model =


let build model =
  let () = Model.build_dir model |> Unix.mkdir_p in
  let () = Model.build_dir model |> Core_unix.mkdir_p in
  let output_funcs =
    [
      generate_post_pages;

M src/fleaswallow_lib/cache.ml => src/fleaswallow_lib/cache.ml +5 -5
@@ 3,7 3,7 @@ open Core
type last_modified_map = int String.Map.t

(* The in-memory representation of a cache is a map from source file (as a
 * string) to last modified time (as an int). Unix.stat
 * string) to last modified time (as an int). Core_unix.stat
 * returns a _float_ number of seconds since epoch in "last modified time"
 * but we'll truncate it for simplicity; I doubt we'll need sub-second granularity here.
 * *)


@@ 28,7 28,7 @@ let get_cache directory =
  | true ->
      cache_location |> Files.file_contents |> Option.value_exn |> Files.lines |> inifile_to_cache
  | false ->
      let _ = Unix.with_file cache_location ~mode:[O_RDWR; O_CREAT] ~f:(fun _ -> ()) in
      let _ = Core_unix.with_file cache_location ~mode:[O_RDWR; O_CREAT] ~f:(fun _ -> ()) in
      inifile_to_cache []




@@ 40,9 40,9 @@ let get_cache directory =
 * and that post itself.
 * *)
let model_updates cache filepath =
  let current_time = Unix.time () |> Unix.gmtime in
  let current_time = Core_unix.time () |> Core_unix.gmtime in
  let is_fresh source =
    match Unix.stat source, Map.find cache source with
    match Core_unix.stat source, Map.find cache source with
    | _, None -> true, source
    | { st_mtime; _ }, Some cache_generated ->
        let mtime_as_int = st_mtime |> int_of_float in


@@ 132,7 132,7 @@ let update_cache model =
  let freshen_cache old_cache =
    (* let config_sources = [ Model.title; Model.description; Model.author; Model.hostname;
       Model.build_dir; Model.default_og_image; ] in *)
    let as_int_string timestamp = timestamp |> Unix.timegm |> int_of_float in
    let as_int_string timestamp = timestamp |> Core_unix.timegm |> int_of_float in
    let template_updates =
      [
        Model.index_template, "./templates/index-template.tmpl";

M src/fleaswallow_lib/dune => src/fleaswallow_lib/dune +1 -1
@@ 1,7 1,7 @@
(library
 (name fleaswallow_lib)
 (inline_tests)
 (libraries core re2 cmarker jingoo fileutils inifiles ISO8601 logs)
 (libraries core core_unix core_unix.sys_unix re2 cmarker jingoo fileutils inifiles ISO8601 logs)
 (preprocess (pps ppx_let ppx_inline_test ppx_expect base_quickcheck.ppx_quickcheck
              ppx_stable ppx_assert ppx_bench ppx_bin_prot ppx_custom_printf
              ppx_fields_conv ppx_here ppx_inline_test ppx_let

M src/fleaswallow_lib/files.ml => src/fleaswallow_lib/files.ml +6 -5
@@ 1,4 1,5 @@
open Core
open Core_unix
open Filename
open Re2



@@ 11,7 12,7 @@ type file_with_contents = {
type t = file_with_contents

let to_record filename =
  let stat_record = Unix.stat filename in
  let stat_record = Core_unix.stat filename in
  {
    name = filename;
    lines = In_channel.read_lines filename;


@@ 33,7 34,7 @@ let file_contents path =


let check_exists path =
  match Sys.file_exists ~follow_symlinks:true path with
  match Sys_unix.file_exists ~follow_symlinks:true path with
  | `No -> false
  | `Yes
  | `Unknown ->


@@ 46,7 47,7 @@ let whitelist_regexes = List.map ~f:(Re2.create_exn ~options:Options.default) wh

let in_whitelist x = List.exists whitelist_regexes ~f:(fun y -> Re2.matches y x)

let dir_contents dir_name = dir_name |> Sys.readdir |> Array.to_list
let dir_contents dir_name = dir_name |> Sys_unix.readdir |> Array.to_list

(** Retrieves files from a directory and their contents as lines *)
let file_contents_in_dir dirname =


@@ 59,7 60,7 @@ let file_contents_in_dir dirname =

let write_out_to_file build_dir (path, content) =
  let filename = Filename.concat build_dir path in
  let () = Unix.mkdir_p (dirname filename) in
  let () = Core_unix.mkdir_p (dirname filename) in
  Out_channel.write_all filename ~data:content




@@ 79,7 80,7 @@ let copy_static_dir_if_necessary toplevel build_dir =
      | false -> 
        FileUtil.cp ~force:Force ~recurse:true ~preserve:true [full_name] left_dir
      | true -> 
          match (Unix.stat full_name).st_kind with
          match (Core_unix.stat full_name).st_kind with
          | S_REG ->
              ()
          | S_DIR -> 

M src/fleaswallow_lib/fleaswallow_lib.ml => src/fleaswallow_lib/fleaswallow_lib.ml +1 -1
@@ 27,7 27,7 @@ let create_new_post name =
  let basename =
    String.concat
      ~sep:"-"
      [Unix.gettimeofday () |> Unix.gmtime |> Utils.format_date_index; Utils.dasherized name]
      [Core_unix.gettimeofday () |> Core_unix.gmtime |> Utils.format_date_index; Utils.dasherized name]
  in
  let filepath = conflict_free_filename posts_directory basename in
  let () = Files.write_out_to_file "./" (filepath, body) in

M src/fleaswallow_lib/model.ml => src/fleaswallow_lib/model.ml +2 -2
@@ 1,7 1,7 @@
open Core

type 'a source =
  | Fresh of 'a * Unix.tm
  | Fresh of 'a * Core_unix.tm
  | Cached of 'a

type blog_metadata = {


@@ 111,7 111,7 @@ let build_blog_model_cached
  let template_string x = x |> Files.file_contents |> Option.value_exn |> Files.contents in
  let _, conf_path = config_fresh in
  let conf = read_config_values conf_path in
  let current_time = Unix.gettimeofday () |> Unix.gmtime in
  let current_time = Core_unix.gettimeofday () |> Core_unix.gmtime in
  let config_field x =
    match config_fresh with
    | true, _ -> Fresh (x, current_time)

M src/fleaswallow_lib/model.mli => src/fleaswallow_lib/model.mli +1 -1
@@ 1,7 1,7 @@
open Core

type 'a source =
  | Fresh of 'a * Unix.tm
  | Fresh of 'a * Core_unix.tm
  | Cached of 'a

type t

M src/fleaswallow_lib/post.ml => src/fleaswallow_lib/post.ml +4 -4
@@ 7,7 7,7 @@ type post_body =

type post = {
  title: string;
  datetime: Unix.tm;
  datetime: Core_unix.tm;
  last_modified: int;
  tags: string list;
  og_image: string option;


@@ 119,7 119,7 @@ let handle_metadata data =
    |> Re2.rewrite_exn to_tagify ~template:"_"
    |> Re2.rewrite_exn trailing_underscore ~template:""
  in
  let to_datetime = Fn.compose Unix.gmtime (ISO8601.Permissive.datetime ~reqtime:true) in
  let to_datetime = Fn.compose Core_unix.gmtime (ISO8601.Permissive.datetime ~reqtime:true) in
  let title = metadata_handle "Title" |> Option.value_exn in
  let datetime = metadata_handle "Date" |> Option.value_exn |> to_datetime in
  let tags =


@@ 153,7 153,7 @@ let make_post file =

(** Inverting the normal sort order since we want them in descending order *)
let compare_post_dates { datetime = datetime1; _ } { datetime = datetime2; _ } =
  let tm x = Unix.mktime x |> Utils.fst in
  let tm x = Core_unix.mktime x |> Utils.fst in
  compare_float (tm datetime1) (tm datetime2)




@@ 222,7 222,7 @@ let post_to_string
    }
  =
  let get_timestring x =
    Unix.mktime x |> (fun (x, _) -> x) |> ISO8601.Permissive.string_of_datetime
    Core_unix.mktime x |> (fun (x, _) -> x) |> ISO8601.Permissive.string_of_datetime
  in
  let time_str = get_timestring datetime in
  let tag_string = Utils.from_string_list tags in

M src/fleaswallow_lib/post.mli => src/fleaswallow_lib/post.mli +1 -2
@@ 1,4 1,3 @@
open Core
(** The bread-and-butter of any blog is a post. This module contains a
 * datatype to create and manipulate posts as logical entities.
 *)


@@ 13,7 12,7 @@ type post_body =
val title : t -> string
(** Get the post title. *)

val datetime : t -> Unix.tm
val datetime : t -> Core_unix.tm
(** Get the post's publish date. *)

val last_modified : t -> int

M src/fleaswallow_lib/utils.ml => src/fleaswallow_lib/utils.ml +2 -2
@@ 1,5 1,5 @@
open Core
open Unix
open Core_unix

(** Writable list from a string list *)
let from_string_list input =


@@ 56,7 56,7 @@ let format_date_index { tm_mon; tm_mday; tm_year; _ } =


(** Prints the current time as an ISO date *)
let current_time_as_iso () = Unix.gettimeofday () |> ISO8601.Permissive.string_of_datetime
let current_time_as_iso () = Core_unix.gettimeofday () |> ISO8601.Permissive.string_of_datetime

let to_dasherize = Re2.create_exn "[^a-zA-Z0-9]+"
let trailing_dash = Re2.create_exn "-$"