about summary refs log tree commit diff homepage
path: root/utils.jl
diff options
context:
space:
mode:
Diffstat (limited to 'utils.jl')
-rw-r--r--utils.jl39
1 files changed, 31 insertions, 8 deletions
diff --git a/utils.jl b/utils.jl
index 86b16c5..3e58dde 100644
--- a/utils.jl
+++ b/utils.jl
@@ -1,14 +1,42 @@
-using Printf
+using Printf: @sprintf
+using Franklin: convert_html, path
 
 function hfun_author_date()
   return readchomp(`git log -1 --date=short --format=%ad $(locvar(:fd_rpath))`)
 end
 
 function hfun_abslink(args)
-  path = args[1]
-  return @sprintf("<a href=/%s>%s</a>", path, pagevar(path, "title"))
+  rpath = args[1]
+  return @sprintf("<a href=/%s>%s</a>", rpath, pagevar(rpath, :title))
 end
 
+dir_url() = strip(dirname(locvar(:fd_url)), '/')
+message_id() = @sprintf("<%s@cnx>", dir_url())
+hfun_comments() = @sprintf("https://lists.sr.ht/~cnx/site?search=%s:%s",
+                           "In-Reply-To", message_id())
+
+function hfun_comment_rss()
+  rpath = joinpath(dir_url(), "comments.xml")
+  head_template = joinpath(path(:rss), "comment-head.xml")
+  item_template = joinpath(path(:rss), "comment-item.xml")
+  open(joinpath(path(:site), rpath), "w") do feed
+    write(feed, convert_html(read(head_template, String)))
+    write(feed, read(`python3 formbox.py mbox $(message_id()) $(item_template)`, String))
+    write(feed, "</channel></rss>")
+  end
+  return joinpath(globvar(:website_url), rpath)
+end
+
+function hfun_mailto_comment()
+  return @sprintf("mailto:%s?%s=%s&%s=Re: %s",
+                  "~cnx/site@lists.sr.ht",
+                  "In-Reply-To", message_id(),
+                  "Subject", locvar(:title))
+end
+
+hfun_github(args) = @sprintf("<a href=https://github.com/%s>@%s</a>",
+                             args[1], args[1])
+
 function hfun_pep(args)
   postfix = length(args) < 2 ? "" : '#' * args[2]
   return @sprintf(
@@ -16,11 +44,6 @@ function hfun_pep(args)
     Meta.parse(args[1]), postfix, args[1], postfix)
 end
 
-function hfun_github(args)
-  return @sprintf("<a href=https://github.com/%s>@%s</a>",
-                  args[1], args[1])
-end
-
 function hfun_pip(args)
   content = length(args) < 2 ? "GH-" * args[1] : args[2]
   return @sprintf("<a href=https://github.com/pypa/pip/pull/%s>%s</a>",