- About
- Demo
- Features
- How it works
- Requirements
- Installation
- How to use Bourne to Blog
- Modules
- Other use cases
- To-do
Bourne to Blog is a bash script to create blog posts from .md
files in a simple manner.
You can take a look at this blog post for additional information on my motivation to create this tool
You can take a look at my blog for a sample of what type of blog posts will be produced by using Bourne to Blog.
You can also take a look at others' blogs created with Bourne to Blog here.
Bourne to Blog is meant to be simple and easy to use, these are the features currently implemented:
- Generate blog posts from Markdown files
- Publish blog posts to a public web server via SFTP
- Build and publish RSS feed
- Build and publish posts page
- Build and publish sitemap.xml
Bourne to Blog is designed to be installed on a common-access computer (laptop / desktop) with access to a public web server over SFTP (Internet).
The expected workflow is the following:
- A Bash CLI environment (Not yet tested on other shell environments but I believe it should work as well)
- The discount markdown to html conversion tool
- An existing SFTP capable server (Only for publishing)
Installing Bourne to Blog is simple, below are some detailed instructions on the process.
- Download the
blog
file from the repository - Place it in the
/usr/local/bin
directory - Make your local user the owner of the
/usr/local/bin/blog
file - Enable execution privileges for the
/usr/local/bin/blog
file - Edit the
/usr/local/bin/blog
file variables to fit your environment
Along with the core script I have also provided some sample files (header, footer and CSS) to serve as a starting point. You can find these in the samples
folder in the repository. These files provide the basics you'll need to get started with building your blog with Bourne to Blog.
In order to keep Bourne to Blog as safe as possible the sftp connection uses the built in OpenSSH identity_file mechanism that should be available on any system that can invoke the SSH command. This ensures that you don't use a clear text password while using Bourne to Blog.
In case you already have a password-less public / private SSH key pair you can use that, otherwise you can generate them as follows.
Execute the following commands from your terminal:
$ cd ~/.ssh
$ ssh-keygen -t ed25519
Press the enter key when prompted for a password to leave the key pair without a password.
Copy the generated public key to your SFTP server:
$ ssh-copy-id -i ~/.ssh/ed25519.pub [email protected]
- Install the discount library with your system's preferred method
- Ensure that you have
/usr/local/bin/
in your$PATH
i.e.$ echo $PATH
su - root
wget https://raw.githubusercontent.com/grokkingnix/bourne-to-blog/master/blog -P /usr/local/bin/
chown YOUR_USER:YOUR_USER_GROUP /usr/local/bin/blog
i.e.chown username:groupname /usr/local/bin/blog
chmod +x /usr/local/bin/blog
- Configure all the variables with your favorite text editor i.e.
vim /usr/local/bin/blog
Details of how to use Bourne to Blog with some examples.
Build all posts in the $SOURCE_DIR
:
$ blog -b
Build a single post from the current directory:
$ blog -bs filename.md
Build and publish all posts in the $SOURCE_DIR
(will not overwrite duplicates):
$ blog -bp
Build and force publish all posts in the $SOURCE_DIR
(will overwrite duplicates):
$ blog -bz
Build and publish a single post in the current directory (will overwrite duplicates):
$ blog -bps filename.md
Build and publish a single post with custom header and footer:
$ blog -bps filename.md -h custom-header.html -f custom-footer.html
Build/publish the blog index page from already published posts in the $BLOG_DIR
of the SFTP server (generates a list of blog entries with publish dates):
$ blog -m
Build/publish the blog index page, build/publish the RSS feed and build/publish the sitemap from already published posts:
$ blog -mrS
- Simply create a text file using the markdown extension
.md
with your favorite text editor, for example:
# This is my first blog post!
## It was very simple to accomplish
This is my first blog post using `Bourne to Blog`
-
From the command line run the
blog -b
command to build your first blog post, at this point you can preview what your blog post will look like before publishing it publicly. The generated.html
file will be stored in the$WORK_DIR
directory. -
Once you like the way your blog post looks you can publish it to your public web server with
blog -p
.
Done! You can now visit your public web server address ($BLOG_DOMAIN
) and read your blog post!
In case you have any doubts about what the different options do, you can run blog -H
to get some help.
In addition to the preset header and footer files that you configure, you can also specify the header and footer file on the fly for your posts. This feature can be beneficial when creating different type of posts within your blog.
To specify the header file you can use the -h
flag with the path to your file as an argument, i.e.:
$ blog -bh /home/user/header-file
To specify the footer file you can use the -f
flag with the path to your file as an argument, i.e.:
$ blog -bf /home/user/footer-file
To build a post with custom header and footer:
$ blog -bh /home/user/header-file -f /home/user/footer-file
You can include custom messages in your posts by simply typing one of three message keywords:
Info:
Warning:
Danger:
Bourne to Blog will detect any lines that begin with these key words and will apply a class to them, this can be used together with CSS to create custom messages.
You can check the samples' style-sample.css to see an example of CSS that could be used. This is what it would look like in practice:
By default Bourne to Blog does not overwrite the posts that already exist on your public SFTP server when using the -p
flag. This avoids re-publishing posts and ultimately saves bandwidth.
In case you'd like to force all built posts (all posts in $WORk_DIR
)to be published to your public SFTP server regardless of whether those posts already exist or not, you can use the -z
option, i.e.:
$ blog -bz
By default when you build and publish posts Bourne to Blog will do this in batches. So if you have several articles you can simply run blog -bp
, this will build all posts in $SOURCE_DIR
and publish them with this single command (This will not overwrite any duplicate file names in the SFTP server).
Alternatively you can build and publish a single post by using the -s
flag, i.e.:
blog -bps file.md
This command will only build and publish the specified file file.md
.
You can build and publish the blog index page with the -m
option. Depending on your blog setup this can be thought of as your home page. These variables need to be specified for this option to work:
BLOG_DOMAIN
: This is your blog web address i.e.:https://domain.com
BLOG_MAIN
: The relative path on your web server where your blog index page resides i.e.:/
would mean that your index page resides in the root of your web server.BLOG_INDEX
: File name of your blog index page i.e.:index.html
$MAIN_HEADER_FILE
: Full path to the header file to be used for the blog index page i.e.:/home/user/main-header-file.html
The -m
option will get all of the posts currently published on your website (from $BLOG_DIR
) and create a local list, then build a new page and upload it to your public ftp server.
This option requires for your post .md
files to start with the following style of heading:
# CSS Grid Navigation Bar
##### Published: 2020-08-20 | Last Updated: 2021-02-02 | ~8 Minute Read
This is because of how each post is parsed, the title and published date are expected to be in this specific format. If you have a different format, your index page will not be built as expected.
For an example of how this index page will look please see here.
You can use the -r
option in order to publish an updated RSS feed of our post entries. This feature is meant to be used along with the -m
option when publishing a new post to your blog. The RSS feed <items>
get created based on the format that the -m
options generates.
Examples:
This will build and publish a feed.xml
file based on the contents of your blog index page:
$ blog -r
You can use the -S
option in order to publish an updated sitemap from post entries. This feature is meant to be used along with the -m
option when publishing a new post/s to your blog. The sitemap.xml <url>
tags get created based on the format that the -m
options generates.
Examples:
This will build and publish a sitemap.xml
file based on the contents of your blog index page:
$ blog -S
Bourne to Blog aims to be modular, below are some modules that have been created to add functionality to the core set of features.
You can make use of openring with the -o
flag when building your posts. You need the additional openring.sh
file from the modules
folder. Configure the variable values and you can add the flag to your regular post build/publish workflow i.e. blog -bops post-file.md
. You can find more details on this post.
Below are some additional use cases for Bourne to Blog that may be of interest to some.
You can create your very own Wiki with Bourne to Blog, take a look at the samples
folder for the files that can help you. You can see a detailed step by step guide here
Add sitemap.xml featureAdd post title to HTML title tagIntegrate openringGenerate valid RFC822 date-times in the RSS feedAdd visible SVG icon with link to post id tag sectionsAdd RSS feed featureAdd option to build main blog index fileAdd sample header fileAdd sample footer fileAdd sample CSS fileAdd option to build a single articleAdd option to publish a single articleAdd option to specify header and footer files to build posts withAdd CSSid
attribute o allh2-h4
HTML tagsAdd major Linux distribution installation instructionsAdd CSS class selector in order to display messages