aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authororbifx <fox@orbitalfox.eu>2020-10-13 00:47:32 +0100
committerorbifx <fox@orbitalfox.eu>2020-10-13 14:13:16 +0100
commit6276d86529f8ac8dd78148b355b6228a2276b82f (patch)
treecfab13ef25a31dc0928c6a70c9debc3f4fc1dfb6
parenta0a31af19e6a4aba39611ed3ba0584e97fcddcf3 (diff)
downloadlogarion-xml-orbifx.tar.gz
logarion-xml-orbifx.tar.bz2
logarion-xml-orbifx.zip
Escape reserved XML characters & add document baseorbifx
-rw-r--r--lib/atom.ml11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/atom.ml b/lib/atom.ml
index d469ff8..101f0c1 100644
--- a/lib/atom.ml
+++ b/lib/atom.ml
@@ -1,4 +1,10 @@
-let esc x = x
+let esc x =
+ let fn a c = match c with
+ | '&' -> a ^ "&amp;"
+ | '<' -> a ^ "^lt;"
+ | x -> a ^ String.make 1 x
+ in
+ Seq.fold_left fn "" (String.to_seq x)
let header config url =
let open Logarion.Meta in
@@ -42,7 +48,8 @@ let entry url note =
let fold_note url feed note = feed ^ "\n" ^ entry url note
let feed config url articles =
- "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
+ {|<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom" xml:base="|} ^ url ^ {|/feed.atom">|}
^ header config url
^ articles
^ "</feed>"