about summary refs log tree commit diff homepage
path: root/utils.jl
blob: 5a6e1c43e7b62941f5331d72330b51a683478584 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Printf: @sprintf
using Franklin: convert_html, path

function hfun_author_date()
  readchomp(`git log -1 --date=short --format=%ad $(locvar(:fd_rpath))`)
end

function hfun_abslink(args)
  rpath = args[1]
  @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")
  open(joinpath(path(:site), rpath), "w") do feed
    write(feed, convert_html(readchomp(joinpath(path(:rss), "comments.xml"))))
    #write(feed, read(`python3 formbox.py mbox $(message_id()) $item_template`, String))
  end
  joinpath(globvar(:website_url), rpath)
end

function hfun_fediring(args)
  adj = readlines(joinpath(path(:libs), "fediring"))[parse(Int, args[1])]
  "<a href=https://$adj>$(args[2])</a>"
end

hfun_github(args) = "<a href=https://github.com/$(args[1])>@$(args[1])</a>"
hfun_job_url() = get(ENV, "JOB_URL", "https://builds.sr.ht/~cnx/site")

function hfun_mailto_comment()
  @sprintf("<a href='mailto:%s?%s=%s&%s=Re: %s' title='Reply via email'>%s</a>",
           "~cnx/site@lists.sr.ht",
           "In-Reply-To", message_id(),
           "Subject", locvar(:title),
           globvar(:author))
end

hfun_openring() = readchomp(joinpath(path(:libs), "openring", "out.html"))

function hfun_pep(args)
  postfix = length(args) < 2 ? "" : '#' * args[2]
  @sprintf("<a href=https://www.python.org/dev/peps/pep-%04d%s>PEP %s%s</a>",
           Meta.parse(args[1]), postfix, args[1], postfix)
end

function hfun_pip(args)
  content = length(args) < 2 ? "GH-" * args[1] : args[2]
  "<a href=https://github.com/pypa/pip/pull/$(args[1])>$content</a>"
end