-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from muhokama/add-blog
Add a federated blog
- Loading branch information
Showing
28 changed files
with
524 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
title: Guarded methods using equality witnesses | ||
synopsis: Guarded methods allow constraints to be attached to the receiver | ||
(self) only for certain methods, so that these methods can only | ||
be called if the receiver satisfies these constraints (these guards). | ||
OCaml does not syntactically allow this type of method to be defined | ||
directly. In this note, we'll look at how to encode them using a | ||
type equality witness. | ||
date: 2022-05-29 | ||
authors: [xvw] | ||
link: | ||
url: https://xvw.lol/pages/oop-refl.html | ||
lang: fra | ||
tags: [ocaml, oop, refl, gadt] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
title: OCaml, modules and import schemes | ||
synopsis: In this article, we're going to look at how generalised openings | ||
can be used to reproduce a common practice in other languages, | ||
which I call, somewhat pompously, import strategies, | ||
date: 2023-10-31 | ||
authors: [xvw] | ||
link: | ||
url: https://xvw.lol/pages/modules-import.html | ||
lang: fra | ||
tags: [ocaml, module] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: Effective ML Through Merlin's Destruct Command | ||
synopsis: This article presents the use of the destruct command in Merlin | ||
and OCaml-lsp to generate missing patterns, or to specify patterns in | ||
pattern matching. | ||
date: 2024-05-29 | ||
authors: [xvw] | ||
link: https://tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/ | ||
tags: [ocaml, lsp, ide, emacs, vscode, vim, merlin] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
page_title: Blog | ||
description: A federated blog of Webring's member | ||
--- | ||
|
||
The **Federated Blog** allows [webring members](/) to showcase federated | ||
articles on this page from _time to time_. The list of articles is not | ||
calculated automatically (via RSS/Atom feeds) but is the result of **a manual | ||
addition**. You can retrieve the [ATOM feed from the federated blog](/atom.xml). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
let run (module R : Sigs.RESOLVER) chain = | ||
Yocaml.Action.write_static_file R.Target.blog | ||
(let open Yocaml.Task in | ||
R.track_common_dependencies | ||
>>> Yocaml.Pipeline.track_file R.Source.articles | ||
>>> Yocaml_yaml.Pipeline.read_file_with_metadata | ||
(module Model.Page) | ||
R.Source.blog | ||
>>> first @@ Model.Articles.index chain R.Source.articles | ||
>>> Yocaml_omd.content_to_html () | ||
>>> Yocaml_jingoo.Pipeline.as_template | ||
(module Model.Articles) | ||
(R.Source.template "blog.html") | ||
>>> Yocaml_jingoo.Pipeline.as_template | ||
(module Model.Articles) | ||
(R.Source.template "layout.html") | ||
>>> drop_first ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(** An action that builds the webring blog. *) | ||
|
||
val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let run (module R : Sigs.RESOLVER) chain = | ||
Yocaml.Action.write_static_file R.Target.atom | ||
(let open Yocaml.Task in | ||
R.track_common_dependencies | ||
>>> Yocaml.Pipeline.track_file R.Source.articles | ||
>>> Model.Articles.atom chain R.Source.articles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(** An action that builds the Atom file of the federated blog. *) | ||
|
||
val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
open Model_util | ||
|
||
type t = { | ||
title : string; | ||
synopsis : string option; | ||
date : Yocaml.Archetype.Datetime.t; | ||
tags : string list; | ||
authors : string list; | ||
link : Link.t; | ||
} | ||
|
||
let entity_name = "Article" | ||
let neutral = Yocaml.Metadata.required entity_name | ||
|
||
let validate = | ||
let open Yocaml.Data.Validation in | ||
record (fun fl -> | ||
let+ title = required fl "title" string | ||
and+ synopsis = optional fl "synopsis" string | ||
and+ date = required fl "date" Yocaml.Archetype.Datetime.validate | ||
and+ link = required fl "link" Link.validate | ||
and+ tags = | ||
optional_or fl ~default:[] "tags" @@ list_of Yocaml.Slug.validate | ||
and+ authors = | ||
required fl "authors" | ||
@@ ((string $ fun x -> [ x ]) / list_of Yocaml.Slug.validate) | ||
in | ||
{ title; synopsis; date; tags; authors; link }) | ||
|
||
let authors_in_chain chain { authors; _ } = | ||
let chain = Chain.to_list chain in | ||
List.for_all | ||
(fun author -> | ||
chain |> List.exists (fun (x, _) -> String.equal author (Member.id x))) | ||
authors | ||
|
||
let normalize { title; synopsis; date; tags; authors; link } = | ||
let open Yocaml.Data in | ||
[ | ||
("title", string title); | ||
("has_synopsis", has_opt synopsis); | ||
("synopsis", option string synopsis); | ||
("date", Yocaml.Archetype.Datetime.normalize date); | ||
("tags", list_of string tags); | ||
("has_tags", has_list tags); | ||
("authors", list_of string authors); | ||
("link", Link.normalize link); | ||
] | ||
|
||
let pp ppf article = | ||
Format.fprintf ppf "%a" Yocaml.Data.pp | ||
(article |> normalize |> Yocaml.Data.record) | ||
|
||
let sort a b = Yocaml.Archetype.Datetime.compare a.date b.date | ||
|
||
let to_atom chain { title; synopsis; date; tags; authors; link } = | ||
let open Yocaml_syndication in | ||
let title = title in | ||
let authors = List.map (Chain.as_author chain) authors in | ||
let updated = Datetime.make date in | ||
let categories = List.map Category.make tags in | ||
let url = link |> Link.url |> Url.to_string in | ||
let summary = synopsis |> Option.map Atom.text in | ||
let links = [ Atom.alternate url ~title ] in | ||
Atom.entry ~authors ~updated ~categories ?summary ~links | ||
~title:(Atom.text title) ~id:url () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(** Describes an external Article. *) | ||
|
||
type t | ||
(** The type describing an article. *) | ||
|
||
val authors_in_chain : Chain.t -> t -> bool | ||
(** Ensure that authors are present in chain. *) | ||
|
||
val pp : Format.formatter -> t -> unit | ||
val sort : t -> t -> int | ||
val to_atom : Chain.t -> t -> Yocaml_syndication.Atom.entry | ||
|
||
(** {1 Dealing as metadata} *) | ||
|
||
include Yocaml.Required.DATA_READABLE with type t := t | ||
include Yocaml.Required.DATA_INJECTABLE with type t := t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
open Model_util | ||
|
||
type t = { page : Page.t; articles : Article.t list } | ||
|
||
let from_page = Yocaml.Task.lift (fun (page, articles) -> { page; articles }) | ||
|
||
let fetch ?limit chain path = | ||
Yocaml.Task.from_effect (fun () -> | ||
let open Yocaml.Eff in | ||
let* files = | ||
read_directory ~on:`Source ~only:`Files | ||
~where:(Yocaml.Path.has_extension "yml") | ||
path | ||
in | ||
|
||
let+ articles = | ||
List.traverse | ||
(fun file -> | ||
Yocaml_yaml.Eff.read_file_as_metadata | ||
(module Article) | ||
~on:`Source file) | ||
files | ||
in | ||
limit | ||
|> Option.fold ~none:articles ~some:(fun limit -> | ||
articles |> Stdlib.List.filteri (fun i _ -> i > limit)) | ||
|> Stdlib.List.sort (fun a b -> Article.sort b a) | ||
|> Stdlib.List.filter (Article.authors_in_chain chain)) | ||
|
||
let index ?limit chain path = | ||
let open Yocaml.Task in | ||
lift (fun x -> (x, ())) >>> second (fetch ?limit chain path) >>> from_page | ||
|
||
let normalize { page; articles } = | ||
let open Yocaml.Data in | ||
Page.normalize page | ||
@ [ | ||
("articles", list_of (fun x -> record (Article.normalize x)) articles); | ||
("has_articles", has_list articles); | ||
] | ||
|
||
let atom chain path = | ||
let open Yocaml_syndication in | ||
let open Yocaml.Task in | ||
let id = "https://ring.muhokama.fun/atom.xml" in | ||
let title = Atom.text "ring.muhokama.fun" in | ||
let subtitle = Atom.text "federated blog of Muhokama webring" in | ||
let links = [ Atom.self id; Atom.link "https://ring.muhokama.fun" ] in | ||
let updated = Atom.updated_from_entries () in | ||
let authors = Chain.to_authors chain in | ||
fetch chain path | ||
>>> Atom.from ~updated ~title ~subtitle ~id ~links ~authors | ||
(Article.to_atom chain) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(** Describes a federation page of external articles published by ring members. *) | ||
|
||
type t | ||
(** The type describing the federation. *) | ||
|
||
val index : ?limit:int -> Chain.t -> Yocaml.Path.t -> (Page.t, t) Yocaml.Task.t | ||
val atom : Chain.t -> Yocaml.Path.t -> (unit, string) Yocaml.Task.t | ||
|
||
(** {1 Dealing as metadata} *) | ||
|
||
include Yocaml.Required.DATA_INJECTABLE with type t := t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.