lb

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 333589cb21b3c54268e1305cddd08c8b9d9b12e4
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Wed, 16 May 2018 14:46:29 -0700

first payload

Diffstat:
A2018.html | 25+++++++++++++++++++++++++
AREADME.md | 41+++++++++++++++++++++++++++++++++++++++++
Ablog/.htaccess | 1+
Ablog/this-is-what-a-post-looks-like.html | 3+++
Alb | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arss.xml | 28++++++++++++++++++++++++++++
Astyle.css | 21+++++++++++++++++++++
7 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/2018.html b/2018.html @@ -0,0 +1,25 @@ +<html> +<head> +<title>Blog</title> +<meta charset="utf-8"/> +<link rel='stylesheet' type='text/css' href='style.css'> +</head> + +<body> +<h1>Blog</h1> + +<p>The blog content will appear below here.</p> + +<!-- LB --> + +<div class="entry"> +<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> +<small>Wed, 16 May 2018 14:38:38 -0700</small> +</div> + + +</body> +</html> + diff --git a/README.md b/README.md @@ -0,0 +1,41 @@ +# lb -- Luke's Blog Script + +Blogs and RSS feeds in less than 100 lines of shell script. `lb` stands for whatever. Maybe "Luke's blog", maybe "lightweight blog", maybe "less bloat", doesn't matter that much. + +## Features + ++ Create and publish blog posts for your website. The intended format is for all posts to appear in a rolling blog post. See [https://lukesmith.xyz/2018.html](https://lukesmith.xyz/2018.html) for an example. ++ Custom links are generated for these entries in the form of [standalone files](https://lukesmith.xyz/blog/) and links to the headings of each blog post so you can link people to specific blog posts on the rolling blog. ++ Blog posts are automatically added to your RSS feed when finalized. ++ One command to delete published entries from the RSS feed, rolling blog and standalone entries simultaneously. ++ Posts in the rolling blog have divs that can easily be modified via a CSS stylesheet. + +## Usage + +``` +./lb new # Make a new blog post draft. +./lb finalize # Finalize/publish a blog post draft. +./lb delete # Delete a published blog post. +``` + +Finished posts are in `blog/`; Drafts are in `blog/.drafts/`. Use `./lb delete` to remove finished posts, because this command removes the .html files *and* the entries from the RSSfeed and rolling blog. + +## Installation + ++ Download the `lb` script and put it in your website's home directory. The expectation is that your rolling blog file and RSS feed will be there as well. ++ Open the script and change the first few variables to match the files you use in your website. ++ Add markers for where the new blog posts are added. Don't skip this step. See below. + +### Markers + +For the system to work, add the following comment line where you'd like to both your RSS feed and the HTML file you'd like to use as a rolling blog. + +``` +<!-- LB --> +``` + +When you `finalize` a blog post, it will be added directly below that line in the proper format (either HTML or the proper RSS/XML format), give you the rolling blog and RSS feed for free. + +## Other stuff + +The other files in the repo are an illustration of how the bare bones of the blog can work. The HTML entries create divs with the id "entry", which allows you to modify them with a CSS stylesheet. diff --git a/blog/.htaccess b/blog/.htaccess @@ -0,0 +1 @@ +AddDescription "This is what a post looks like" this-is-what-a-post-looks-like.html diff --git a/blog/this-is-what-a-post-looks-like.html b/blog/this-is-what-a-post-looks-like.html @@ -0,0 +1,3 @@ +<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> diff --git a/lb b/lb @@ -0,0 +1,64 @@ +#!/bin/bash + +# Set your personal data here: +rssfile="rss.xml" +blogfile="2018.html" +website="https://lukesmith.xyz/" +dir=$(pwd) + +getHelp() { \ + echo -e "This system will take the blog entries you write and add them into the RSS file and HTML file of your choosing. Set which files to use by editing the 'lb' file directly and changing the variables at the top.\n" + echo -e "To fully prepare these files, add the following line to both files where you want the content to be added:\n" + echo -e "<!-- LB -->\n" + echo -e "Usage: 'new': create new draft; 'finalize': finish draft and add it to the RSS and HTML page; 'delete': delete a finished page.\n" + echo -e "As you finalize posts, they will be appended in the appropriate format below that line.\n" + echo -e "Blog posts will be stored in 'blog/' and drafts will be in 'blog/.drafts/'. To delete drafts, you only need delete their .html files directly, but use the 'lb delete' command to remove finalized posts since they appear in three places." +} + +listandReturn() { \ + echo "Listing contents of $1." + ls $1 | nl + read -p "Pick an entry by number to $2, or press ctrl-c to cancel. " number + chosen=$(basename $(ls $1 | nl | grep -w "$number" | awk '{print $2}')) + } + +getTitle() { \ + echo "Post will be stored as draft in $dir/blog/.drafts until finalized." + read -p "Give a title for your post: " title + url=$(echo $title | sed -e "s/'\|\"\|=\|+\|_\|,\|:\|;\|?\|!\|@\|\*\|&\|(\|)\|[\|]\|<\|>//g;s/ /-/g" | tr '[:upper:]' '[:lower:]') ;} + +postNew() { \ + mkdir -p $dir/blog/.drafts + echo -e "<h2 id='$url'>$title</h2><small>[<a aria-hidden=\"true\" href=\"$blogfile#$url\">link</a>&mdash;<a href=\"blog/$url.html\">standalone</a>]</small>\n\n<++>" >> $dir/blog/.drafts/$url.html && $EDITOR $dir/blog/.drafts/$url.html ;} + +finalize() { \ + listandReturn $dir/blog/.drafts finalize + url=$(cat $dir/blog/.drafts/$chosen | grep -o "<h2 id='\(.\)*'>" | cut -d "'" -f2) + title=$(cat $dir/blog/.drafts/$chosen | grep -o "<h2 id='\(.\)*h2>" |sed -e 's/<[^>]*>//g') + echo "AddDescription \"$title\" $chosen" >> $dir/blog/.htaccess + rssdate=$(date '+%a, %d %b %Y %H:%M:%S %z') + webdate=$(date '+%a, %d %b %Y %H:%M:%S %z') + tmpdir=$(mktemp -d) + echo -e "\n<item>\n<title>$title</title>\n<guid>$website$blogfile#$url</guid>\n<pubDate>$rssdate</pubDate>\n<description><![CDATA[\n$(cat $dir/blog/.drafts/$chosen)\n]]></description>\n</item>\n"> $tmpdir/rss.xml + echo -e "\n<div class=\"entry\">\n$(cat $dir/blog/.drafts/$chosen)\n<small>$webdate</small>\n</div>\n" > $tmpdir/html.html + sed -i "/<!-- LB -->/r $tmpdir/html.html" $blogfile + sed -i "/<!-- LB -->/r $tmpdir/rss.xml" $rssfile + mv $dir/blog/.drafts/$chosen $dir/blog/$chosen +} + +delete() { \ + listandReturn "$dir/blog/*.html" delete + base=$(echo $chosen | cut -f1 -d'.') + read -p "Really delete \"$base\"? (y,N) " choice + [[ $choice =~ [Yy] ]] || exit + rm $dir/blog/$chosen && echo "Blog post deleted from directories." + sed -i "/<item/{:a;N;/<\/item>/!ba};/$base/d" $rssfile && echo "Entry removed from RSS feed file." + sed -i "/<div/{:a;N;/<\/div>/!ba};/$base/d" $blogfile && echo "HTML code removed from blogfile." + } + +case "$1" in + new) getTitle && postNew ;; + finalize) finalize ;; + delete) delete ;; + *) getHelp ;; +esac diff --git a/rss.xml b/rss.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<?xml-stylesheet type="text/css" href="rss.css" ?> +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> + +<channel> +<title>Your RSS Feed Title</title> +<description>A brief description of your RSS feed.</description> +<language>en-us</language> +<link>http://yourwebsite.com/rss.xml</link> +<atom:link href="http://yourwebsite.com/rss.xml" rel="self" type="application/rss+xml" /> + +<!-- LB --> + +<item> +<title>This is what a post looks like</title> +<guid>https://lukesmith.xyz/2018.html#this-is-what-a-post-looks-like</guid> +<pubDate>Wed, 16 May 2018 14:38:38 -0700</pubDate> +<description><![CDATA[ +<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> +]]></description> +</item> + + +</channel> +</rss> + diff --git a/style.css b/style.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; }