sbrs

Simple blog and RSS system
git clone git://git.christosmarg.xyz/sbrs.git
Log | Files | Refs | README | LICENSE

commit e479346f124ed904a30e425150c2285206e9751f
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu, 20 Aug 2020 22:16:32 +0300

initial commit

Diffstat:
AMakefile | 5+++++
AREADME.md | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautoblog | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ablogindex.html | 15+++++++++++++++
Arss.xml | 21+++++++++++++++++++++
Astyles.css | 21+++++++++++++++++++++
Atemplate.html | 16++++++++++++++++
7 files changed, 202 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,5 @@ +TARGET = autoblog +INSTALL_PATH = /usr/local/bin +.PHONY: install +install: $(TARGET) + cp $(TARGET) $(INSTALL_PATH) diff --git a/README.md b/README.md @@ -0,0 +1,64 @@ +# autoblog + +A small and simple blog and RSS shell script inspired by +[Luke Smith's lb](https://github.com/LukeSmithxyz/lb) but +with a few modifications to match my own workflow. + +## Features + +`autoblog` can do the following: + +* Set up a seperate `HTML` blog page with CSS styling +* Add the blog post on the website's main page and on the blog's index +* Add the blog post to an RSS feed +* List all the published posts +* Revise or delete an already published post + +## Installation + +Run the `Makefile` in order to install the script. It'll +be installed in `usr/local/bin/` + +```shell +$ cd path/to/autoblog/ +$ sudo make install +``` + +You must **always** run the script inside the website's +main directory. + +Alternatively, you can store the script inside your website's +main directory. + +## Preparation + +Inside the script, change the `website` and `author` variables +to your website's URL and your name and make sure the rest +of the variables are properly set to match your website's +structure. By default, all blog posts are stored in `blog/`. + +`autoblog` will search for `<!--BLOG-->` inside `index.html` and +`rss.xml` in order to put the blog post listings and RSS feed +respectively. Inside `blogindex.html` however, it will search for +`<!--BLOG [Month Year]-->` (e.g `<!--January 1800-->`). + +A `template.html` file needs to exist in your main directory +in order for the script to run properly. +That file is how you want your blog post's page to look like. See +my own `template.html` for more. The `TITLE`, `HEADER` and `AUTHOR` +fields must exist and be left as is. + +## Usage + +You can run the script with one of the following +options + +```shell +Options: + -n New post + -p Publish draft post + -e Edit draft post + -r Revise already published post + -d Delete draft post + -l List all published posts +``` diff --git a/autoblog b/autoblog @@ -0,0 +1,60 @@ +#!/bin/sh + +website="https://christosmarg.github.io" +author="Christos Margiolis" +blogdir="blog" +draftdir=".drafts" +blogindex="blogindex.html" +index="index.html" +rssfile="rss.xml" +template="template.html" +[ -z $EDITOR ] && EDITOR="vim" + +listposts() +{ + printf "Blog posts (Total: %d)\n" "$(ls $1 -I "*final*" | wc -l)" + ls -rc $1 -I "*-final*" | awk -F '/' '{print $NF}' | nl + read -erp "Choose a post to by number: " num + blogpost=$(ls -rc $draftdir -I "*-final*" | nl | grep -w " $num" | awk '{print $2}' | sed "s/\..*//") +} + +newpost() +{ + mkdir -p $draftdir + read -erp "Title: " title + blogpost=$(echo $title | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + $EDITOR "$draftdir/$blogpost.html" + sed "s/TITLE/$title/g;s/HEADER/$title/g;s/AUTHOR/$author/g;" $template > $draftdir/$blogpost-final.html +} + +publish() +{ + title=$(cat $draftdir/$blogpost-final.html | grep "<title>" | sed "s/<title>//;s/<\/title>//;s/ *//;") + sed -i "/<!--BLOG-->/r $draftdir/$blogpost.html" $draftdir/$blogpost-final.html + sed "s/</\&lt;/g;s/>/\&gt;/g;" "$draftdir/$blogpost.html" > $draftdir/$blogpost.xml + cp $draftdir/$blogpost-final.html $blogdir && rename $blogpost-final.html $blogpost.html $blogdir/$blogpost-final.html + printf "\t\t\t\t<li>%s &ndash; <a href=\"%s\">%s</a></li>\n" "$(date '+%Y %b %d')" "$blogdir/$blogpost.html" "$title" > $draftdir/$blogpost-htmlentry + printf "<item>\n\t<title>%s</title>\n\t<guid>%s</guid>\n\t<pubDate>%s</pubDate>\n\t<description>\n\t\t%s\n\t</description>\n</item>\n" "$title" "$website/$blogdir/$blogpost.html" "$(date '+%a, %d %b %Y')" "$(cat $draftdir/$blogpost.xml)" > $draftdir/$blogpost-rssentry + + #sed -i 40d $index # don't hardcode so much + sed -i "/<!--BLOG $(date '+%B %Y')-->/r $draftdir/$blogpost-htmlentry" $blogindex && echo "Blogindex... done." + sed -i "/<!--BLOG-->/r $draftdir/$blogpost-htmlentry" $index && echo "Index... done" + sed -i "/<!--BLOG-->/r $draftdir/$blogpost-rssentry" $rssfile && echo "RSS... done" + rm -f $draftdir/$blogpost* + echo "Published $blogpost" +} + +delete() +{ + rm $draftdir/$blogpost.html +} + +case $1 in + n*) newpost ;; + p*) listposts $draftdir && publish ;; + e*) listposts $draftdir && $EDITOR $draftdir/$blogpost.html ;; + r*) listposts $draftdir && revise ;; + d*) listposts $draftdir && delete ;; + l*) listposts $blogdir ;; + *) printf "Usage: autoblog [OPTION]\n\nOptions:\n -n\t\tNew post\n -p\t\tPublish post\n -e\t\tEdit draft post\n -r\t\tRevise already published post\n -d\t\tDelete draft post\n -l\t\tList all draft posts\n" +esac diff --git a/blogindex.html b/blogindex.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> + <link rel="stylesheet" href="styles.css"/> + <title>Blog Index</title> + </head> + + <body> + <!--BLOG [Month Year]--> + <h2>Month Year</h2> + <ul> + </ul> + </body> +</html> diff --git a/rss.xml b/rss.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8" ?> +<rss version="2.0"> + +<channel> +<title>Your RSS Feed Title<title> +<description>Sample Description</description> +<link>https://yourwebsite.com/rss.xml</link> + +<!--BLOG--> + +<item> + <title>Sample post</title> + <guid>https://yourwebsite.com/sample-post.html</guid> + <pubDate>Wed, 11 Aug 1900</pubDate> + <description> + &lt;p&gt;Sample post.&lt;/p&gt; + </description> +</item> + +</channel> +</rss> diff --git a/styles.css b/styles.css @@ -0,0 +1,21 @@ +html { + max-width: 1050px; + margin-left: auto; + margin-right: auto; + margin-top: 30px; + color: #333; + padding-bottom: 200px; + } + +a {color: royalblue; } +a:hover {color: lightblue; } + +.entry { + border-left: 10px solid darkslategray; + padding: 0px 10px 0px 10px; + border-radius: 0 30px 30px 0; + margin-bottom: 20px; + background-color: #eee; + } + +.entry h2 { margin: 5px auto 2px auto; } diff --git a/template.html b/template.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> + <link rel="stylesheet" href="styles.css"/> + <title>TITLE</title> + </head> + + <body> + <h1>HEADER<h1> + + <!--BLOG--> + + <center>by <a href="../index.html">AUTHOR</a></center> + </body> +</html>