[2] | 1 | let esc = Converter.Html.esc
|
---|
| 2 |
|
---|
| 3 | let element tag content = "<" ^ tag ^ ">" ^ content ^ "</" ^ tag ^ ">"
|
---|
| 4 |
|
---|
| 5 | let opt_element tag_name content =
|
---|
| 6 | if content <> ""
|
---|
| 7 | then element tag_name content
|
---|
| 8 | else ""
|
---|
| 9 |
|
---|
| 10 | module P = Parsers.Plain_text.Make (Converter.Html)
|
---|
| 11 |
|
---|
[3] | 12 | let id txt = "<id>urn:uuid:" ^ Logarion.(txt.Text.id) ^ "</id>"
|
---|
[2] | 13 | let title text = "<title>" ^ esc text.Logarion.Text.title ^ "</title>"
|
---|
| 14 |
|
---|
| 15 | let 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 |
|
---|
| 24 | let updated txt = let open Logarion in
|
---|
| 25 | "<updated>"^ Date.(txt.Text.date |> listing |> rfc_string) ^"</updated>"
|
---|
| 26 |
|
---|
| 27 | let 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 |
|
---|
| 38 | let 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 |
|
---|
| 47 | let 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>"
|
---|