~hristoast/mousikofidi

9acd5996aa6018dadb46fa52f7410a9beb6cbb01 — Hristos N. Triantafillou 6 months ago d2a0d46
Add modify and source link widgets
3 files changed, 50 insertions(+), 0 deletions(-)

A plugins/source-link.lua
M soupault.conf
M templates/main.html
A plugins/source-link.lua => plugins/source-link.lua +37 -0
@@ 0,0 1,37 @@
-- Creates a "source link" from a given repo base and injects the link into the page.
--
-- Minimal soupault version: 1.3
-- Author: Hristos N. Triantafillou
-- License: MIT

link_text = config["link_text"]
selector = config["selector"]
repo_base = config["repo_base"]

if (not link_text) then
  Log.warning("Missing option \"link_text\", using default (\"This page's source code\")")
  link_text = "This page's source code"
end

if (not selector) then
  Log.warning("Missing required option \"selector\", using default (\"div#source-link\")")
  selector = "div#source-link"
end

if (not repo_base) then
  Log.warning("Missing required option \"repo_base\"")
  -- Nothing to do
else
  -- Remove trailing slashes
  repo_base = Regex.replace(repo_base, "\\/?$", "")

  source_link_container = HTML.select_one(page, selector)

  if (source_link_container) then
    url = repo_base .. "/" .. page_file
    source_link = HTML.create_element("a", link_text)
    HTML.set_attribute(source_link, "href", url)

    HTML.append_child(source_link_container, source_link)
  end
end

M soupault.conf => soupault.conf +11 -0
@@ 35,6 35,17 @@
  selector = "nav"
  active_link_class = "current"

[widgets.last-modified]
  widget = "exec"
  selector = "#git-timestamp"
  command = "git log -n 1 --pretty=format:%ad --date=format:%Y-%m-%d -- $PAGE_FILE"

[widgets.source-link]
  widget = "source-link"
  selector = "div#source-link"
  link_text = "Source link for this page"
  repo_base = "https://git.sr.ht/~hristoast/mousikofidi/tree/mousikofidi.info/"

[widgets.footer]
  widget = "include"
  selector = "footer"

M templates/main.html => templates/main.html +2 -0
@@ 19,6 19,8 @@
      <hr />
      <footer class="center"></footer>
    </header>
    <div id="timestamp" class="center" title="A last modified timestamp derived from git.">This page was last modified on: <span id="git-timestamp"></span></div>
    <div class="center" id="source-link"></div>
    <script data-goatcounter="https://mousikofidi.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
  </body>
</html>