Something went wrong. Try again.
static-site-generator blogging hypertext ocaml
Something went wrong. Try again.
2.0 kB · 81 lines
OCaml
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(* * SPDX-FileCopyrightText: 2024 The Forester Project Contributors * SPDX-FileCopyrightText: 2026 The Forester Project Contributors * * SPDX-License-Identifier: GPL-3.0-or-later *)
open Forester_prelude
open struct module T = Typesend
module G = Graph.Imperative.Digraph.ConcreteBidirectional (Vertex)include Gmodule V = Vertexinclude Graph.Oper.I (G)module Map = Graph.Gmap.Vertex (G)
module Topo = Graph.Topological.Make (G)
let topo_fold = Topo.foldlet topo_iter = Topo.iterlet safe_succ g x = if mem_vertex g x then succ g x else []let safe_dependents = safe_succlet safe_pred g x = if mem_vertex g x then pred g x else []let immediate_dependencies = safe_pred
let dependencies graph vertex : t = let dep_graph = create () in let rec go v = iter_pred (fun dep -> if mem_vertex dep_graph dep then () else begin add_edge dep_graph dep v; go dep end) graph v in go vertex; dep_graph
let transitive_dependents g uri = let seen = Hashtbl.create 8 in let rec go v = let@ w = List.iter @~ safe_dependents g v in if not (Hashtbl.mem seen w) then begin Hashtbl.add seen w (); go w end in go (T.Uri_vertex uri); topo_fold (fun v acc -> if Hashtbl.mem seen v then v :: acc else acc) g [] |> List.rev |> List.filter_map Vertex.uri_of_vertex
let filter_vertex pred g = G.fold_vertex (fun v acc -> if pred v then v :: acc else acc) g []
let filter_map_vertex f g = G.fold_vertex (fun v acc -> match f v with Some a -> a :: acc | None -> acc) g []
module Graphviz = Graph.Graphviz.Dot (struct include G module V = Vertex
let vertex_name v = match Vertex.uri_of_vertex v with | Some uri -> "\"" ^ URI.to_string uri ^ "\"" | None -> ""
let graph_attributes _ = [] let default_vertex_attributes _ = [] let vertex_attributes _ = [] let default_edge_attributes _ = [] let edge_attributes _e = [`Label ""] let get_subgraph _ = Noneend)