~hristoast/hristoast

c80bab2fc0f96a4cd77971c639ef979f7fb7397d — Hristos N. Triantafillou 7 months ago dc08600
The RSS feed returns
5 files changed, 87 insertions(+), 10 deletions(-)

M .build.yml
M Makefile
A scripts/json2feed.py
M soupault.conf
M templates/main.html
M .build.yml => .build.yml +3 -2
@@ 4,7 4,8 @@ environment:
  soupault_version: 1.10.0
packages:
  - highlight
  - python3-pystache
  - make
  - python3-feedgenerator
  - rsync
  - wget
secrets:


@@ 22,7 23,7 @@ tasks:
      sudo mv -v ./soupault-$soupault_version-linux-x86_64/soupault /usr/bin/
  - build: |
      cd ./hristoast
      soupault --verbose
      make prod-site
  - deploy: |
      cat > ~/.ssh/known_hosts <<EOF
      $(cat ~/.hristoast_known_hosts)

M Makefile => Makefile +8 -3
@@ 2,7 2,12 @@ proj_dir := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

.DEFAULT_GOAL:= rebuild-staging

build-site:
prod-site:
	soupault --verbose
	soupault --index-only
	$(proj_dir)/scripts/json2feed.py index.json > $(proj_dir)/build/feed.xml

staging-site:
	soupault --verbose

clean:


@@ 14,6 19,6 @@ deploy:
deploy-staging:
	rsync -aPv --delete build/ hristoast@hristoast:~/staging/

rebuild: clean build-site deploy
rebuild: clean prod-site deploy

rebuild-staging: clean build-site deploy-staging
rebuild-staging: clean staging-site deploy-staging

A scripts/json2feed.py => scripts/json2feed.py +68 -0
@@ 0,0 1,68 @@
#!/usr/bin/env python3

# Adapted from:
# https://github.com/dmbaturin/baturin.org/blob/be8feeb8cf369ce73f601a3e4fc9f43f22b9d758/scripts/json2feed.py

import sys
import json
import dateutil.tz
import dateutil.parser

from datetime import datetime
from feedgen.feed import FeedGenerator


base_url = "https://hristos.co"

default_date = datetime(1970, 1, 1, tzinfo=dateutil.tz.gettz("Etc/UTC"))

feed_id = base_url + "/feed.xml"
feed_author = "Hristos N Triantafillou"
feed_title = feed_author + "'s blog"
feed_subtitle = "On programming and things related and not"
feed_logo = base_url + "/img/slime.png"
feed_language = "en"
feed_author_email = "me@hristos.co"


def get_date(ds):
    try:
        return dateutil.parser.parse(ds, default=default_date).isoformat()
    except Exception:
        return default_date


fg = FeedGenerator()
fg.id(feed_id)
fg.title(feed_title)
fg.subtitle(feed_subtitle)
fg.author({"name": feed_author, "email": feed_author_email})
# fg.link( href=, rel='alternate' )
fg.logo(feed_logo)
fg.language(feed_language)

index_file = sys.argv[1]

with open(index_file, "r") as f:
    entries = json.load(f)

for entry in entries:
    entry["author"] = feed_author

    if not entry["title"] or not entry["date"]:
        continue

    fe = fg.add_entry()

    url = base_url + entry["url"]

    fe.id(url)
    fe.link(href=url, rel="alternate")
    fe.title(entry["title"])
    fe.content(entry["excerpt"], type="html")
    fe.updated(get_date(entry["date"]))


atomfeed = fg.atom_str(pretty=True).decode()

print(atomfeed)

M soupault.conf => soupault.conf +5 -5
@@ 30,19 30,19 @@

[index]
  index = true
  index_selector = "#blog-index"
  index_title_selector = "h1#title"
  index_date_selector = ["time#post-date", "time"]
  index_excerpt_selector = ["p#post-excerpt", "p"]
  dump_json = "index.json"
  newest_entries_first = true
  use_default_view = false

  exclude_path_regex = ["site/404.html", "site/contact.html", "site/gpg.html", "site/init.el.html",
                        "site/livejam.html", "site/now-playing.html", "site/privacy.html",
                        "site/projects.html", "site/radio.html", "site/xbps.html", ]
                        "site/projects.html", "site/radio.html", "site/video/(.*)", "site/xbps.html"]

[index.views.blog]
  index_selector = "#blog-index"
  index_title_selector = "h1#title"
  index_date_selector = ["time#post-date", "time"]
  index_excerpt_selector = ["p#post-excerpt", "p"]
  index_item_template = """
<div class="entry">
<h3><a href="{{url}}">{{{title}}}</a></h3>

M templates/main.html => templates/main.html +3 -0
@@ 22,6 22,9 @@
            <a href="/">Blog</a>
          </li>
          <li>
            <a href="/feed.xml">RSS</a>
          </li>
          <li>
            <a href="/contact/">Contact</a>
          </li>
          <li>