Skip to content

Commit

Permalink
chore: partial restructure with resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
maiste committed Aug 3, 2024
1 parent 98939e5 commit 1ba7df3
Show file tree
Hide file tree
Showing 22 changed files with 347 additions and 318 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Clean dir
run: |
rm -rf bin contents dune-project LICENSE maiste-web.opam maiste-web.opam.templatepages README.md templates
mv _build/public /tmp
mv target /tmp
mv _opam /tmp
# "--allow-empty" ensures we have a trace of when the CI is triggered.
Expand All @@ -38,7 +38,7 @@ jobs:
git fetch origin gh-pages
git switch gh-pages
rm -rf ./*
mv /tmp/public/* ./
mv /tmp/target/* ./
git add -A .
git commit -m "Blog v$(date +'%Y-%m-%d')" --allow-empty
git push origin gh-pages
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# OCaml
_build/
_opam/

# Export
target/
121 changes: 121 additions & 0 deletions bin/actions.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
open Yocaml

(* FIXME: turn me into a First class module *)
module P = Resolver.Make (struct
let source = Path.rel []
let target = Path.rel [ "target" ]
end)

module Blog = struct
module Index = Index.Blog
module Model = Model.Blog

module Tree = struct
let years = [ "2021"; "2022" ]
let source year = Path.(P.Source.blog / year)

let target year file =
let into = Path.(P.Target.blog / year) in
P.Target.as_html_index ~into file
;;

let index = Path.(P.Target.blog / "index.html")
end

let process_index ~title path =
let file_target =
Path.(P.(truncate_and_move ~into:Target.root path 1) / "index.html")
in
let open Task in
Action.write_static_file
file_target
(Pipeline.track_file P.Source.binary
>>> Index.compute_index ~title path
>>> Yocaml_jingoo.Pipeline.as_template
(module Index)
(P.Source.template "blog.section.html")
>>> Yocaml_jingoo.Pipeline.as_template
(module Index)
(P.Source.template "base.html")
>>> drop_first ())
;;

let process_post year file =
let file_target = Tree.target year file in
let open Task in
Action.write_static_file
file_target
(Pipeline.track_file P.Source.binary
>>> Yocaml_yaml.Pipeline.read_file_with_metadata (module Model) file
>>> Yocaml_cmarkit.content_to_html ()
>>> Yocaml_jingoo.Pipeline.as_template
(module Model)
(P.Source.template "blog.html")
>>> Yocaml_jingoo.Pipeline.as_template
(module Model)
(P.Source.template "base.html")
>>> drop_first ())
;;

let process_posts : Action.t =
let f year =
let path = Tree.source year in
let process_post = process_post year in
Generator.process_markdown ~only:`Files path process_post
in
List.map f Tree.years |> Generator.process_actions
;;

(* Extract index from loop *)
let process : Action.t =
let open Eff in
fun cache ->
process_posts cache
>>= process_index ~title:"Blog" P.Source.blog
>>= process_index ~title:"2021" (P.Source.posts "2021")
>>= process_index ~title:"2022" (P.Source.posts "2022")
;;
end

module Css = struct
let process =
Action.batch
~only:`Files
~where:Rule.is_css
P.Source.css
(Action.copy_file ~into:P.Target.css)
;;
end

module Wiki = struct
let process_page ~into file =
let file_target = P.Target.(as_html_index ~into file) in
let open Task in
Action.write_static_file
file_target
(Pipeline.track_file P.Source.binary
>>> Yocaml_yaml.Pipeline.read_file_with_metadata (module Archetype.Page) file
>>> Yocaml_cmarkit.content_to_html ()
>>> Yocaml_jingoo.Pipeline.as_template
(module Archetype.Page)
(P.Source.template "page.html")
>>> Yocaml_jingoo.Pipeline.as_template
(module Archetype.Page)
(P.Source.template "base.html")
>>> drop_first ())
;;

let process_books : Action.t =
Generator.process_markdown
~only:`Files
(P.Source.wiki_section "books")
(process_page ~into:(P.Target.wiki_section "books"))
;;

let process = process_books
end

let eval cache =
let open Eff in
Blog.process cache >>= Css.process >>= Wiki.process
;;
164 changes: 0 additions & 164 deletions bin/blog.ml

This file was deleted.

84 changes: 0 additions & 84 deletions bin/core.ml

This file was deleted.

Loading

0 comments on commit 1ba7df3

Please sign in to comment.