package yocaml
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Core engine of the YOCaml Static Site Generator
Install
dune-project
Dependency
Authors
Maintainers
Sources
yocaml-2.7.0.tbz
sha256=89a74bd5cb37e580e45e4ed3d43b07b2cca5af9ab7f98966c48fe9730dc4af2e
sha512=ae77555570320c28c47d748e75056ccc44bb43cddf6fef70e8b556254fd809d67b915b313bd1833c28581db1fdeefbe34e81d5548744d6ecabe466ee1ef6284c
doc/src/yocaml/metadata.ml.html
Source file metadata.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118(* YOCaml a static blog generator. Copyright (C) 2024 The Funkyworkers and The YOCaml's developers This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. *) type 'a validated = ('a, Required.provider_error) result type extraction_strategy = | Regular of char | Custom of (string -> string option * string) let regular char = Regular char let jekyll = regular '-' let custom f = Custom f let consume content len ~until i = let buf = Buffer.create 1 in let rec aux i = if i >= len then None else let () = Buffer.add_char buf content.[i] in if content.[i] = until then Some (succ i, buf) else aux (succ i) in aux i let extract_regular delim content = let len = String.length content in if len <= 4 then (None, content) else let consume = consume content len ~until:'\n' in if List.for_all (Char.equal delim) [ content.[0]; content.[1]; content.[2] ] && Char.equal '\n' content.[3] then let buf = Buffer.create 1 in let rec aux i = if i >= len then (None, content) else match content.[i] with | c when len > i + 3 && List.for_all (Char.equal delim) [ c; content.[i + 1]; content.[i + 2] ] && Char.equal '\n' content.[3] -> let metadata = buf |> Buffer.to_bytes |> Bytes.to_string in let remaining = String.sub content (i + 4) (len - (i + 4)) in (Some metadata, remaining) | _ -> ( match consume i with | None -> (None, content) | Some (new_index, other_buf) -> let () = Buffer.add_buffer buf other_buf in aux new_index) in aux 4 else (None, content) let extract_from_content ~strategy content = match strategy with | Custom f -> f content | Regular delim -> extract_regular delim content let validate (type a) (module P : Required.DATA_PROVIDER) (module R : Required.DATA_READABLE with type t = a) value = value |> Option.map P.from_string |> Option.map (Result.map P.normalize) |> Option.fold ~none:R.neutral ~some:(fun normalized -> Result.bind normalized (fun value -> value |> R.validate |> Result.map_error (fun error -> Required.Validation_error { entity = R.entity_name; error }))) let required entity = Error (Required.Required_metadata { entity }) module Injectable (D : Required.DATA_INJECTABLE) : sig include Data.S with type t = D.t include Required.DATA_INJECTABLE with type t := t end = struct type t = D.t let to_data x = Data.record (D.normalize x) let normalize = D.normalize end module Readable (D : Data.Validation.S) (V : sig val name : string val neutral : [ `Optional of D.t | `Required ] end) : sig include Data.Validation.S include Required.DATA_READABLE with type t := t end = struct include D let entity_name = V.name let neutral = match V.neutral with | `Optional x -> Ok x | `Required -> Error (Required.Required_metadata { entity = entity_name }) let validate = D.from_data end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>