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

Last change on this file since 2 was 2, checked in by fox, 3 years ago

Samhain 21

Converter

  • type selection
  • subdir conversion
  • htm extension

Gemini

  • index.gmi
  • topics and latest
  • gmi.atom feed

Add pull (http(s)) operation

  • peers.pub.conf and peers.priv.conf

HTML5 format & fixes by Novaburst
Phony target (thanks Gergely)

May

Basic unit renamed from Note to Text.
New modular text-parser, internal to Logarion, for generic notation parsing. The default input format is now a much plainer text.
Logarion created texts have part of the UUID in filename.
Logarion's index re-written in Messagepack format. Removed indices command. They are generated during convert.

File size: 2.4 KB
Line 
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
12let id txt = "<id>urn:uuid:" ^ Logarion.(Id.to_string txt.Text.uuid) ^ "</id>"
13let title text = "<title>" ^ esc text.Logarion.Text.title ^ "</title>"
14
15let authors text =
16 let u acc addr = acc ^ element "uri" (Uri.to_string addr) in
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="|}
54 ^ self ^ {|" /><id>urn:uuid:|} ^ Logarion.Id.to_string archive_id ^ "</id><updated>"
55 ^ Ptime.to_rfc3339 (Ptime_clock.now ()) ^ "</updated>\n"
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.