From ed4e35da340817fa5769040737545ec80f6d37ba Mon Sep 17 00:00:00 2001 From: "Hristos N. Triantafillou" Date: Fri, 15 Nov 2019 21:27:29 -0600 Subject: [PATCH] Create and use the source link plugin --- plugins/source-link.lua | 37 +++++++++++++++++++++++++++++++++++++ site/css/site.css | 6 ++++++ soupault.conf | 9 +++++++++ templates/main.html | 1 + 4 files changed, 53 insertions(+) create mode 100644 plugins/source-link.lua diff --git a/plugins/source-link.lua b/plugins/source-link.lua new file mode 100644 index 0000000..d6306e1 --- /dev/null +++ b/plugins/source-link.lua @@ -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 diff --git a/site/css/site.css b/site/css/site.css index 40d4f49..bcaf47d 100644 --- a/site/css/site.css +++ b/site/css/site.css @@ -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; diff --git a/soupault.conf b/soupault.conf index d9059e2..e4d5079 100644 --- a/soupault.conf +++ b/soupault.conf @@ -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 = "" @@ -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 = "" diff --git a/templates/main.html b/templates/main.html index 84df2e3..f2f0669 100644 --- a/templates/main.html +++ b/templates/main.html @@ -54,5 +54,6 @@
This page was last modified on:
+ -- 2.26.2