Skip to content

Commit

Permalink
feat: support blog draft
Browse files Browse the repository at this point in the history
  • Loading branch information
maiste committed Dec 13, 2024
1 parent 0c4e017 commit 8eee6fd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
22 changes: 15 additions & 7 deletions bin/actions/blog.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ let file_to_action (module R : S.RESOLVER) path content =
(Pipeline.track_file R.Source.binary
>>> lift (fun () -> content)
>>> Yocaml_cmarkit.content_to_html ()
>>> Yocaml_jingoo.Pipeline.as_template
(module Blog)
(R.Source.template "blog.html")
>>> Yocaml_jingoo.Pipeline.as_template
(module Blog)
(R.Source.template "base.html"))
>>> Yocaml_jingoo.Pipeline.as_template (module Blog) (R.Source.template "blog.html")
>>> Yocaml_jingoo.Pipeline.as_template (module Blog) (R.Source.template "base.html")
)
;;

let extract_metadata_from_dir path = function
Expand All @@ -50,6 +47,13 @@ let generate_index (module R : S.RESOLVER) = function
Peak.v ~title path metadata
;;

let is_draft = function
| Tree.Dir _ -> false
| Tree.File { content; _ } ->
let metadata, _ = content in
Blog.is_draft metadata
;;

let compare_blog_data p1 p2 =
let m1 = Peak.metadata p1 in
let m2 = Peak.metadata p2 in
Expand All @@ -64,7 +68,11 @@ let compare_blog_data p1 p2 =
;;

let dir_to_action (module R : S.RESOLVER) path children content =
let index = List.map (generate_index (module R)) children in
let index =
children
|> List.filter (fun child -> not (is_draft child))
|> List.map (generate_index (module R))
in
let title, content = extract_metadata_from_dir path content in
let metadata = Section.v ~title index |> Section.sort ~f:compare_blog_data in
let section = metadata, content in
Expand Down
2 changes: 1 addition & 1 deletion bin/actions/syndicate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let fetch_posts (module R : S.RESOLVER) =
let ff acc path content =
let metadata, _ = content in
let path = R.truncate path 1 |> Path.abs |> R.Target.as_html_index_untouched in
(path, metadata) :: acc
if not @@ Blog.is_draft metadata then (path, metadata) :: acc else acc
in
let fd acc _path _content _children = acc in
Tree.fetch
Expand Down
8 changes: 6 additions & 2 deletions bin/model/blog.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ type t =
; description : string
; date : Archetype.Datetime.t
; lang : string option
; draft : bool
}

let title t = t.title
let description t = t.description
let date t = t.date
let lang t = t.lang
let is_draft t = t.draft

let neutral =
Data.Validation.fail_with ~given:"null" "Cannot be null"
Expand All @@ -26,8 +28,9 @@ let validate =
let+ title = required fields "title" string
and+ description = required fields "description" string
and+ date = required fields "date" Archetype.Datetime.validate
and+ lang = optional fields "lang" string in
{ title; description; date; lang })
and+ lang = optional fields "lang" string
and+ draft = optional_or fields "draft" ~default:false bool in
{ title; description; date; lang; draft })
;;

let normalize t =
Expand All @@ -37,6 +40,7 @@ let normalize t =
; "date", Archetype.Datetime.normalize t.date
; "lang", option string t.lang
; "has_lang", bool @@ Option.is_some t.lang
; "draft", bool t.draft
]
;;

Expand Down
6 changes: 6 additions & 0 deletions static/pages/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ care about it.

## 2024

## 2024-12-13

Support the `draft: <bool>` metadata with `Blog.t` elements. It allows testing
online without referencing them. Write a new blog post about the donations!
Yeah, being a bit productive on personal time :)

## 2024-12-08

Add the RSS2 flux as a syndication page. This allows users to have both _Atom_
Expand Down

0 comments on commit 8eee6fd

Please sign in to comment.