Add page template.
This commit is contained in:
parent
1f6f11dfc2
commit
8fc8885cfd
53
README.md
53
README.md
|
@ -1,50 +1,59 @@
|
|||
# blg
|
||||
# blg - a minimal blogging tool.
|
||||
|
||||
A static blog generator written in a single fish script.
|
||||
Blg is a minimalist tool for creating static blogs written, and it lives in a single fish script.
|
||||
|
||||
# To install blg
|
||||
Blogs are seen sometimes as complex things, requiring large tech stacks and all sorts of fancy esoteric setup to make them work. The truth of the matter is that, at the heart of it, a blog is just a bunch of text files.
|
||||
|
||||
Copy the *blg.fish* file to *~/.config/fish/functions/*
|
||||
This little tool is to show that a blog does not need to be made up of complex databases and dynamically loading pages.
|
||||
|
||||
# To create a blog
|
||||
# Install
|
||||
|
||||
Set up the blog project like so:
|
||||
Clone this repo and ```cp blg.fish ~/.config/fish/functions/blg.fish``` or wherever the fish functions live on your install.
|
||||
|
||||
# Creating a new blog
|
||||
```
|
||||
mkdir blog
|
||||
cd blog
|
||||
mkdir content
|
||||
blg -i
|
||||
```
|
||||
|
||||
To make a new blog post run:
|
||||
This will create you a new blog, and your first post to go with it!
|
||||
|
||||
# Creating a new post
|
||||
|
||||
```
|
||||
blg -n
|
||||
```
|
||||
|
||||
And fill in the post title.
|
||||
This will create you a new post on your blog. It will tell you witch file to edit to fill it in, and will create a line in the blog map so that you can publish, and unpublish, it at build.
|
||||
|
||||
Your new post will be added to the *blogmap* file, which is created for you. To see a listing of all oyour posts just:
|
||||
# Building your blog
|
||||
|
||||
```
|
||||
cat blogmap
|
||||
blg
|
||||
```
|
||||
|
||||
## Edit the post
|
||||
Just run blg in the root of your blog and it will create the static output in the ```out/``` directory.
|
||||
|
||||
All of your posts are in the *content* directory. Just write your gemtext in the correct file. Each numbered file in the *content* directory can be referenced to a numbered entry in the *blogmap*
|
||||
# Publishing posts.
|
||||
|
||||
## Published and unpublished blog posts
|
||||
There is a file in the root of your blog called blogmap. Each line of this file is a single entry in your blog. Lines that begin with a "#" are un-published and will be skipped on build, all other lines will produce an output html file.
|
||||
|
||||
When you create a new blog post with *blg -n* an entry for that post is placed in the *blogmap file.
|
||||
Each post in your blog is on its own line in that file.
|
||||
# About markup in blog posts.
|
||||
|
||||
Lines beginning with "#" are not published on build, lines without are.
|
||||
This tool uses gemtext instead of markdown to format blog posts. If you do not know what gemtext is then look it up; it is fast to write and very simple. The only addon to getmtext that this projecct uses is the :: tag.
|
||||
|
||||
## Build your blog
|
||||
Lines that begin with :: define a content tag that the article is linked to.
|
||||
|
||||
```
|
||||
blg -b
|
||||
:: games
|
||||
:: writing
|
||||
```
|
||||
|
||||
The static files for your blog will be in the *out* directory.
|
||||
The two lines above tag an article as being in the games, and writing categories. All articles with similar tags are collected together into an html file that allows you to see all the other articles taged as such.
|
||||
|
||||
# The template.html file
|
||||
|
||||
The static output is created from a template.html. This file contains spectial tags that are then replaced during build to give you a nicely formatted blog at the end. Look at the one in this repo for an example.
|
||||
|
||||
# Should I use this?
|
||||
|
||||
Go ahead, although I make no claim to how stable or useful it is. I built this for fun, and if you find use for it then good, but it isn't intended for every day use.
|
||||
|
|
213
blg.fish
213
blg.fish
|
@ -1,19 +1,40 @@
|
|||
function blg
|
||||
|
||||
set -g blog_title "This is the blog title"
|
||||
set -g blog_index "out/index.html"
|
||||
set -g tag_files "out/index.html"
|
||||
set -g blog_index "tmp/index.gmi"
|
||||
|
||||
argparse 'n/new-post' 'b/build' -- $argv
|
||||
argparse 'n/new-post' 'i/init' -- $argv
|
||||
|
||||
if set -q _flag_n
|
||||
new_post
|
||||
return
|
||||
end
|
||||
|
||||
if set -q _flag_b
|
||||
build_blog
|
||||
if set -q _flag_i
|
||||
init_new_blog
|
||||
return
|
||||
end
|
||||
|
||||
build_blog
|
||||
|
||||
end
|
||||
|
||||
function init_new_blog
|
||||
|
||||
read -l -P "Name of new blog: " name
|
||||
set name (string replace -a ' ' _ $name)
|
||||
mkdir $name
|
||||
mkdir "$name/content"
|
||||
echo "blog created in $name/"
|
||||
|
||||
cd $name
|
||||
create_template
|
||||
|
||||
echo "Now let us create your first post!"
|
||||
|
||||
new_post
|
||||
|
||||
cd ..
|
||||
|
||||
end
|
||||
|
||||
|
@ -54,115 +75,64 @@ function build_blog
|
|||
rm -rf out
|
||||
end
|
||||
mkdir out
|
||||
|
||||
touch $blog_index
|
||||
index_top $blog_index
|
||||
|
||||
if test -d tmp
|
||||
rm -rf tmp
|
||||
end
|
||||
mkdir tmp
|
||||
|
||||
while read -l line
|
||||
switch $line
|
||||
case "#*"
|
||||
continue
|
||||
case "*"
|
||||
|
||||
set -l parts (string split "~" $line)
|
||||
set article_number (string trim $parts[1])
|
||||
set article_date $parts[2]
|
||||
set article_title $parts[3]
|
||||
set -l article_link "<a href=\"$article_number.html\">$article_date: $article_title</a><br>"
|
||||
set -l article_number (string trim $parts[1])
|
||||
set -l article_date $parts[2]
|
||||
set -l article_title $parts[3]
|
||||
|
||||
set -l content_file "content/$article_number.gmi" # The input
|
||||
set -l article_file "out/$article_number.html" # The output
|
||||
set -l article_link "<a href=\"$article_number.html\">$article_date: $article_title</a><br>" # Link to article
|
||||
|
||||
echo "publishing - $article_number $article_title"
|
||||
set content_file "content/$article_number.gmi"
|
||||
set article_file "out/$article_number.html"
|
||||
article_top $article_title $article_date $article_file
|
||||
parse $content_file $article_link >> $article_file
|
||||
article_bottom $article_file
|
||||
|
||||
|
||||
set -l article_body (parse $content_file $article_link)
|
||||
|
||||
set -l tag_tags "<h2>This article is tagged with the following subjects:</h2>"
|
||||
if set -q article_tag_links
|
||||
echo "<h2>This article is tagged with the following subjects:</h2>" >>$article_file
|
||||
for item in $article_tag_links;
|
||||
echo "$item<br>" >> $article_file
|
||||
set -a tag_tags "$item<br>"
|
||||
end
|
||||
set -e article_tag_links
|
||||
end
|
||||
|
||||
write_file "$article_title" "$article_title" "$tag_tags" "$article_file" "$article_body"
|
||||
|
||||
echo $article_link >> $blog_index
|
||||
end
|
||||
end < blogmap
|
||||
|
||||
for page in $tag_files;
|
||||
article_bottom $page
|
||||
end
|
||||
echo "Generating index."
|
||||
set -l idxbdy (cat $blog_index)
|
||||
write_file "Blog index" "Blog index" " " "out/index.html" "$idxbdy"
|
||||
|
||||
echo "Generating tags."
|
||||
write_tags
|
||||
|
||||
end
|
||||
|
||||
function index_top -a f
|
||||
echo "<!doctype html>" >> $f
|
||||
echo "<html>" >> $f
|
||||
echo "<head>" >> $f
|
||||
echo "<title>$blog_title</title>" >> $f
|
||||
echo "<meta name=\"description\" content=\"$blog_title\">" >> $f
|
||||
echo "<meta name=\"keywords\" content=\"blog\">" >> $f
|
||||
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" >> $f
|
||||
echo "<style>" >> $f
|
||||
echo "body {" >> $f
|
||||
echo " width: 600px;" >> $f
|
||||
echo " padding: 15px;" >> $f
|
||||
echo "}" >> $f
|
||||
echo "</style>" >> $f
|
||||
echo "</head>" >> $f
|
||||
echo "<body id=\"top\">" >> $f
|
||||
echo "<h1>Posts</h1>" >> $f
|
||||
echo "<hr>" >> $f
|
||||
end
|
||||
function write_file -a ti de ta of bd
|
||||
set -l temp (cat template.html)
|
||||
set temp (string replace -a ';;title' $ti $temp)
|
||||
set temp (string replace -a ';;description' $de $temp)
|
||||
set temp (string replace -a ';;body' $bd $temp)
|
||||
set temp (string replace -a ';;title' $ti $temp)
|
||||
set temp (string replace -a ';;tags' $ta $temp)
|
||||
|
||||
function tag_top -a tag f
|
||||
echo "<!doctype html>" >> $f
|
||||
echo "<html>" >> $f
|
||||
echo "<head>" >> $f
|
||||
echo "<title>$tag</title>" >> $f
|
||||
echo "<meta name=\"description\" content=\"$tag\">" >> $f
|
||||
echo "<meta name=\"keywords\" content=\"$tag\">" >> $f
|
||||
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" >> $f
|
||||
echo "<style>" >> $f
|
||||
echo "body {" >> $f
|
||||
echo " width: 600px;" >> $f
|
||||
echo " padding: 15px;" >> $f
|
||||
echo "}" >> $f
|
||||
echo "</style>" >> $f
|
||||
echo "</head>" >> $f
|
||||
echo "<body id=\"top\">" >> $f
|
||||
echo "<h1>Posts tagged with $tag</h1>" >> $f
|
||||
echo "<hr>" >> $f
|
||||
end
|
||||
|
||||
function index_bottom
|
||||
article_bottom $blog_index
|
||||
end
|
||||
|
||||
function article_top -a art_title art_date f
|
||||
echo "<!doctype html>" >> $f
|
||||
echo "<html>" >> $f
|
||||
echo "<head>" >> $f
|
||||
echo "<title>$art_title</title>" >> $f
|
||||
echo "<meta name=\"description\" content=\"$art_title\">" >> $f
|
||||
echo "<meta name=\"keywords\" content=\"blog\">" >> $f
|
||||
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" >> $f
|
||||
echo "<style>" >> $f
|
||||
echo "body {" >> $f
|
||||
echo " width: 600px;" >> $f
|
||||
echo " padding: 15px;" >> $f
|
||||
echo "}" >> $f
|
||||
echo "</style>" >> $f
|
||||
echo "</head>" >> $f
|
||||
echo "<body id=\"top\">" >> $f
|
||||
echo "<nav>" >> $f
|
||||
echo "<a href=\"index.html\">index</a>" >> $f
|
||||
echo "</nav>" >> $f
|
||||
echo "<h1>$art_title</h1>" >> $f
|
||||
echo "<em>$art_date</em>" >> $f
|
||||
echo "<hr>" >> $f
|
||||
end
|
||||
|
||||
function article_bottom -a f
|
||||
echo "<a href=\"#top\">[top]</a>" >> $f
|
||||
echo "</body>" >> $f
|
||||
echo "</html>" >> $f
|
||||
echo $temp >> $of
|
||||
end
|
||||
|
||||
function parse -a input article_link
|
||||
|
@ -174,7 +144,6 @@ function parse -a input article_link
|
|||
while read -Lla line
|
||||
switch $line
|
||||
case "::*" # Put a link in the tag file
|
||||
echo "This is the place"
|
||||
do_tag $line $article_link
|
||||
|
||||
case "#*" # Print a header
|
||||
|
@ -251,13 +220,57 @@ function do_tag -a line article_link
|
|||
set tag (string sub -s 3 $line)
|
||||
set tag (string trim $tag)
|
||||
set sf_tag (string replace -a ' ' _ $tag)
|
||||
set -l tf "out/$sf_tag.html"
|
||||
set -l tf "out/$sf_tag.html"
|
||||
set -l inf "tmp/$sf_tag.gmi"
|
||||
set -a -g article_tag_links "<a href=\"$sf_tag.html\">$tag</a>"
|
||||
|
||||
if ! test -e $tf
|
||||
set tag_files -a $tf
|
||||
tag_top $tag $tf
|
||||
|
||||
if ! test -e $inf
|
||||
echo "$tag :: $inf :: $tf" >> tmp/tagindex
|
||||
end
|
||||
|
||||
echo $article_link >> $tf
|
||||
echo $article_link >> $inf
|
||||
end
|
||||
|
||||
function write_tags
|
||||
|
||||
while read -l line
|
||||
|
||||
set -l parts (string split "::" $line)
|
||||
set title (string trim $parts[1])
|
||||
set inf (string trim $parts[2])
|
||||
set out (string trim $parts[3])
|
||||
set body (cat $inf)
|
||||
write_file "$title" "$title" " " "$out" "$body"
|
||||
|
||||
end < tmp/tagindex
|
||||
|
||||
end
|
||||
|
||||
function create_template
|
||||
|
||||
set template "template.html"
|
||||
|
||||
touch $template
|
||||
|
||||
echo "<!doctype htmml>" >> $template
|
||||
echo "<html>" >> $template
|
||||
echo "<head>" >> $template
|
||||
echo "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" >> $template
|
||||
echo "<title>;;title</title>" >> $template
|
||||
echo "<meta name=\"description\" content=\";;description\">" >> $template
|
||||
echo "</head>" >> $template
|
||||
echo "<body id=\"top\">" >> $template
|
||||
echo " <nav>" >> $template
|
||||
echo " <a href=\"index.html\">index</a>" >> $template
|
||||
echo " </nav>" >> $template
|
||||
echo " <hr>" >> $template
|
||||
echo " <main>" >> $template
|
||||
echo " <h1>;;title</h1>" >> $template
|
||||
echo " ;;body" >> $template
|
||||
echo " </main>" >> $template
|
||||
echo " <p>;;tags</p>" >> $template
|
||||
echo " <p><a href=\"#top\">[top]</a></p>" >> $template
|
||||
echo "</body>" >> $template
|
||||
echo "</html>" >> $template
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<!doctype htmml>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"
|
||||
;;title
|
||||
;;description
|
||||
</head>
|
||||
|
||||
|
||||
<body id="top">
|
||||
|
||||
<nav>
|
||||
<a href="index.html">index</a>
|
||||
</nav>
|
||||
<hr>
|
||||
|
||||
<main>
|
||||
|
||||
<h1>;;title</h1>
|
||||
|
||||
;;body
|
||||
|
||||
</main>
|
||||
|
||||
<p>
|
||||
;;tags
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="#top">[top]</a>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue