WordBash

The WordPress clone written in GNU Bash

header image

Introduction to WordBash

Posted on Oct 18, 2013 14:35PM

WordBash is a Bash Shell Script

WordBash is written, if you do not already know, in Bash, the GNU Bourne-Again SHell. All content is generated by a shell script. All comments are parsed, stored and displayed by Bash. And when I say the code is written in Bash, I mean (with only one exception explained later): No SED. No AWK. No TR. Just 100% Bash.

It has been tested with Linux, Mac OS-X and Windows/Cygwin. Bash at least 3.2 is required.

These posts will describe WordBash in detail, and make some claims about it. Ultimately though, of course, the code gets the last word.

About the Code

Posted on Nov 5, 2013 14:35PM

This version of WordBash lacks the Admin code and some features.

WordBash is Weird

If you have looked at the source code you are probably shaking your head in bewilderment as WordBash is not written an any sort of "standard" style. I do some things that nobody else does or would do; but there is a reason to my madness. I may appear to be trying to obfuscate the code; on the contrary, it should become clear.

The file readme.txt explains the variable naming convention I chose, and over time things have gotten a bit more complicated than I imply here (it's essentially this post updated).

WordBash is written in a unique style of my own making because I was working with only the Bash man page at the time (it provides no examples), and I made things up to suit myself—and I created a stringent, self-documenting naming convention. I started with an Object Oriented approach suitable for change (yes, OO in Bash). This is described below.

Everything is designed with a minimalist's perspective—everything is minimal in size and scale: variable names, file names, file length, function length... everything.

Continue reading →

About the Data

Posted on Dec 16, 2013 7:12PM

Document Database

The code does not use an SQL database (although it can I am not sure I want it to), so it is fairly heavy on the file system (as is an SQL database). Every post and comment is stored as a separate file, and some meta data too are stored in files, but every Operating System is optimized for reading and writing files.

Changes will occur in the data format so I am hesitant to document it. Taken as a whole the data is a combination hierarchical, relational, document-oriented database. But the API is designed for change. The goofy "Object Oriented like" library interface I described? I will just replace one library with a new one that adheres to it when making changes, or simply add another library to extend operation (although there are a limited amount of letters).

Currently, posts are stored in meta/psts/ as numbered files; other directories are for pages, post comments, and post meta data for categories and tags. FTP or cPanel can be used for basic site administration.

Record Format

Both posts and comments are stored in a standard format: newline delimited headers followed by a newline, followed by the data. Such a format has two very good features. Easy to parse, amenable to additions. (This is as near to non-encoded as data can be.) Example:

Title
Date

<p>Post text.</p>

Continue reading →

Web Templates

Posted on Jan 6, 2014 11:12AM

A Web Template Non-Engine

I have seen it written that templates cannot be implemented in Bash. Well, "The impossible takes a little longer," someone once said. But it actually did not take me all that long to create a true web template API of about 100 lines.

First, there exists global site data such as this:

bash code

sitebase=${SCRIPT_NAME%/*}

sitehost="http://$HTTP_HOST$REQUEST_URI"

sitedesc="Syntagmatic Personal Publishing Platform"

sitename="WordBash"

sitetitle="The first WordBash site"

A basic template, which comes from a file, is like this:

text='<!DOCTYPE html>
<title>$sitetitle</title>
<link rel="stylesheet" type="text/css" href="$sitebase/style.css">
<header>
<h1><a href="$sitehost" title="$sitetitle">$sitename</a></h1>
<h2>$sitetitle</h2>
</header>'

Just what is a this for anyway?

It is to display the HTML with the variable references replaced by the actual data during run-time. Doing so takes what is known as an "engine". Why? It generally takes a lot of code to do it. A lot of code.

It can be done in Bash like this:

Continue reading →

WordBash Interactive

Posted on Jan 28, 2014 21:53PM

An Interactive Session

This demonstrates using WordBash interactively.

bash -i

/var/www/htdocs/wordbash

$ bash -i

bash-4.1$ . ./B.sh

bash-4.1$ P n

bash-4.1$ echo $Pn

5

bash-4.1$ P l

bash-4.1$ echo ${Pl[@]}

1 2 3 4 5

bash-4.1$ P r 1

bash-4.1$ echo ${Dh[@]}

Introduction to WordBash Oct 18, 2013 14:35PM WordBash WordBash bash

bash-4.1$ echo "$Dr"

Introduction to WordBash

Oct 18, 2013 14:35PM

WordBash

WordBash bash

 

<p>These posts will describe WordBash in detail, and make some claims about it.

...

bash-4.1$ P p 1

<article>

<h1><a href="?post=1" title="Introduction to WordBash">Introduction to WordBash</a></h1>

<time>Posted on <a>Oct 18, 2013 14:35PM</a></time>

<p>These posts will describe <cite>WordBash</cite> in detail, and make some claims about it.

...

bash-4.1$

0m0.090s 0m0.014s 0m0.007s 0m0.013s