~hristoast/hristoast

ed4e35da340817fa5769040737545ec80f6d37ba — Hristos N. Triantafillou 1 year, 8 days ago 87e72f7
Create and use the source link plugin
4 files changed, 53 insertions(+), 0 deletions(-)

A plugins/source-link.lua
M site/css/site.css
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 required 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\", using default (\"CHANGEME\")")
  repo_base = "https://git.sr.ht/~yourname/your-repo/tree/cool-branch/"
end

-- Remove trailing slashes
repo_base = Regex.replace(repo_base, "\\/?$", "")

source_link = HTML.select_one(page, selector)

if (source_link) then
   HTML.append_child(source_link, HTML.create_element("a", link_text))
   link = HTML.select_one(source_link, "a")

   url = repo_base .. "/" .. page_file
   HTML.set_attribute(link, "href", url)
end

M site/css/site.css => site/css/site.css +6 -0
@@ 98,6 98,12 @@ div#footnotes {
    font-size: 0.8em;
}

div#source-link, div#source-link a {
    color: #999;
    font-size: 0.8em;
    text-align: center;
}

div#timestamp {
    color: #777;
    font-size: 0.7em;

M soupault.conf => soupault.conf +9 -0
@@ 43,6 43,9 @@
[plugins.section-link-highlight]
  file = "plugins/section-link-highlight.lua"

[plugins.source-link]
  file = "plugins/source-link.lua"

[widgets.asciinema-player-css]
  widget = "insert-if"
  html = "<link rel='stylesheet' type='text/css' href='/asciinema/asciinema-player.css' />"


@@ 60,6 63,12 @@
  selector = "nav"
  active_link_class = "bold"

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

[widgets.vidpos-js]
  widget = "insert-if"
  html = "<script src='/js/vidpos.js' type='text/javascript'></script>"

M templates/main.html => templates/main.html +1 -0
@@ 54,5 54,6 @@
    <script src="/js/tracking.js" type="text/javascript"></script>
    <noscript><p><img src="//stats.hristos.co/piwik.php?idsite=1&rec=1" style="border:0;" alt="" /></p></noscript>
    <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 id="source-link"></div>
  </body>
</html>