Skip to content

Commit

Permalink
Some small reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Nov 19, 2024
1 parent 2b7180d commit dc2a7e6
Show file tree
Hide file tree
Showing 42 changed files with 136 additions and 133 deletions.
8 changes: 4 additions & 4 deletions bin/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ let with_message source target f () =

let run_build log_level target source configuration_file =
let module Resolver =
Static.Resolver.Make (struct
Generator.Resolver.Make (struct
let source, target = source, target
let configuration_file = configuration_file
end)
in
let program =
with_message source target
@@ Static.Action.run (module Resolver : Static.Intf.RESOLVER)
@@ Generator.Action.run (module Resolver : Generator.Intf.RESOLVER)
in
let () = Yocaml_runtime.Log.setup ~level:log_level () in
Yocaml_eio.run ~level:log_level program
;;

let run_watch port log_level target source configuration_file =
let module Resolver =
Static.Resolver.Make (struct
Generator.Resolver.Make (struct
let source, target = source, target
let configuration_file = configuration_file
end)
in
let program =
with_message source target
@@ Static.Action.run (module Resolver : Static.Intf.RESOLVER)
@@ Generator.Action.run (module Resolver : Generator.Intf.RESOLVER)
in
let () = Yocaml_runtime.Log.setup ~level:log_level () in
Yocaml_eio.serve ~level:log_level ~target ~port program
Expand Down
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(name capsule)
(public_name capsule)
(libraries yocaml yocaml_runtime yocaml_eio static cmdliner))
(libraries yocaml yocaml_runtime yocaml_eio generator cmdliner))
File renamed without changes.
File renamed without changes.
73 changes: 38 additions & 35 deletions lib/static/model/common.ml → lib/generator/archetype/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ let validate_document_kind =
string
& fun x ->
match String.(trim @@ lowercase_ascii x) with
| "page" -> Ok Types.Page
| "article" -> Ok Types.Article
| "page" -> Ok Model.Types.Page
| "article" -> Ok Model.Types.Article
| _ -> fail_with ~given:x "Invalid document kind"
;;

Expand All @@ -50,7 +50,7 @@ let validate fields =
let+ title = optional fields "page_title" string
and+ document_kind =
optional_or
~default:Types.Article
~default:Model.Types.Article
fields
"document_kind"
validate_document_kind
Expand All @@ -63,9 +63,9 @@ let validate fields =
optional fields "updated_at" Yocaml.Archetype.Datetime.validate
and+ synopsis = required fields "synopsis" string
and+ tags = optional_or fields ~default:[] "tags" (list_of Slug.validate)
and+ cover = optional fields "cover" Cover.validate
and+ cover = optional fields "cover" Model.Cover.validate
and+ breadcrumb =
optional_or fields ~default:[] "breadcrumb" (list_of Link.validate)
optional_or fields ~default:[] "breadcrumb" (list_of Model.Link.validate)
and+ display_toc = optional_or fields ~default:false "display_toc" bool in
new t
~title
Expand All @@ -83,48 +83,51 @@ let validate fields =
;;

let pseudo_og obj =
[ Meta.from_option "twitter:card" (Some "summary_large_image")
; Meta.from_option "twitter:title" obj#page_title
; Meta.from_option "og:title" obj#page_title
; Meta.from_option "twitter:description" obj#description
; Meta.from_option "og:description" obj#description
; Meta.from_option "og:site_name" (Some "xvw.lol")
]
Model.Meta.
[ from_option "twitter:card" (Some "summary_large_image")
; from_option "twitter:title" obj#page_title
; from_option "og:title" obj#page_title
; from_option "twitter:description" obj#description
; from_option "og:description" obj#description
; from_option "og:site_name" (Some "xvw.lol")
]
;;

