Use Staticman and a bit of python to add a feed submission form to Pluto Static Feed Reader

10 views
Skip to first unread message

infominer

unread,
Oct 6, 2020, 11:59:42 PM10/6/20
to wwwmake
I just added this form to my planet

https://identosphere.net/blogcatcher/


Staticman enables comments on sites hosted by GitHub Pages.

If you clone the dev branch and click the "Deploy to heroku" button from your cloned(not forked) repo it's not too much trouble to get running from there. (You need to make a bot account on github)

After you fill out the form on your feed, the data file it submits with a pull-request is perfect for updating your planet.ini file with a bit of python and some github actions magic.

Once I approve the pull request, the submission is automatically added to the ini file and the page is re-built.

import yaml, os

input = os.environ.get('relative') + os.environ.get('config')
output = os.environ.get('ini')

submission = "\n"

with open(input,'r') as file:
feed = yaml.load(file, Loader=yaml.FullLoader)
for k, v in feed.items():
if k == "_id":
submission += '[' + v + ']'
if k == "title":
submission += '\n title = ' + v
if k == "link":
submission += '\n link = ' + v
if k == "feed":
submission += '\n feed = ' + v
file.close

print(submission)

with open(output,'a') as ini:
ini.write(submission)
ini.close

----

name: addblog

on:
push:
paths:
- '_data/feeds/planetid'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.7.5'
- uses: py-actions/py-dependency-install@v2
- shell: bash
run: export relative=_data/feeds/planetid/ && export config=$(ls -t _data/feeds/planetid | head -1) && export ini=planetid.ini && python addfeed.py
- name: Deploy Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git pull
git commit -a -m "add organization"
git push gh-token master

---

Then of course I have a trigger on my workflow that builds the reader whenever the ini files are updated.

:tada: :D

Gerald Bauer

unread,
Oct 7, 2020, 2:54:17 AM10/7/20
to www...@googlegroups.com
Hello,
As always thanks for sharing the tip / setup. Great to see your
planet live @ https://identosphere.net/blogcatcher/
I am a big fan of Simon Willison's Datasette - great to see the
blog and weekly notes included / featured. Keep it up. Cheers. Prost.
Reply all
Reply to author
Forward
0 new messages