just pushing the old code.

This commit is contained in:
Bradford Morgan White
2026-02-08 12:41:50 -05:00
parent 561d2a4d2a
commit 66405db6f1
10 changed files with 216 additions and 1 deletions
+9
View File
File diff suppressed because one or more lines are too long
+23
View File
@@ -0,0 +1,23 @@
SHELL := /bin/bash
PREFIX?=/var/www
PUB=$(PREFIX)/public
install:
@echo "Installing Bash Blog"
mkdir -p $(PUB)/posts
install -m 750 ./var/www/public/posts.cgi $(PUB)
install -m 750 ./var/www/public/index.cgi $(PUB)
install -m 640 ./var/www/public/style.css $(PUB)
install -m 640 ./var/www/public/config $(PUB)
install -m 640 ./var/www/public/footer.include $(PUB)
install -m 640 ./var/www/public/header.include $(PUB)
uninstall:
@echo "Removing Bash Blog"
rm -fv $(PUB)/{posts.cgi,index.cgi,style.css,config,footer.include,header.include}
rmdir -v $(PUB)/posts
reinstall:
@echo "Running reinstall"
make uninstall && make install
+30 -1
View File
@@ -1,2 +1,31 @@
# BashBlog # Bash Blog Thing
## Blog Engine in Bash, Why Not?
### SUMMARY
The idea here is that you can just upload a markdown file to the `public/posts` directory, and every thing else is automatic. The main rules are that the post has to be named `YYYY-MM-DD_Title-of-the-post.md` and the first line in the markdown file needs to be a heading with the title.
### INSTALLATION
As root, just type `make install` within this archive. There is one configurable option within the make file, and that is the installation prefix. It will default to `/var/www`. There is a `make uninstall` as well if you decide you hate it, and there is a `make reinstall` if you modify something and make the script worse.
I use John Gruber's `markdown` which is written in Perl, and can be installed on Debian/Ubuntu via `apt install markdown`. You can use any markdown parser you want if it accepts string input and outputs strings to stdout. If yours isn't named "markdown" but fits that description, just symlink it into place like `ln -s /usr/bin/whatever /usr/local/bin/markdown`.
### USAGE
You need to enable CGI in your web server. I use nginx with fcgi wrap. The document root needs to be the `public` directory made during install, unless you intend to use a subdirectory.
### STUFF FOR THE FUTURE
* Comments
* Tags and tag navigation
* Search
* RSS
---
### LICENSE
This software is licensed under terms of the [Absurd License](https://absurd.wtf/licentiam_absurdum.html).
+9
View File
@@ -0,0 +1,9 @@
########################################
# CONFIGURATION FILE FOR THE BASH BLOG #
########################################
BLOGNAME="The Bash Blog"
URL="example.com"
POSTSPERPAGE="8"
BLOGDESCRIPTION="This is a blog in Bash CGI."
BLOGKEYWORDS="bash, cgi, blog"
BLOGAUTHOR="a guy in a room, being"
+2
View File
@@ -0,0 +1,2 @@
echo "<p class=\"center\">&copy; MMXXII, ${URL}</p>"
echo "</body></html>";
+11
View File
@@ -0,0 +1,11 @@
echo "<!DOCTYPE html>";
echo "<html><head>";
[ -v TITLE ] && echo "<title>${BLOGNAME}: ${TITLE}</title>" || echo "<title>${BLOGNAME}</title>"
echo "<meta charset=\"utf-8\" />";
echo "<meta name=\"description\" content=\"${BLOGDESCRIPTION}\" />";
echo "<meta name=\"keywords\" content=\"${BLOGKEYWORDS}\" />";
echo "<meta name=\"author\" content=\"${BLOGAUTHOR}\" />";
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />";
echo "</head><body>";
[ -v TITLE ] && echo "<h1>${BLOGNAME}: ${TITLE}</h1>" || echo "<h1>${BLOGNAME}</h1>"
+62
View File
@@ -0,0 +1,62 @@
#!/bin/bash
printf "Content-type: text/html\n\n"
saveIFS=$IFS
IFS='=&'
parm=($QUERY_STRING)
IFS=$saveIFS
declare -A ARGUMENTS
for ((i=0; i<${#parm[@]}; i+=2))
do
ARGUMENTS[${parm[i]}]=${parm[i+1]}
done
source config
source header.include
shopt -s nullglob
ARR=(posts/*)
TOTALPOSTS="${#ARR[@]}"
NUMPAGES=$(($TOTALPOSTS/$POSTSPERPAGE))
PAGE=${ARGUMENTS[page]}
if [[ ! $PAGE =~ ^[0-9]+$ ]]; then
PAGE=1
elif [[ $PAGE -lt 0 ]] || [[ $PAGE -gt $NUMPAGES ]]; then
PAGE=1
fi
MIN=0
MAX=$(( ${#ARR[@]} - 1 ))
while [[ $MIN -lt $MAX ]]; do
X="${ARR[$MIN]}"
ARR[$MIN]="${ARR[$MAX]}"
ARR[$MAX]="$X"
(( MIN++, MAX-- ))
done
if [[ $PAGE -gt 1 ]]; then
SUB=$(( $PAGE - 1 ))
TOSUB=$(($SUB*$POSTSPERPAGE))
ARR=( ${ARR[@]:$TOSUB} )
echo "<p>Page $PAGE of $NUMPAGES</p>"
fi
for (( I=0; I<$POSTSPERPAGE; I++)); do
POST=${ARR[$I]}
FILENAME=$(echo ${POST/^posts\///})
printf "<div class=\"post\"><p><a href=\"posts.cgi?post=$FILENAME&page=$PAGE\">$(egrep '^# ' $POST | cut -f2- -d' ')</a> &nbsp; &#8674; &nbsp; $(egrep -v "^#" $POST | egrep -v "^$" | head -n1 | cut -c1-255 | markdown) </div>";
done
printf "<br /><p class=\"center\">";
for (( NUM = 1; NUM <= $NUMPAGES; NUM++ )); do
if [ $NUM -lt $NUMPAGES ]; then
printf "<a href=\"index.cgi?page=$NUM\"><b>$NUM</b></a> | "
else
printf "<a href=\"index.cgi?page=$NUM\"><b>$NUM</b></a></p><br />"
fi
done
source footer.include
+26
View File
@@ -0,0 +1,26 @@
#!/bin/bash
printf "Content-type: text/html\n\n"
saveIFS=$IFS
IFS='=&'
parm=($QUERY_STRING)
IFS=$saveIFS
declare -A ARGUMENTS
for ((i=0; i<${#parm[@]}; i+=2))
do
ARGUMENTS[${parm[i]}]=${parm[i+1]}
done
POST="${ARGUMENTS[post]}"
PAGE="${ARGUMENTS[page]}"
TITLE=$(egrep '^# ' $POST | cut -f2- -d' ')
source config
source header.include
egrep -v "^# " $POST | egrep -v "^tags: "| markdown
echo " <p><a href=\"index.cgi?page=$PAGE\">&#8672; back</a></p>";
source footer.include
@@ -0,0 +1,6 @@
# TITLE
## 20210122
The text all goes down here and such!
+38
View File
@@ -0,0 +1,38 @@
html, body {
font-size: 1.2em;
}
h1, h2 {
font-family: monospace, monospace;
}
code {
color: #9cf;
background-color:#036;
overflow: auto;
}
code, pre {
font-family: monospace;
padding: 4px;
}
pre {
background-color:#036;
color:#9cf;
overflow: auto;
line-height:1.5;
}
.post {
border-bottom: 1px solid #ddd;
}
img {
max-width: 99vw;
display: block;
margin-left: auto;
margin-right: auto;
}
p.center { text-align: center; clear: both; width: 100%; }