~bpv/sbs

9b8144c98b7a36498032211870507ebf5428914e — Bryce Vandegrift 5 months ago 1538443
Version 1.0.0
2 files changed, 67 insertions(+), 12 deletions(-)

M README.md
M sbs
M README.md => README.md +52 -2
@@ 1,5 1,55 @@
# sbs
Static Blogging System

## Note:
This program is not in working condition yet.
sbs is a POSIX compliant static blog generator that generates an HTML blog, an RSS feed,
and a rolling blog page from Markdown.

## Installation

First, make sure [Pandoc](https://pandoc.org/) is installed on your system.

In order to use sbs the `<!-- SB -->` (start blog) tag needs to be added
to your RSS, home page, and rolling blog pages in order to enable those
features. You can use my website repository as an example [here](https://git.sr.ht/~bpv/website)
or my actual website [here](https://brycevandegrift.xyz).

Change all the variables in the beginning of the script according to your
own website specifications as well as create the:
- Website directory
- Blog Directory
- RSS file
- Rolling blog page in blog directory
- Drafts directory
- Home page (index.html)
- CSS stylesheet
- Website icon

You can also set your `EDITOR` variable to use your preferred text editor,
otherwise vi is used by default.

sbs can also be used on a directory by directory basis, just change the
`website_dir` variable to `$(pwd)`.

## Usage

```
sbs new		# Create a new blog post
sbs edit	# Quickly edit existing draft
sbs publish	# Publish a draft and turn it into a webpage
sbs delete	# Delete a draft
sbs help	# Show quick help
sbs version	# Show version
```

## Bugs

Please report any bugs or errors to [bpv@disroot.org](mailto://bpv@disroot.org).

## Contributions

Parts of this program were used from [Luke Smith's blog generation script](https://github.com/LukeSmithxyz/lb).

## Notice

In the future I plan to expand on this script in order to add more features
as well as to make it more portable and easier to use.

M sbs => sbs +15 -10
@@ 7,11 7,11 @@

name="Bryce Vandegrift"
website="https://brycevandegrift.xyz"
website_dir="/home/bryce/Documents/website" # Absolute path to website directory
blog_dir="blog"
website_dir="/home/bryce/Documents/website" # Absolute path to website directory (replace with $(pwd) for local dir use)
blog_dir="blog" # Blog directory relative to website directory
blogindex="blog/index.html"
rssindex="rss.xml"
draft_dir=".drafts"
rssindex="rss.xml" # RSS index relative to website directory
draft_dir=".drafts" # Draft directory relative to website directory
html_css_path="//brycevandegrift.xyz/index.css" # Path to css stylesheet
html_icon_path="//brycevandegrift.xyz/p/icon.ico" # Path to web icon



@@ 46,13 46,18 @@ publish() {
	listDrafts publish "$@"
	dir_name=$(echo $choice | sed 's/.md$//g')
	date=$(date '+%a, %d %b %Y %H:%M:%S %z')
	url="$website/blog/$dir_name"
	url="$website/blog/$dir_name/$dir_name.html"
	contents=$(pandoc -f markdown -t html "$website_dir/$draft_dir/$choice")
	title=$(echo "$contents" | grep "<h1.*</h1>$" | sed 's/<\/h1>$//g' | sed 's/^<h1\s.*>//g')
	tmp_dir=$(mktemp -d)
	printf "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"utf-8\">\n<link rel=\"icon\" href='%s' type=\"image/x-icon\">\n<link rel=\"stylesheet\" href='%s'>\n<title>%s</title>\n</head>\n<body>\n%s\n</body>\n</html>" "$html_icon_path" "$html_css_path" "$title" "$contents" > $tmp_dir/blog.html
	printf "\n<item>\n<title>%s</title>\n<guid>%s</guid>\n<link>%s</link>\n<pubDate>%s</pubDate>\n<description>\n%s\n</description>\n</item>" "$title" "$url.html" "$url.html" "$date" "$contents" > $tmp_dir/rss.xml
	printf "\n<li>%s - <a href='%s'>%s</a></li>" "$(date '+%b %d, %Y')" "$url.html" "$title" > $tmp_dir/preview.html
	mkdir $website_dir/$blog_dir/$dir_name
	printf "<!DOCTYPE html>\n<html lang=\"en\" dir=\"ltr\">\n<head>\n<meta charset=\"utf-8\">\n<link rel=\"icon\" href='%s' type=\"image/x-icon\">\n<link rel=\"stylesheet\" href='%s'>\n<title>%s</title>\n</head>\n<body>\n%s\n</body>\n</html>" "$html_icon_path" "$html_css_path" "$title" "$contents" > $website_dir/$blog_dir/$dir_name/$dir_name.html
	printf "\n<item>\n<title>%s</title>\n<guid>%s</guid>\n<link>%s</link>\n<pubDate>%s</pubDate>\n<description>\n%s\n</description>\n</item>\n" "$title" "$url.html" "$url.html" "$date" "$contents" > $tmp_dir/rss.xml
	printf "\n<li>%s - <a href='%s'>%s</a></li>\n" "$(date '+%b %d, %Y')" "$url.html" "$title" > $tmp_dir/preview.html
	sed -i "/<!-- SB -->/r $tmp_dir/rss.xml" $website_dir/$rssindex
	sed -i "/<!-- SB -->/r $tmp_dir/preview.html" $website_dir/$blogindex
	sed -i "/<!-- SB -->/r $tmp_dir/preview.html" $website_dir/index.html
	rm -f $website_dir/$draft_dir/$choice
}

delete() {


@@ 70,9 75,9 @@ Operations:
	sbs publish
	sbs delete
        sbs help
                Show this text
        sbs version
                Show program version

Read README.md for more details.
EOF
}