Skip to content
Browse files

initial

  • Loading branch information...
0 parents commit 5bec8d1abec5d8f679859483b19b6bc4cffae7de @nuex committed Sep 22, 2011
8 LICENSE
@@ -0,0 +1,8 @@
+The MIT License (MIT)
+Copyright (c) 2011 Chase Allen James <zodiac-nx@nu-ex.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 Makefile
@@ -0,0 +1,12 @@
+include config.mk
+
+install:
+ @echo Installing zod executable to ${PREFIX}/bin
+ @mkdir -p ${PREFIX}/bin
+ @sed "s#ZODLIB_PATH#${AWKLIB}#g" < bin/zod.template > ${PREFIX}/bin/zod
+ @chmod 755 ${PREFIX}/bin/zod
+ @echo Installing awk lib files to ${AWKLIB}
+ @mkdir -p ${AWKLIB}
+ @cp lib/render.awk ${AWKLIB}/
+ @cp lib/markdown.awk ${AWKLIB}/
+ @echo Installation Complete
98 README
@@ -0,0 +1,98 @@
+# zodiac
+
+## SYNOPSIS
+
+ZODIAC is a static website generator powered by sh and awk.
+
+## INSTALL
+
+ git clone ssh://github.com/nuex/zodiac.git
+
+Edit the config.mk file to customize the install paths
+
+ sudo make install
+
+## USAGE
+
+ zod projectdir targetdir
+
+A typical Zodiac project will look something like this:
+
+ site/
+ index.md
+ index.meta
+ main.layout
+ global.meta
+ projects/
+ project-1.md
+ project-1.meta
+ project-2.md
+ project-2.meta
+ cv.md
+ cv.meta
+ 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:
+
+ this: that
+ title: Contact
+ author: Me
+
+Each markdown page can have its own meta file. The only requirement is that the meta file is in the same directory as the page, has the same name as the page and has the `.meta` file extension.
+
+The optional `global.meta` file contains data that is available to all of your site's pages, like a site_title.
+
+Page metadata will always override global metadata of the same key.
+
+### Layouts
+
+A `main.layout` file should look something like this:
+
+ <!DOCTYPE html>
+ <html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="stylesheet" href="/stylesheets/style.css" />
+ <title>{{page_title}}</title>
+ </head>
+ <body>
+ <header>
+ <h1><a href="/">{{site_title}}</a></h1>
+ </header>
+ <article>
+ {{{yield}}}
+ </article>
+ <footer>
+ <p>powered by static files, compiled by <a href="http://nu-ex.com/projects/zodiac">zodiac</a>.</p>
+ </footer>
+ </body>
+ </html>
+
+### Helpers
+
+The `helpers.awk` file is an awk script that can make custom data available to your templates. You also have access to the page and global data. Here is a peak at the script included in the examples folder:
+
+ { helpers = "yes" }
+
+ function load_helpers() {
+ # your custom data settings
+ data["page_title"] = page_title()
+ }
+
+ # your custom functions
+ function page_title( title) {
+ if (data["title"]) {
+ title = data["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.
+
+### License
+
+MIT
86 bin/zod
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# ZODIAC - a simple static site generator
+# Copyright (c) 2011 Chase Allen James <zodiac-nx@nu-ex.com>
+
+ZODLIB="$( cd "$( dirname "$0" )" && pwd )/../lib"
+
+proj=$1
+target=$2
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "usage: zod projectdir targetdir"
+ exit
+fi
+
+if [ ! -e $proj ]; then
+ echo "error: project directory does not exist"
+ exit
+fi
+
+if [ ! -e $target ]; then
+ echo "error: target directory does not exist"
+ exit
+fi
+
+layout=$proj/main.layout
+global_meta=$proj/global.meta
+
+for f in $(find $proj/*); do
+ dir=$(dirname $f)
+
+ # Find the target directory if one must be created
+ # Start by pulling the project directory out of the filepath
+ # with awk and then removing the filename with sed
+ targetdir=$(awk "BEGIN { split(\"$f\",a,\"$proj/\"); print a[2] }" | sed "s/`basename $f`//")
+ targetpath=$target/$targetdir
+ if [ ! -z "$targetdir" ]; then
+ mkdir -p $target/$targetdir
+ else
+ # There is no directory to create in target,
+ # i.e. file is in the root of the project
+ targetpath=$target
+ fi
+
+ filename=$(basename $f)
+ if [ "$(echo $filename | sed 's/\.md//;s/\.meta//;s/\.layout//')" == $filename ] &&
+ [ $filename != "helpers.awk" ]; then
+
+ # we're just moving a file over
+ if [ ! -d $f ]; then
+ cp $f $targetpath/
+ fi
+
+ elif [ "$(echo $filename | sed 's/\.md//')" != $filename ]; then
+
+ page=$(basename $f | sed 's/\.md//')
+
+ ops=""
+
+ if [ -e $proj/helpers.awk ]; then
+ ops="$ops -f `pwd`/$proj/helpers.awk"
+ fi
+
+ ops="$ops -f $ZODLIB/render.awk"
+ ops="$ops -v AWKLIB=\"$ZODLIB\""
+
+ if [ -e $global_meta ]; then
+ ops="$ops $global_meta"
+ fi
+
+ if [ -e $dir/$page.meta ]; then
+ ops="$ops $dir/$page.meta"
+ fi
+
+ ops="$ops $dir/$page.md"
+
+ if [ -e $layout ]; then
+ ops="$ops $layout"
+ fi
+
+ awk $ops > $targetpath/$page.html
+
+ fi
+
+
+done
86 bin/zod.template
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+# ZODIAC - a simple static site generator
+# Copyright (c) 2011 Chase Allen James <zodiac-nx@nu-ex.com>
+
+ZODLIB=ZODLIB_PATH
+
+proj=$1
+target=$2
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "usage: zod projectdir targetdir"
+ exit
+fi
+
+if [ ! -e $proj ]; then
+ echo "error: project directory does not exist"
+ exit
+fi
+
+if [ ! -e $target ]; then
+ echo "error: target directory does not exist"
+ exit
+fi
+
+layout=$proj/main.layout
+global_meta=$proj/global.meta
+
+for f in $(find $proj/*); do
+ dir=$(dirname $f)
+
+ # Find the target directory if one must be created
+ # Start by pulling the project directory out of the filepath
+ # with awk and then removing the filename with sed
+ targetdir=$(awk "BEGIN { split(\"$f\",a,\"$proj/\"); print a[2] }" | sed "s/`basename $f`//")
+ targetpath=$target/$targetdir
+ if [ ! -z "$targetdir" ]; then
+ mkdir -p $target/$targetdir
+ else
+ # There is no directory to create in target,
+ # i.e. file is in the root of the project
+ targetpath=$target
+ fi
+
+ filename=$(basename $f)
+ if [ "$(echo $filename | sed 's/\.md//;s/\.meta//;s/\.layout//')" == $filename ] &&
+ [ $filename != "helpers.awk" ]; then
+
+ # we're just moving a file over
+ if [ ! -d $f ]; then
+ cp $f $targetpath/
+ fi
+
+ elif [ "$(echo $filename | sed 's/\.md//')" != $filename ]; then
+
+ page=$(basename $f | sed 's/\.md//')
+
+ ops=""
+
+ if [ -e $proj/helpers.awk ]; then
+ ops="$ops -f `pwd`/$proj/helpers.awk"
+ fi
+
+ ops="$ops -f $ZODLIB/render.awk"
+ ops="$ops -v AWKLIB=\"$ZODLIB\""
+
+ if [ -e $global_meta ]; then
+ ops="$ops $global_meta"
+ fi
+
+ if [ -e $dir/$page.meta ]; then
+ ops="$ops $dir/$page.meta"
+ fi
+
+ ops="$ops $dir/$page.md"
+
+ if [ -e $layout ]; then
+ ops="$ops $layout"
+ fi
+
+ awk $ops > $targetpath/$page.html
+
+ fi
+
+
+done
2 config.mk
@@ -0,0 +1,2 @@
+PREFIX = /usr/local
+AWKLIB = ${PREFIX}/lib/zodiac
2 example/Makefile
@@ -0,0 +1,2 @@
+all:
+ zod site www
5 example/site/blog.md
@@ -0,0 +1,5 @@
+# Blog
+
+These are my blog posts
+
+* 2011-04-02 [Hello](/blog/hello.html)
1 example/site/blog.meta
@@ -0,0 +1 @@
+title: Blog
3 example/site/blog/hello.md
@@ -0,0 +1,3 @@
+# Hi
+
+This is my first blog post
1 example/site/blog/hello.meta
@@ -0,0 +1 @@
+title: hello
1 example/site/global.meta
@@ -0,0 +1 @@
+site_title: my site
13 example/site/helpers.awk
@@ -0,0 +1,13 @@
+{ helpers = "yes" }
+
+function load_helpers() {
+ data["page_title"] = page_title()
+}
+
+function page_title( title) {
+ if (data["title"]) {
+ title = data["title"] " - "
+ }
+ title = title data["site_title"]
+ return title
+}
5 example/site/index.md
@@ -0,0 +1,5 @@
+## Introduction
+
+Welcome to my website
+
+Check out [my blog](/blog.html)
1 example/site/index.meta
@@ -0,0 +1 @@
+title: home
19 example/site/main.layout
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="stylesheet" href="/stylesheets/style.css" />
+ <title>{{page_title}}</title>
+ </head>
+ <body>
+ <header>
+ <h1><a href="/">{{site_title}}</a></h1>
+ </header>
+ <article>
+ {{{yield}}}
+ </article>
+ <footer>
+ <p>powered by static files</p>
+ </footer>
+ </body>
+</html>
4 example/site/style.css
@@ -0,0 +1,4 @@
+body {
+ background-color: #fff;
+ color: #000;
+}
0 example/www/.keep
No changes.
228 lib/markdown.awk
@@ -0,0 +1,228 @@
+#.H1 Markdown.awk
+
+#.H2 Synopsis
+#.P awk -f markdown.awk file.txt > file.html
+#.H2 Download
+#.P
+#Download from
+#.URL http://lawker.googlecode.com/svn/fridge/gawk/text/markdown.awk LAWKER.
+#.H2 Description
+#.P
+# (Note: this code was orginally called <em>txt2html.awk</em> by its author but that caused a name
+# clash inside LAWKER. Hence, I've taken the liberty of renamining it. --<a href="?who/timm">Timm</a>)
+#.P The following code implements a subset of John Gruber's <a href="http://daringfireball.net/projects/markdown/">Markdown</a> langauge: a widely-used, ultra light-weight markup language for html.
+
+#.UL
+#.LI Paragraghs- denoted by a leading blank line.
+#.LI
+#Links: <pre>An [example](http://url.com/ "Title") </pre>
+#.LI
+#Images: <pre>![alt text](/path/img.jpg "Title")</pre>
+#.LI
+#Emphasis: **To be in italics**
+#.LI
+#Code: `&lt;code&gt;` spans are delimited by backticks.
+#.LI
+#Headings (Setex style)
+#.PRE
+#Level 1 Header
+#===============
+#
+#Level 2 Header
+#--------------
+#
+#Level 3 Header
+#______________
+#./PRE
+#.LI
+#Heaings (Atx style):
+#.P Number of leading "#" codes the heading level:
+#.PRE
+## Level 1 Header
+##### Level 4 Header
+#./PRE
+#.LI Unordered lists
+#.PRE
+#- List item 1
+#- List item 2
+#./PRE
+#.P Note: beginnging and end of list are automatically inferred, maybe not always correctly.
+#.LI Ordered lists
+#.P Denoted by a number at start-of-line.
+#.PRE
+#1 A numbered list item
+#./PRE
+#./UL
+#.H2 Code
+#.P
+# The following code demonstrates a "exception-style" of Awk programming. Note
+#how all the processing relating to each mark-up tag is localized (exception, carrying
+#round prior text and environments). The modularity of the following code should make it
+#easily hackable.
+#.H3 Globals
+#.PRE
+BEGIN {
+ env = "none";
+ text = "";
+}
+#./PRE
+#.H3 Images
+#.PRE
+/^!\[.+\] *\(.+\)/ {
+ split($0, a, /\] *\(/);
+ split(a[1], b, /\[/);
+ imgtext = b[2];
+ split(a[2], b, /\)/);
+ imgaddr = b[1];
+ print "<p><img src=\"" imgaddr "\" alt=\"" imgtext "\" title=\"\" /></p>\n";
+ text = "";
+ next;
+}
+#./PRE
+#.H3 Links
+#.PRE
+/\] *\(/ {
+ do {
+ na = split($0, a, /\] *\(/);
+ split(a[1], b, "[");
+ linktext = b[2];
+ nc = split(a[2], c, ")");
+ linkaddr = c[1];
+ text = text b[1] "<a href=\"" linkaddr "\">" linktext "</a>" c[2];
+ for(i = 3; i <= nc; i++)
+ text = text ")" c[i];
+ for(i = 3; i <= na; i++)
+ text = text "](" a[i];
+ $0 = text;;
+ text = "";
+ }
+ while (na > 2);
+}
+#./PRE
+#.H3 Code
+#.PRE
+/`/ {
+ while (match($0, /`/) != 0) {
+ if (env == "code") {
+ sub(/`/, "</code>");
+ env = pcenv;
+ }
+ else {
+ sub(/`/, "<code>");
+ pcenv = env;
+ env = "code";
+ }
+ }
+}
+#./PRE
+#.H3 Emphasis
+#.PRE
+/\*\*/ {
+ while (match($0, /\*\*/) != 0) {
+ if (env == "emph") {
+ sub(//, "</emph>");
+ env = peenv;
+ }
+ else {
+ sub(/\*\*/, "<emph>");
+ peenv = env;
+ env = "emph";
+ }
+ }
+}
+#./PRE
+#.H3 Setex-style Headers
+#.P (Plus h3 with underscores.)
+#.PRE
+/^=+$/ {
+ print "<h1>" text "</h1>\n";
+ text = "";
+ next;
+}
+
+/^-+$/ {
+ print "<h2>" text "</h2>\n";
+ text = "";
+ next;
+}
+
+/^_+$/ {
+ print "<h3>" text "</h3>\n";
+ text = "";
+ next;
+}
+#./PRE
+#.H3 Atx-style headers
+#.PRE
+/^#/ {
+ match($0, /#+/);
+ n = RLENGTH;
+ if(n > 6)
+ n = 6;
+ print "<h" n ">" substr($0, RLENGTH + 1) "</h" n ">\n";
+ next;
+}
+#./PRE
+#.H3 Unordered Lists
+#.PRE
+/^[*-+]/ {
+ if (env == "none") {
+ env = "ul";
+ print "<ul>";
+ }
+ print "<li>" substr($0, 3) "</li>";
+ text = "";
+ next;
+}
+
+/^[0-9]./ {
+ if (env == "none") {
+ env = "ol";
+ print "<ol>";
+ }
+ print "<li>" substr($0, 3) "</li>";
+ next;
+}
+#./PRE
+#.H3 Paragraphs
+#.PRE
+/^[ t]*$/ {
+ if (env != "none") {
+ if (text)
+ print text;
+ text = "";
+ print "</" env ">\n";
+ env = "none";
+ }
+ if (text)
+ print "<p>" text "</p>\n";
+ text = "";
+ next;
+}
+#./PRE
+#.H3 Default
+#.PRE
+// {
+ text = text $0;
+}
+#./PRE
+#.H3 End
+#.PRE
+END {
+ if (env != "none") {
+ if (text)
+ print text;
+ text = "";
+ print "</" env ">\n";
+ env = "none";
+ }
+ if (text)
+ print "<p>" text "</p>\n";
+ text = "";
+}
+#./PRE
+#.H2 Bugs
+#.P Does not implement the full Markdown syntax.
+#.H2 Author
+#.P Jesus Galan (yiyus) 2006
+# &lt;yiyu DOT jgl AT gmail DOT com>
104 lib/render.awk
@@ -0,0 +1,104 @@
+# render.awk - Awk-based templating
+
+BEGIN {
+ action = "none"
+ helpers_loaded = "no"
+ content = ""
+ layout = ""
+}
+
+{
+ action = action_from_filetype(FILENAME)
+}
+
+# Process lines from meta files
+action == "meta" {
+ split($0, kv, ": ")
+ data[kv[1]] = kv[2]
+ next
+}
+
+# Done processing meta
+# Since data is loaded now, load the helpers
+action != "meta" && helpers_loaded == "no" && helpers == "yes" {
+ load_helpers()
+ helpers_loaded = "yes"
+}
+
+# Process lines from the page
+action == "page" {
+ if (content == "") {
+ content = bind_data($0)
+ } else {
+ content = content "\n" bind_data($0)
+ }
+ next
+}
+
+# Process lines from the layout
+action == "layout" {
+
+ # replace yield with rendered content
+ if (match($0, /{{{yield}}}/)) {
+ sub(/{{{yield}}}/, render_content(content))
+ }
+
+ if (layout == "") {
+ layout = bind_data($0)
+ } else {
+ layout = layout "\n" bind_data($0)
+ }
+}
+
+END {
+ if (layout != "") {
+ print layout
+ } else {
+ print render_content(content)
+ }
+}
+
+function action_from_filetype(filename) {
+ if (match(filename, /\.meta/)) return "meta"
+ if (match(filename, /\.layout/)) return "layout"
+ if (match(filename, /\.md/)) return "page"
+}
+
+function bind_data(txt, tag, key) {
+ if (match(txt, /{{([^}]*)}}/)) {
+ tag = substr(txt, RSTART, RLENGTH)
+ match(tag, /(\w|[?]).*[^}]/)
+ key = substr(tag, RSTART, RLENGTH)
+ gsub(tag, data[key], txt)
+ return bind_data(txt, data)
+ } else {
+ return txt
+ }
+}
+
+function render_content(txt) {
+ return markdown(txt)
+}
+
+function markdown(txt, rand_date, tmpfile, rendered_txt, date_cmd, markdown_cmd, line) {
+ date_cmd = "date +%Y%m%d%H%M%S"
+ date_cmd | getline rand_date
+ close(date_cmd)
+
+ tmpfile = "/tmp/render" rand_date
+ markdown_cmd = "awk -f " AWKLIB "/markdown.awk > " tmpfile
+
+ # pipe content to markdown.awk
+ print txt | markdown_cmd
+ close(markdown_cmd)
+
+ # pull out the filtered page
+ while((getline line < tmpfile) > 0) {
+ rendered_txt = rendered_txt "\n" line
+ }
+ close(tmpfile)
+
+ system("rm " tmpfile)
+
+ return rendered_txt
+}

0 comments on commit 5bec8d1

Please sign in to comment.
Something went wrong with that request. Please try again.