about summary refs log tree commit diff homepage
path: root/utils.jl
blob: 4d43cdcac80cf10e1388a393264e5809f3db49bf (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
55
56
57
58
59
60
61
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)
  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")
  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
  return joinpath(globvar(:website_url), rpath)
end

hfun_fediring(args) = "https://fediring.net/$(args[1])?host=cnx.srht.site"
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()
  return @sprintf("mailto:%s?%s=%s&%s=Re: %s",
                  "~cnx/site@lists.sr.ht",
                  "In-Reply-To", message_id(),
                  "Subject", locvar(:title))
end

ring_sources = ["https://blog.ganssle.io/feeds/all.atom.xml",
                "https://codesections.com/rss.xml",
                "https://danct12.github.io/feed.xml",
                "https://drewdevault.com/feed.xml",
                "https://huyngo.envs.net/index.xml",
                "https://pgjones.dev/blog/rss20.xml",
                "https://stallman.org/rss/rss.xml",
                "https://unixsheikh.com/feed.rss"]
# TODO: joinpath
hfun_openring() = readchomp(pipeline("_templates/openring.html",
                                     `openring -n4 -s$ring_sources`))

function hfun_pep(args)
  postfix = length(args) < 2 ? "" : '#' * args[2]
  return @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]
  return @sprintf("<a href=https://github.com/pypa/pip/pull/%s>%s</a>",
                  args[1], content)
end