added `sup` for classical site updating

This commit is contained in:
Luke Smith 2020-09-02 13:04:42 -04:00
parent c29080a25e
commit 7a638fbc59
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252
3 changed files with 102 additions and 15 deletions

View File

@ -1,10 +1,15 @@
# lb -- Luke's Blog Script
# lb and sup -- Luke's Blog Script and Site Updater
Blogs and RSS feeds in less than 100 lines of shell script, actually, right now, less than 80. `lb` stands for whatever. Maybe "Luke's blog", maybe "lightweight blog", maybe "less bloat", doesn't matter that much.
Blogs and RSS feeds in less than 100 SLOC. `lb` stands for whatever. Maybe "Luke's blog", maybe "lightweight blog", maybe "less bloat", doesn't matter that much.
[Video Showcase](
## Features
I've also added `sup`, which is even more minimal and focused on old-school static websites with no blog, but a need for a site updater! See it at the bottom of this README.
Both `lb` and `sup` are mutually compatible and you can use them both on the same site and even feed into the same RSS feed.
`lb` makes new blog posts which go to make standalone pages, a rolling blog file and an RSS entry. `sup`, on the other hand, is if you manually add a new page to your website and want to make people know about that change. It can be run multiple times on a page for each time it is updated.
## `lb` Features
`lb` is an extremely small shell script that lets you write blog posts and will format them in all the ways you could ever want. Here's what it will produce:
@ -56,3 +61,28 @@ When you `finalize` a blog post, it will be added directly below that line in th
- `blog/.htaccess` acts as a "database" file. `lb` stores filenames with their corresponding proper names and publishing dates there.
- The other files in this repo just illustrate how you can use `lb`. Only the `lb` script itself is necessary.
- Your `$EDITOR` variable should be set to your preferred text editor, vim will be assumed if you don't have one set.
# `sup` -- Site updater or "What'**s up**?"
If having a "blog" is too cringe for you and you just want an RSS feed where you can post updates about recently changed pages, use `sup`.
Let's say you make a page called `favorite-programs.html`.
Just run `sup favorite-programs.html` and that new page's content will be added to the RSS feed.
Specifically, `sup` will get only the `<body>` tag, but also exclude the `<nav>` and `<footer>` tags. All the rest of the content will be directly viewable via RSS.
If you update that page in the future, run `sup` on it again and it will prompt you for an update message
## Installation of `sup`
Just add the
<!-- LB -->
line in your RSS feed like for `lb` above and be sure to change the variables (rss file name and website) in the `sup` script.
**`sup` and `lb` are fully compatible and can be run on the same website for different purposes.**

View File

@ -11,18 +11,6 @@
<!-- LB -->
<title>This is what a post looks like</title>
<pubDate>Wed, 16 May 2018 14:38:38 -0700</pubDate>
<h2 id='this-is-what-a-post-looks-like'>This is what a post looks like</h2><small>[<a aria-hidden="true" href="2018.html#this-is-what-a-post-looks-like">link</a>&mdash;<a href="blog/this-is-what-a-post-looks-like.html">standalone</a>]</small>
<p>This is autogenerated by the blog. As you can see, an equivalent RSS feed entry and standalone blog post is generated after you finalize the post.</p>

sup Executable file
View File

@ -0,0 +1,69 @@
[ ! -f "$1" ] &&
echo "Give \`sup\` a page which has been added/updated." &&
exit 1
# You will want to change these variables to your needs.
# In order to cleanly use sed on a multi-line file, we have to use `tr` to
# convert newlines to a set character, then run sed, then reconvert the
# character. Unfortunately, due to a current issue in GNU's tr, characters of
# more than one byte are not functioning properly. It would be more ideal to
# use a rarer character (some random Tamil character, for example), but ^ is
# one byte.
# So if you have a page with ^ in it, you'll have to change this to another
# single byte character that isn't in the page like ~ or something.
title="$(sed -n 's/<title>\(.*\)<\/title>/\1/Ip' "$1")"
# Check and see if this page has already been added to the RSS feed.
if grep -q "<guid.*>$link</guid>" "$rssfile"; then
# Do this if it has been adding and we are updating it.
# If updating a file, we append the time/date to the GUID, as all GUIDs
# must be unique to validate an RSS feed. Even feed readers that follow
# GUIDs will still be lead to the same page with this.
guid="$link#$(date '+%y%m%d%H%M%S')"
title="$title (Updated)"
echo "Explain the nature of the update:"
read -r content
[ -z "$content" ] && content="New updates to $link"
# Do this if it is a new page.
# Get the page body content, excluding the nav and footer.
content="$(tr '\n' $replchar < "$1" | sed "
" | tr -s $replchar '\n')"
rssdate="$(LC_TIME=en_US date '+%a, %d %b %Y %H:%M:%S %z')"
# Eh, I'm a brainlet and I'm not sure how to elegantly add in the content to
# the RSS feed without first writing it out to a file. This is because if we
# tried run, say, a sed substitute command, we'd have to escape with \
# basically every other character. If you know how to do it without creating a
# temporary file, tell me. I do the same in lb, actually.
trap 'rm -f "$temp"' 0 1 2 3 15 # Delete temp file after script termination.
echo "
" > "$temp"
sed -i "/<!-- LB -->/r $temp" "$rssfile"