working out zod phases

This commit is contained in:
nuex 2011-10-18 01:07:12 -04:00
parent 7448411442
commit f7affcaca7
6 changed files with 124 additions and 74 deletions

114
README.md
View File

@ -1,20 +1,31 @@
# zodiac
# zodiac - a static site generator
ZODIAC is a static website generator powered by sh and awk. The core features of zodiac are:
* utliization of existing tools (i.e. awk, sh, find, etc.)
* built-in support for markdown
* a simple, easy to use templating system
* supports custom helpers written in awk
* multiple layouts
* partials
* configuration, meta, helpers, etc. can be added as you need them
* support any markup format via external tools
## SYNOPSIS
ZODIAC is a static website generator powered by sh and awk.
zod projectdir targetdir
## INSTALL
git clone git://github.com/nuex/zodiac.git
Edit the config.mk file to customize the install paths
Edit the config.mk file to customize the install paths. `/usr/local` is the default install prefix.
sudo make install
Run the following (as root if necessary):
## USAGE
make install
zod projectdir targetdir
## DESCRIPTION
A typical Zodiac project will look something like this:
@ -33,6 +44,17 @@ A typical Zodiac project will look something like this:
stylesheets/
style.css
And it's output could look like this:
site/
index.html
projects/
project-1.html
project-2.html
cv.html
stylesheets/
style.css
### Meta
`.meta` files contain a key / value pair per line. A key and its value must be separated by a ": ". A metafile looks like this:
@ -90,25 +112,83 @@ The `helpers.awk` file is an awk script that can make custom data available to y
# your custom functions
function page_title( title) {
if (data["title"]) {
title = data["title"] " - "
if ("title" in data) {
return data["title"] "-" data["site_title"]
} else {
return data["site_title"]
}
title = title data["site_title"]
return title
}
Just be sure to set the data array in the load_helpers() function at the top of the script to make your custom data available to the template.
Just be sure to set the data array in the `load_helpers()` function at the top of the script to make your custom data available to the template.
## FUTURE
### Config
- multiple filters support
- multiple layout support
- mustache support
- partials/snippets
For more control over the parsing and conversion process, a `.zod/config` file can be created within your project directory. Here is a sample config:
[parse]
htm
html
[parse_convert]
md smu
txt asciidoc -s -
[convert]
coffee coffee -s > {}.js
[ignore]
Makefile
Here we're only parsing (not converting to a different format) files matching `*.htm` and `*.html`.
Files matching `*.md` are going to be parsed and converted using the `smu` markdown parsing program.
Files matching `*.txt` are going to be parsed and converted using `asciidoc`.
Files matching `*.coffee` are going to be converted to JavaScript before being copied into the target directory. The `{}` notation will be expanded to the path and filename of the coffeescript file, but without the `.coffee` extension.
Files matching `Makefile` will be ignored and not copied.
Conversion programs must accept a UNIX-style pipe and send converted data to stdout.
### Per-page Templates and Partials
Multiple templates and partials are also supported.
For example; a `blog.md` page:
title: my blog
layout: blog
A `sidebar.partial`:
<div id="sidebar">
<ul>
<li><a href="/blog/some-article.html">Some Article</a></li>
<li><a href="/blog/another-one.html">Another One</a></li>
</ul>
</div>
And `blog.layout`:
<!DOCTYPE html>
<html>
<head>
<title>Blog Page</title>
</head>
<body>
<div id="main">
{{{yield}}}
</div>
{{>sidebar}}
</body>
</html>
`{{>sidebar}}` will be replaced with the parsed contents of `sidebar.partial`.
## CREDITS
zsw: for the introduction to parameter expansion and other shell scripting techniques
* zsw: for the introduction to parameter expansion and other shell scripting techniques
## LICENSE

View File

@ -1,59 +1,32 @@
#!/bin/sh
# render a zodiac page
# zod_render zodlibdir projdir targetdir md_builtin [files]
zod_lib="$1"
proj="$2"
target="$3"
f="$4"
md_builtin="$4"
f="$5"
md_builtin="awk -f $zod_lib/markdown.awk"
[ -f "$proj/helpers.awk" ] && helper_opts="$proj/helpers.awk"
[ -f "$proj/filters.config" ] && filter_opts="$proj/filters.config"
[ -f "$proj/global.meta" ] && global_meta_opts="$proj/global.meta"
[ -f "$proj/main.layout" ] && layout_opts="$proj/main.layout"
# Find the target directory if one must be created
subdir=${f%/*}
subdir=${subdir#$proj}
if [ "$subdir" ]; then
destination="$target$subdir"
mkdir -p "$destination"
else
# There is no directory to create in target,
# i.e. file is in the root of the project
destination="$target"
fi
# source zod sh functions
. $zod_lib/zod_functions
ext=${f##*.}
meta=${f%.$ext}.meta
# Add filter support provided by the filters.config file
[ "$filter_opts" ] && supported="$supported $(zod_supported_extensions "$zod_lib" "$filter_opts")"
set -- -f "$zod_lib/render.awk"
[ -f "$proj/helpers.awk" ] && set -- "$@" -f "$proj/helpers.awk"
set -- "$@" -v markdown_filter_cmd="$md_builtin"
[ -f "$proj/global.meta" ] && set -- "$@" $proj/global.meta
[ -f "$meta" ] && set -- "$@" $meta
set -- "$@" "$f"
for supported_ext in "$supported"; do
[ $ext == "$supported_ext" ] && { is_supported=true; break }
find "$proj" -type f -name "*.partial" -o -name "*.layout"
while read -r part; do
set -- "$@" "$part"
done
if [ "$is_supported" ]; then
meta=${f%.$ext}.meta
[ -f "$meta" ] && page_meta_opts="$meta"
set -- -f "$zod_lib/render.awk"
[ "$helper_opts" ] && set -- "$@" -f "$helper_opts"
set -- "$@" -v markdown_filter_cmd="$md_builtin" \
"$filter_opts" \
"$global_meta_opts" \
"$page_meta_opts" \
"$f" \
"$layout_opts"
page=${f##*/}
page=${page%.$ext}.html
awk "$@" > "$destination/$page"
else
cp "$f" "$destination" # Copying a non-template file
fi
page=${f##*/}
page=${page%.$ext}.html
__zod_destination "$proj" "$target" "$f"
awk "$@" > "$destination/$page"

0
bin/zod_supported_extensions Normal file → Executable file
View File

View File

@ -1,2 +1,3 @@
PREFIX = /usr/local
AWKLIB = ${PREFIX}/lib/zodiac
#AWKLIB = ${PREFIX}/lib/zodiac
AWKLIB = /home/nuex/_dev/zodiac/lib

View File

@ -5,9 +5,9 @@ function load_helpers() {
}
function page_title( title) {
if (data["title"]) {
title = data["title"] " - "
if ("title" in data) {
return data["title"] " - " data["site_title"]
} else {
return data["site_title"]
}
title = title data["site_title"]
return title
}

View File

@ -6,14 +6,10 @@
<title>{{page_title}}</title>
</head>
<body>
<header>
<h1><a href="/">{{site_title}}</a></h1>
</header>
{{>header}}
<article>
{{{yield}}}
</article>
<footer>
<p>powered by static files</p>
</footer>
{{>footer}}
</body>
</html>