let article_meta obj =
match obj#document_kind with
| Types.Page -> [ Meta.from_option "og:type" (Some "website") ]
| Types.Article ->
[ Meta.from_option "og:type" (Some "article")
; Meta.from_option
"og:article:published_time"
(Option.map
(Format.asprintf "%a" Yocaml.Archetype.Datetime.pp)
obj#published_at)
; Meta.from_option
"og:article:modified_time"
(Option.map
(Format.asprintf "%a" Yocaml.Archetype.Datetime.pp)
obj#updated_at)
; Meta.from_option "og:article:section" obj#section
]
| Model.Types.Page -> [ Model.Meta.from_option "og:type" (Some "website") ]
| Model.Types.Article ->
Model.Meta.
[ from_option "og:type" (Some "article")
; from_option
"og:article:published_time"
(Option.map
(Format.asprintf "%a" Yocaml.Archetype.Datetime.pp)
obj#published_at)
; from_option
"og:article:modified_time"
(Option.map
(Format.asprintf "%a" Yocaml.Archetype.Datetime.pp)
obj#updated_at)
; from_option "og:article:section" obj#section
]
@ List.map
(fun tag -> Meta.from_option "og:article:tag" (Some tag))
(fun tag -> Model.Meta.from_option "og:article:tag" (Some tag))
obj#tags
;;

let meta obj =
[ Meta.from_list "keywords" obj#tags
; Meta.from_option "description" obj#description
; Meta.from_option "generator" (Some "YOCaml")
]
Model.Meta.
[ from_list "keywords" obj#tags
; from_option "description" obj#description
; from_option "generator" (Some "YOCaml")
]
@ pseudo_og obj
@ article_meta obj
;;

let normalize obj =
let open Model_util in
let open Model.Model_util in
let open Yocaml.Data in
[ "page_title", option string obj#page_title
; "page_charset", option string obj#page_charset
Expand All @@ -134,8 +137,8 @@ let normalize obj =
; "published_at", option Yocaml.Archetype.Datetime.normalize obj#published_at
; "updated_at", option Yocaml.Archetype.Datetime.normalize obj#updated_at
; "tags", list_of string obj#tags
; "breadcrumb", list_of Link.normalize obj#breadcrumb
; "cover", option Cover.normalize obj#cover
; "breadcrumb", list_of Model.Link.normalize obj#breadcrumb
; "cover", option Model.Cover.normalize obj#cover
; "toc", option string obj#toc
; "has_section", exists_from_opt obj#section
; "has_toc", bool (obj#display_toc && Option.is_some obj#toc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class t :
document_kind:Types.document_kind
document_kind:Model.Types.document_kind
-> title:string option
-> charset:string option
-> cover:Cover.t option
-> cover:Model.Cover.t option
-> description:string option
-> synopsis:string
-> section:string option
-> published_at:Yocaml.Archetype.Datetime.t option
-> updated_at:Yocaml.Archetype.Datetime.t option
-> tags:string list
-> breadcrumb:Link.t list
-> breadcrumb:Model.Link.t list
-> display_toc:bool
-> Types.common

Expand All @@ -18,4 +18,4 @@ val validate
-> t Yocaml.Data.Validation.validated_record

val normalize : #t -> (string * Yocaml.Data.t) list
val meta : #t -> Meta.t option list
val meta : #t -> Model.Meta.t option list
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions lib/static/archetype/page.ml → lib/generator/archetype/page.ml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module Parse = struct
class type t = Model.Types.common
class type t = Types.common

let entity_name = "Page"
let neutral = Yocaml.Metadata.required entity_name

let validate =
let open Yocaml.Data.Validation in
record Model.Common.validate
record Common.validate
;;
end

class type t = object
inherit Parse.t
inherit [Config.t] Model.Types.with_configuration
inherit Model.Types.with_target_path
inherit Model.Types.with_source_path
inherit Types.with_configuration
inherit Types.with_target_path
inherit Types.with_source_path
end

let resolve_cover config cover =
Expand All @@ -24,7 +24,7 @@ let resolve_cover config cover =
class make p config source_path target_path =
object (_ : #t)
inherit
Model.Common.t
Common.t
~title:p#page_title
~document_kind:p#document_kind
~section:p#section
Expand Down Expand Up @@ -89,13 +89,13 @@ let meta page =
| None -> []
| Some x -> Model.Cover.meta_for x
in
Model.Common.meta page
Common.meta page
@ Model.Identity.meta_for (Config.owner_of page#configuration)
@ meta_cover
;;

let normalize page =
Model.Common.normalize page
Common.normalize page
@ [ "config", Config.normalize page#configuration
; "build_info", normalize_build_info page
; "meta", Model.Meta.normalize_options @@ meta page
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions lib/generator/archetype/types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class type with_configuration = object
method configuration : Config.t
end

class type with_target_path = object
method target_path : Yocaml.Path.t
end

class type with_source_path = object
method source_path : Yocaml.Path.t
end

class type common = object ('a)
method document_kind : Model.Types.document_kind
method page_title : string option
method page_charset : string option
method cover : Model.Cover.t option
method description : string option
method published_at : Yocaml.Archetype.Datetime.t option
method updated_at : Yocaml.Archetype.Datetime.t option
method synopsis : string
method section : string option
method breadcrumb : Model.Link.t list
method tags : string list
method display_toc : bool
method toc : string option
method with_toc : string option -> 'a
method on_description : (string option -> string option) -> 'a
method on_synopsis : (string -> string) -> 'a
end
4 changes: 2 additions & 2 deletions lib/static/dune → lib/generator/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(library
(name static)
(public_name capsule.static)
(name generator)
(public_name capsule.generator)
(libraries
yocaml
yocaml_yaml
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/generator/model/cover.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type t

include Types.MODEL with type t := t

val meta_for : t -> Meta.t option list
val resolve : Url.t -> t -> t
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/static/model/link.mli → lib/generator/model/link.mli
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
type t

include Types.MODEL with type t := t

val make : string -> Url.t -> t
val equal : t -> t -> bool
val validate : Yocaml.Data.t -> t Yocaml.Data.Validation.validated_value
val normalize : t -> Yocaml.Data.t

val validate_from_url
: string
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion lib/static/model/meta.mli → lib/generator/model/meta.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
type t

include Types.NORMALIZABLE with type t := t

val make : name:string -> content:string -> t
val from_option : string -> string option -> t option
val from_list : string -> string list -> t option
val normalize : t -> Yocaml.Data.t
val normalize_options : t option list -> Yocaml.Data.t
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions lib/generator/model/types.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
type document_kind =
| Page
| Article

module type NORMALIZABLE = sig
type t

val normalize : t -> Yocaml.Data.t
end

module type VALIDABLE = sig
type t

val validate : Yocaml.Data.t -> t Yocaml.Data.Validation.validated_value
end

module type MODEL = sig
include NORMALIZABLE
include VALIDABLE with type t := t
end

module type KEY_VALUE = sig
type t
type key
type value

val from_list : (key * value) list -> t
val to_list : t -> (key * value) list
val empty : t
val has_elements : t -> Yocaml.Data.t

include MODEL with type t := t
end
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/static/model/url.mli → lib/generator/model/url.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type t

include Types.MODEL with type t := t

val http : string -> t
val https : string -> t
val gemini : string -> t
val from_path : Yocaml.Path.t -> t
val validate : Yocaml.Data.t -> t Yocaml.Data.Validation.validated_value
val normalize : t -> Yocaml.Data.t
val equal : t -> t -> bool
val get_url : ?with_scheme:bool -> t -> string
val resolve : t -> t -> t
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions lib/static/model/cover.mli

This file was deleted.

Loading

0 comments on commit dc2a7e6

Please sign in to comment.