File using uuid naming
This commit is contained in:
parent
673190ab45
commit
00699cefc4
@ -26,7 +26,7 @@ let updated txt = let open Logarion in
|
|||||||
|
|
||||||
let htm_entry base_url text =
|
let htm_entry base_url text =
|
||||||
let open Logarion in
|
let open Logarion in
|
||||||
let u = Text.alias text in
|
let u = Text.short_id text in
|
||||||
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".htm\" />"
|
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".htm\" />"
|
||||||
^ title text ^ id text ^ updated text ^ authors text
|
^ title text ^ id text ^ updated text ^ authors text
|
||||||
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
|
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
|
||||||
@ -37,7 +37,7 @@ let htm_entry base_url text =
|
|||||||
|
|
||||||
let gmi_entry base_url text =
|
let gmi_entry base_url text =
|
||||||
let open Logarion in
|
let open Logarion in
|
||||||
let u = Text.alias text in
|
let u = Text.short_id text in
|
||||||
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".gmi\" />"
|
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".gmi\" />"
|
||||||
^ title text ^ id text ^ updated text ^ authors text
|
^ title text ^ id text ^ updated text ^ authors text
|
||||||
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
|
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
|
||||||
|
@ -61,7 +61,12 @@ let file files = match A.of_path "." with
|
|||||||
| Error msg -> prerr_endline msg
|
| Error msg -> prerr_endline msg
|
||||||
| Ok _archive ->
|
| Ok _archive ->
|
||||||
let dirs, files = split_filetypes files in
|
let dirs, files = split_filetypes files in
|
||||||
let link dir file = Unix.link file (dir ^"/"^ file) in
|
let _link_as_named dir file = Unix.link file (dir ^"/"^ file) in
|
||||||
|
let link_with_id dir file =
|
||||||
|
match File_store.to_text "." file with Error s -> prerr_endline s
|
||||||
|
| Ok t -> Unix.link file (dir ^"/"^ String.sub (Id.to_string (t.Text.uuid)) 0 8 ^".txt")
|
||||||
|
in
|
||||||
|
let link = link_with_id in
|
||||||
List.iter (fun d -> List.iter (link d) files) dirs
|
List.iter (fun d -> List.iter (link d) files) dirs
|
||||||
|
|
||||||
let file_term =
|
let file_term =
|
||||||
|
@ -8,15 +8,15 @@ let convert_modified source dest fn title text =
|
|||||||
then (File_store.file dest (fn title text); true) else false
|
then (File_store.file dest (fn title text); true) else false
|
||||||
|
|
||||||
let word_fname dir text = dir ^ "/" ^ Text.alias text
|
let word_fname dir text = dir ^ "/" ^ Text.alias text
|
||||||
let id_fname dir text = dir ^ "/" ^ String.sub (Id.to_string text.Text.uuid) 0 8
|
let id_fname dir text = dir ^ "/" ^ Text.short_id text
|
||||||
|
|
||||||
let writer types dir name (text,store_item) = (* todo: single_parser -> [files] *)
|
let writer types dir name (text,store_item) = (* todo: single_parser -> [files] *)
|
||||||
(* convert_modified store_item idfilename (fun _title -> Text.to_string) text.title text;*)
|
(* convert_modified store_item idfilename (fun _title -> Text.to_string) text.title text;*)
|
||||||
let h = if "htm" = types || "all" = types then
|
let h = if "htm" = types || "all" = types then
|
||||||
convert_modified store_item (word_fname dir text ^ ".htm") Html.page name text
|
convert_modified store_item (id_fname dir text ^ ".htm") Html.page name text
|
||||||
else false in
|
else false in
|
||||||
let g = if "gmi" = types || "all" = types then
|
let g = if "gmi" = types || "all" = types then
|
||||||
convert_modified store_item (word_fname dir text ^ ".gmi") Gemini.page name text
|
convert_modified store_item (id_fname dir text ^ ".gmi") Gemini.page name text
|
||||||
else false in
|
else false in
|
||||||
h || g
|
h || g
|
||||||
|
|
||||||
@ -48,18 +48,18 @@ let index_writer types dir archive topic_roots topic_map indexed_texts =
|
|||||||
)
|
)
|
||||||
|
|
||||||
let txt_writer types dir name ((text, _store_item) as r) =
|
let txt_writer types dir name ((text, _store_item) as r) =
|
||||||
match Logarion.Text.str "Content-Type" text with
|
match Text.str "Content-Type" text with
|
||||||
| "" | "text/plain" -> writer types dir name r
|
| "" | "text/plain" -> writer types dir name r
|
||||||
| x -> prerr_endline ("Can't convert Content-Type: "^x^" file: " ^text.Text.title); false
|
| x -> prerr_endline ("Can't convert Content-Type: "^x^" file: " ^text.Text.title); false
|
||||||
|
|
||||||
let convert_all types dir archive =
|
let convert_all types dir archive =
|
||||||
let name = archive.A.name in
|
let name = archive.A.name in
|
||||||
let fn (ts,ls,acc) ((elt,_) as r) =
|
let fn (ts,ls,acc) ((elt,_) as r) =
|
||||||
Logarion.(Topic_set.to_map ts (Text.set "topics" elt)),
|
(Topic_set.to_map ts (Text.set "topics" elt)),
|
||||||
elt::ls, if txt_writer types dir name r then acc+1 else acc in
|
elt::ls, if txt_writer types dir name r then acc+1 else acc in
|
||||||
let empty = Logarion.Topic_set.Map.empty in
|
let empty = Topic_set.Map.empty in
|
||||||
let topic_map, indexed_metas, count = A.(fold ~order:newest fn (empty,[],0) archive) in
|
let topic_map, indexed_metas, count = A.(fold ~order:newest fn (empty,[],0) archive) in
|
||||||
let topic_roots = Logarion.Topic_set.roots topic_map in
|
let topic_roots = Topic_set.roots topic_map in
|
||||||
index_writer types dir archive topic_roots topic_map indexed_metas;
|
index_writer types dir archive topic_roots topic_map indexed_metas;
|
||||||
print_endline @@ "Converted: " ^ string_of_int (count)
|
print_endline @@ "Converted: " ^ string_of_int (count)
|
||||||
^ "\nIndexed: " ^ string_of_int (List.length indexed_metas);
|
^ "\nIndexed: " ^ string_of_int (List.length indexed_metas);
|
||||||
|
@ -9,7 +9,7 @@ let page _archive_title text =
|
|||||||
let date_index title meta_list =
|
let date_index title meta_list =
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun a m ->
|
(fun a m ->
|
||||||
a ^ "=> " ^ Logarion.Text.alias m ^ ".gmi " ^
|
a ^ "=> " ^ Logarion.Text.short_id m ^ ".gmi " ^
|
||||||
Logarion.(Date.(pretty_date (listing m.date)) ^ " " ^ m.title) ^ "\n")
|
Logarion.(Date.(pretty_date (listing m.date)) ^ " " ^ m.title) ^ "\n")
|
||||||
("# " ^ title ^ "\n\n## Posts by date\n\n") meta_list
|
("# " ^ title ^ "\n\n## Posts by date\n\n") meta_list
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ let to_dated_links ?(limit) meta_list =
|
|||||||
List.fold_left
|
List.fold_left
|
||||||
(fun a m ->
|
(fun a m ->
|
||||||
a
|
a
|
||||||
^ "=> " ^ Logarion.Text.alias m ^ ".gmi "
|
^ "=> " ^ Logarion.Text.short_id m ^ ".gmi "
|
||||||
^ Logarion.(Date.(pretty_date (listing m.Text.date))) ^ " "
|
^ Logarion.(Date.(pretty_date (listing m.Text.date))) ^ " "
|
||||||
^ m.Logarion.Text.title ^ "\n")
|
^ m.Logarion.Text.title ^ "\n")
|
||||||
"" meta_list
|
"" meta_list
|
||||||
@ -35,7 +35,7 @@ let topic_link root topic =
|
|||||||
|
|
||||||
let text_item path meta =
|
let text_item path meta =
|
||||||
let open Logarion in
|
let open Logarion in
|
||||||
"=> " ^ path ^ Text.alias meta ^ ".gmi "
|
"=> " ^ path ^ Text.short_id meta ^ ".gmi "
|
||||||
^ Date.(pretty_date (listing meta.Text.date)) ^ " "
|
^ Date.(pretty_date (listing meta.Text.date)) ^ " "
|
||||||
^ meta.Text.title ^ "\n"
|
^ meta.Text.title ^ "\n"
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ let to_dated_links ?(limit) meta_list =
|
|||||||
List.fold_left
|
List.fold_left
|
||||||
(fun a m ->
|
(fun a m ->
|
||||||
a ^ Logarion.(Date.(pretty_date (listing m.Text.date)) ^ " ")
|
a ^ Logarion.(Date.(pretty_date (listing m.Text.date)) ^ " ")
|
||||||
^ {|<a href="|} ^ Logarion.Text.alias m ^ {|.htm">|} ^ m.Logarion.Text.title ^ "</a><br>")
|
^ {|<a href="|} ^ Logarion.Text.short_id m ^ {|.htm">|} ^ m.Logarion.Text.title ^ "</a><br>")
|
||||||
"" meta_list
|
"" meta_list
|
||||||
|
|
||||||
let date_index ?(limit) title meta_list =
|
let date_index ?(limit) title meta_list =
|
||||||
@ -90,7 +90,7 @@ let fold_topics topic_map topic_roots metas =
|
|||||||
let text_item path meta =
|
let text_item path meta =
|
||||||
let open Logarion in
|
let open Logarion in
|
||||||
"<time>" ^ Date.(pretty_date (listing meta.Text.date))
|
"<time>" ^ Date.(pretty_date (listing meta.Text.date))
|
||||||
^ {|</time> <a href="|} ^ path ^ Text.alias meta ^ {|.htm">|} ^ meta.Text.title
|
^ {|</time> <a href="|} ^ path ^ Text.short_id meta ^ {|.htm">|} ^ meta.Text.title
|
||||||
^ "</a><br>"
|
^ "</a><br>"
|
||||||
|
|
||||||
let listing_index topic_map topic_roots path metas =
|
let listing_index topic_map topic_roots path metas =
|
||||||
|
@ -99,3 +99,4 @@ let string_alias t =
|
|||||||
Buffer.contents b
|
Buffer.contents b
|
||||||
|
|
||||||
let alias t = match str "alias" t with "" -> string_alias t.title | x -> x
|
let alias t = match str "alias" t with "" -> string_alias t.title | x -> x
|
||||||
|
let short_id ?(len=8) t = String.sub (Id.to_string t.uuid) 0 len
|
||||||
|
Loading…
x
Reference in New Issue
Block a user