From 3f1448f72da8af8d4c69c72158ac1920a8521828 Mon Sep 17 00:00:00 2001 From: earnest ma Date: Thu, 25 May 2023 19:11:49 -0400 Subject: [PATCH] feat: Blogroll It somehow works --- .gitignore | 1 + .woodpecker.yml | 4 +- Justfile | 2 + content/blog/minor-website-update-2023.md | 2 +- content/blogroll.md | 5 +++ scripts/opml_to_html.py | 50 ++++++++++++++++++++++ static/blogroll.opml | 52 +++++++++++++++++++++++ 7 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 content/blogroll.md create mode 100644 scripts/opml_to_html.py create mode 100644 static/blogroll.opml diff --git a/.gitignore b/.gitignore index cd5c340..b54110c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ public/ resources static/recipes.yaml +layouts/shortcodes/blogroll.html diff --git a/.woodpecker.yml b/.woodpecker.yml index dc79e29..3fc4b2d 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -7,7 +7,7 @@ pipeline: event: [ pull_request ] secrets: [ ssh_key ] commands: - - apk add --no-cache git hugo just openssh-client rsync + - apk add --no-cache git hugo just openssh-client python3 rsync # lychee hasn't been packaged for Alpine Linux - apk add --no-cache curl - curl -LO https://github.com/lycheeverse/lychee/releases/download/v0.9.0/lychee-v0.9.0-x86_64-unknown-linux-musl.tar.gz @@ -26,7 +26,7 @@ pipeline: branch: main secrets: [ ssh_key ] commands: - - apk add --no-cache git hugo just openssh-client rsync + - apk add --no-cache git hugo just openssh-client python3 rsync # lychee hasn't been packaged for Alpine Linux - apk add --no-cache curl - curl -LO https://github.com/lycheeverse/lychee/releases/download/v0.9.0/lychee-v0.9.0-x86_64-unknown-linux-musl.tar.gz diff --git a/Justfile b/Justfile index 527759a..4af3bec 100644 --- a/Justfile +++ b/Justfile @@ -22,6 +22,7 @@ clean: # build the site build site=hugo_baseurl +flags='--gc': clean cp data/recipes.yaml static/recipes.yaml + python scripts/opml_to_html.py hugo -b {{ site }} {{ flags }} # deploy @@ -34,6 +35,7 @@ deploy-staging: (build staging_url) # serve serve: + python scripts/opml_to_html.py hugo serve # run tests diff --git a/content/blog/minor-website-update-2023.md b/content/blog/minor-website-update-2023.md index a4df7e0..36814b0 100644 --- a/content/blog/minor-website-update-2023.md +++ b/content/blog/minor-website-update-2023.md @@ -17,7 +17,7 @@ Here are some changes I've made to my website so far: Some more things I hope to get to soon: - [x] Add a page for my fountain pens and inks -- [ ] Add a Blogroll page +- [x] Add a Blogroll page - [ ] Support photo album/ galleries. I was thinking of just embedding or linking to Google Photos albums, but it seems much nicer if it was fully integrated. - [ ] Add a favourite music page - [ ] Share to Mastodon link diff --git a/content/blogroll.md b/content/blogroll.md new file mode 100644 index 0000000..ad1110e --- /dev/null +++ b/content/blogroll.md @@ -0,0 +1,5 @@ ++++ +title = "Blogroll" ++++ + +{{< blogroll >}} diff --git a/scripts/opml_to_html.py b/scripts/opml_to_html.py new file mode 100644 index 0000000..c5e1b5a --- /dev/null +++ b/scripts/opml_to_html.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import xml.etree.ElementTree as ET + +if __name__ == "__main__": + f = open("static/blogroll.opml", mode="rt") + dest = open("layouts/shortcodes/blogroll.html", "w") + out = ET.Element("div", attrib={"class": "blogroll"}) + + tree = ET.parse(f) + root = tree.getroot() + + p = ET.Element("p") + p.text = "If the HTML URL is missing, the feed URL will be linked instead. You can also download my " + aa = ET.Element("a") + aa.attrib["href"] = "/blogroll.opml" + aa.text = "OPML file here." + p.append(aa) + out.append(p) + + for folder in root.findall("body")[0]: + heading = ET.Element("h3") + heading.text = folder.attrib["text"] + out.append(heading) + # print(folder.tag, folder.attrib) + + ul = ET.Element("ul") + for it in folder: + # print(it.tag, it.attrib) + li = ET.Element("li") + a = ET.Element("a") + + a.text = it.attrib["text"] + + # use xmlUrl instead: + if it.attrib["htmlUrl"] == "" or it.attrib["htmlUrl"] == "http:///": + a.attrib["href"] = it.attrib["xmlUrl"] + a.text += " (RSS)" + else: # use htmlUrl + a.attrib["href"] = it.attrib["htmlUrl"] + + li.append(a) + + ul.append(li) + + out.append(ul) + + # yeah, unicode to do str, not b'' (utf-8) + # print(ET.tostring(out, encoding="unicode")) + dest.write(ET.tostring(out, encoding="unicode")) diff --git a/static/blogroll.opml b/static/blogroll.opml new file mode 100644 index 0000000..9c725a7 --- /dev/null +++ b/static/blogroll.opml @@ -0,0 +1,52 @@ + + + + + Subscriptions-iCloud.opml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file