source: code/trunk/cli/atom.ml@ 14

Last change on this file since 14 was 3, checked in by fox, 3 years ago
  • Removed 'txt init'

Format

  • New B32 ID

Index

  • New option: txt index --print
  • Move scheme to peers
  • Replace peer.*.conf files with index packed locations Instead of adding a URL to peers.*.conf, run txt pull <url>

Conversion

  • Rewritten converters
  • txt-convert looks for a .convert.conf containing key: value lines.
  • Specifiable topic-roots from .convert.conf.
  • Added Topics: key, with comma seperated topics.

If set only those topics will appear in the main index and used as topic roots.
Other topics will have sub-indices generated, but won't be listed in the main index.

  • HTML converter header & footer options
  • HTML-index renamed to HTM-index

Internal

  • Change types: uuid:Uuid -> id:string
  • File_store merges identical texts
  • Use peer ID for store path, store peers' texts in .local/share/texts
  • Simple URN resolution for converter

Continue to next feed if parsing one fails

  • Phasing-out Archive, replaced by improved packs
  • Eliminate Bos, Cohttp, lwt, uri, tls, Re, Ptime, dependencies
  • Lock version for Cmdliner, fix dune-project
  • Optional resursive store
  • Improve header_pack
  • Fix recursive mkdir
File size: 2.3 KB
RevLine 
[2]1let esc = Converter.Html.esc
2
3let element tag content = "<" ^ tag ^ ">" ^ content ^ "</" ^ tag ^ ">"
4
5let opt_element tag_name content =
6 if content <> ""
7 then element tag_name content
8 else ""
9
10module P = Parsers.Plain_text.Make (Converter.Html)
11
[3]12let id txt = "<id>urn:uuid:" ^ Logarion.(txt.Text.id) ^ "</id>"
[2]13let title text = "<title>" ^ esc text.Logarion.Text.title ^ "</title>"
14
15let authors text =
[3]16 let u acc addr = acc ^ element "uri" addr in
[2]17 let open Logarion in
18 let fn txt a =
19 a ^ "<author>" ^ (opt_element "name" @@ esc txt.Person.name)
20 ^ (List.fold_left u "" txt.Person.addresses)
21 ^ "</author>" in
22 Person.Set.fold fn text.Text.authors ""
23
24let updated txt = let open Logarion in
25 "<updated>"^ Date.(txt.Text.date |> listing |> rfc_string) ^"</updated>"
26
27let htm_entry base_url text =
28 let open Logarion in
29 let u = Text.short_id text in
30 "<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".htm\" />"
31 ^ title text ^ id text ^ updated text ^ authors text
32 ^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
33 ^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ esc elt ^ "\"/>") (Text.set "topics" text) ""
34 ^ "<content type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">"
35 ^ P.of_string text.body ""
36 ^ "</div></content></entry>\n"
37
38let gmi_entry base_url text =
39 let open Logarion in
40 let u = Text.short_id text in
41 "<entry><link rel=\"alternate\" href=\"" ^ base_url ^ "/" ^ u ^ ".gmi\" />"
42 ^ title text ^ id text ^ updated text ^ authors text
43 ^ (opt_element "summary" @@ esc @@ Text.str "abstract" text)
44 ^ String_set.fold (fun elt a -> a ^ "<category term=\"" ^ elt ^ "\"/>") (Text.set "topics" text) ""
45 ^ "</entry>\n"
46
47let feed title archive_id base_url alternate_type texts =
48 let entry, self = match alternate_type with
49 | "text/gemini" -> gmi_entry, base_url^"/gmi.atom"
50 | "text/html" | _ -> htm_entry, base_url^"/feed.atom" in
51 {|<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ base_url ^ {|"><title>|}
52 ^ title ^ {|</title><link rel="alternate" type="|} ^ alternate_type ^ {|" href="|}
53 ^ base_url ^ {|/" /><link rel="self" type="application/atom+xml" href="|}
[3]54 ^ self ^ {|" /><id>urn:uuid:|} ^ archive_id ^ "</id><updated>"
55 ^ Logarion.Date.now () ^ "</updated>\n"
[2]56 ^ List.fold_left (fun acc t -> acc ^ entry base_url t) "" texts
57 ^ "</feed>"
Note: See TracBrowser for help on using the repository browser.