Fix RSS/Atom generation for Gemini and HTTP, remove the txt publish feature

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/kosuzu/trunk@61 eb64cd80-c68d-6f47-b6a3-0ada418499da
This commit is contained in:
yakumo.izuru
2024-04-01 14:01:11 +00:00
parent 4858c48c0e
commit 52683496cc
6 changed files with 12 additions and 69 deletions

View File

@@ -11,7 +11,7 @@ let opt_element tag_name content =
module P = Parsers.Plain_text.Make (Converter.Html)
let id txt = "<id>urn:uuid:" ^ Logarion.(txt.Text.id) ^ "</id>"
let id txt = "<id>urn:txtid:" ^ Logarion.(txt.Text.id) ^ "</id>"
let title text = "<title>" ^ esc text.Logarion.Text.title ^ "</title>"
let authors text =
@@ -29,21 +29,19 @@ let updated txt = let open Logarion in
let htm_entry base_url text =
let open Logarion in
let u = Text.short_id text in
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".htm\" />"
"<entry>\n<link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".htm\" />"
^ title text ^ id text ^ updated text ^ authors text
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ esc elt ^ "\"/>") (Text.set "topics" text) ""
^ "<content type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">"
^ P.of_string text.body ""
^ "</div></content></entry>\n"
^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ esc elt ^ "\"/>\n") (Text.set "topics" text) ""
^ "</entry>\n"
let gmi_entry base_url text =
let open Logarion in
let u = Text.short_id text in
"<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".gmi\" />"
"<entry>\n<link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".gmi\" />\n"
^ title text ^ id text ^ updated text ^ authors text
^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ elt ^ "\"/>") (Text.set "topics" text) ""
^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ elt ^ "\"/>\n") (Text.set "topics" text) ""
^ "</entry>\n"
let base_url kv protocol = try
@@ -65,7 +63,7 @@ let indices alternate_type c =
{|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|}
^ self ^ {|" /><id>urn:uuid:|} ^ c.Conversion.id ^ "</id><updated>"
^ self ^ {|" /><id>urn:txtid:|} ^ c.Conversion.id ^ "</id><updated>"
^ Logarion.Date.now () ^ "</updated>\n"
^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" c.texts
^ "</feed>"

View File

@@ -2,5 +2,5 @@
(name txt)
(public_name txt)
(modules txt authors convert conversion edit file index last listing
new topics html atom gemini peers publish pull read recent)
new topics html atom gemini peers pull read recent)
(libraries text_parse.converter text_parse.parsers logarion msgpck curl str cmdliner))

View File

@@ -1,54 +0,0 @@
let targets pubdir = List.fold_left
(fun a x ->
let path = Filename.concat pubdir (snd x) in
try if Sys.is_directory path then (fst x, path)::a else a with Sys_error _ -> a)
[]
["htm,atom", "public_html/"; "gmi,gmi-atom", "public_gemini/"; "", "public_gopher/"]
let wizard () =
print_endline "No txt.conf found. It's required for the repository name & id. Create one? (y/N)";
match input_line stdin with
|"y"->
let title =
print_endline "Title for repository: ";
input_line stdin in
let authors =
print_endline "Authors (format: name <name@email> <http://website>): ";
input_line stdin in
Logarion.File_store.file "txt.conf"
(Printf.sprintf "Id: %s\nTitle: %s\nAuthors: %s\n" (Logarion.Id.generate ()) title authors);
Logarion.File_store.of_kv_file ()
| _ -> print_endline "Create a txt.conf and run publish again"; exit 1
open Logarion
let publish pubdir ids =
let kv =
match Logarion.File_store.of_kv_file ()
with x when x = Logarion.Store.KV.empty -> wizard () | x -> x in
let predicate t = List.mem t.Text.id ids in
let pubdir_source, pubdir = match pubdir with Some d -> "--pubdir ", d | None ->
try "txt.conf:Pubdir", Logarion.Store.KV.find "Pubdir" kv with Not_found ->
try "$txtpubdir", Sys.getenv "txtpubdir" with Not_found -> "$txtpubdir", ""
in
let targets = targets pubdir in
if targets = [] then
Printf.eprintf "No target directories in %s='%s' (for example %s)\n"
pubdir_source pubdir (Filename.concat pubdir "public_html")
else begin
let pub_dirs = List.map (fun x -> snd x) targets in
File_store.iter ~predicate (fun (_t, p) ->
try File.file ((List.hd p)::pub_dirs)
with Unix.Unix_error (Unix.EEXIST, _, _) -> ());
List.iter (fun t -> Printf.eprintf "%s %s\n" (fst t) (snd t);
Index.((load (snd t)) false None None None None);
Convert.at_path (fst t) false (snd t))
targets
end
open Cmdliner
let term =
let ids = Arg.(value & pos_all string [] & info [] ~docv:"text ids") in
let pubdir = Arg.(value & opt (some string) None & info ["p"; "pubdir"] ~docv:"directory path"
~doc:"set top directory for publishing files") in
let doc = "convert texts into standard public dirs pubdir/public_{html,gemini,gopher} if they exist" in
Term.(const publish $ pubdir $ ids), Term.info "publish" ~doc ~man:[ `S "DESCRIPTION"; `P doc ]

View File

@@ -1,9 +1,9 @@
let version = "1.3.1"
let version = "1.3.2"
open Cmdliner
let default_cmd =
let doc = "Discover, collect & exchange texts" in
let man = [ `S "CONTACT"; `P "<mailto:logarion@lists.tildeverse.org?subject=Logarion>" ] in
let man = [ `S "CONTACT"; `P "<mailto:logarion-dev@chaotic.ninja>" ] in
Term.(ret (const (`Help (`Pager, None)))), Term.info "txt" ~version ~doc ~man
let () = match Term.eval_choice default_cmd [
@@ -16,7 +16,6 @@ let () = match Term.eval_choice default_cmd [
Listing.term;
New.term;
Peers.term;
Publish.term;
Pull.term;
Read.term;
Recent.term;

View File

@@ -1,6 +1,6 @@
(lang dune 2.0)
(name logarion)
(version 1.3.1)
(version 1.3.2)
(license EUPL-1.2)
(authors "orbifx <fox@orbitalfox.eu>")
(bug_reports "mailto:logarion@lists.tildeverse.org")

View File

@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "1.3.1"
version: "1.3.2"
synopsis: "Texts archival and exchange"
maintainer: ["Izuru Yakumo <yakumo.izuru@chaotic.ninja>"]
authors: ["orbifx <fox@orbitalfox.eu>"]