Skip to content

Commit

Permalink
Add ATOM feed
Browse files Browse the repository at this point in the history
  • Loading branch information
gr-im committed Aug 6, 2024
1 parent 38b53fa commit 7247af1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,13 @@ ol.bibliography > li .authors > li:first-child::before {
.articles-list > li > p {
font-style: italic;
}

.atom-btn {
margin-top: 12px;
display: inline-block;
background-color: #ff6600;
color: white;
text-decoration: none;
padding: 2px 4px;
font-weight: 900;
}
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name generator)
(public_name site.generator)
(libraries yocaml yocaml_yaml yocaml_jingoo yocaml_omd))
(libraries yocaml yocaml_yaml yocaml_jingoo yocaml_omd yocaml_syndication))
30 changes: 30 additions & 0 deletions lib/repr.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
open Yocaml

let base_url = "https://gr-im.github.io"
let feed_url = base_url ^ "/" ^ "atom.xml"

let owner =
Yocaml_syndication.Person.make ~uri:base_url ~email:"[email protected]" "Grim"

module Page = struct
type t = { title : string; description : string; tags : string list }

Expand Down Expand Up @@ -120,6 +126,17 @@ module Article = struct
^ Bib.to_string meta.bib ))

let compare { date = a; _ } { date = b; _ } = Archetype.Datetime.compare a b

let to_atom_entry (url, { page; date; _ }) =
let open Yocaml_syndication in
let title = page.title in
let url = base_url ^ Path.to_string url in
let updated = Datetime.make date in
let categories = List.map Category.make page.tags in
let summary = Atom.text page.description in
let links = [ Atom.alternate url ~title ] in
Atom.entry ~links ~categories ~summary ~updated ~id:url
~title:(Atom.text title) ()
end

module Articles = struct
Expand Down Expand Up @@ -178,4 +195,17 @@ module Articles = struct
let index path =
let open Task in
lift (fun x -> (x, ())) >>> second (fetch path) >>> from_page

let to_atom path =
let open Task in
let open Yocaml_syndication in
let id = feed_url in
let title = Atom.text "Grim's web corner" in
let subtitle = Atom.text "Notes, essays and ramblings" in
let links = [ Atom.self feed_url; Atom.link base_url ] in
let updated = Atom.updated_from_entries () in
let authors = Yocaml.Nel.singleton owner in
fetch path
>>> Atom.from ~updated ~title ~subtitle ~id ~links ~authors
Article.to_atom_entry
end
1 change: 1 addition & 0 deletions lib/repr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Articles : sig
type t

val index : Yocaml.Path.t -> (Page.t, t) Yocaml.Task.t
val to_atom : Yocaml.Path.t -> (unit, string) Yocaml.Task.t

include Yocaml.Required.DATA_READABLE with type t := t
include Yocaml.Required.DATA_INJECTABLE with type t := t
Expand Down
6 changes: 6 additions & 0 deletions lib/rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ let articles ~target =
Action.batch ~only:`Files ~where:(Path.has_extension "md")
(Path.rel [ "articles" ]) (article ~target)

let atom ~target =
Action.write_static_file
Path.(target / "atom.xml")
(Repr.Articles.to_atom (Path.rel [ "articles" ]))

let index ~target =
let articles = Path.rel [ "articles" ] in
Action.write_static_file
Expand Down Expand Up @@ -79,4 +84,5 @@ let all ~target () =
>>= pages ~target
>>= articles ~target
>>= index ~target
>>= atom ~target
>>= Action.store_cache cache
1 change: 1 addition & 0 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ <h2><a href="/">Grim's web corner</a></h2>
<a href="https://ring.muhokama.fun/u/grm/pred">Pred</a> |
<a href="https://ring.muhokama.fun/u/grm/succ">Succ</a>
</p>
<a class="atom-btn" href="/atom.xml">atom</a>
</footer>
</body>
</html>

0 comments on commit 7247af1

Please sign in to comment.