Coder Social home page Coder Social logo

zodiac's Introduction

zodiac

ZODIAC is a static website generator powered by sh and awk. The core features of zodiac are:

  • utilization of existing tools (i.e. awk, sh, find, etc.)
  • supports using plain html
  • built-in support for markdown
  • a simple, easy to use templating system
  • supports custom helpers written in awk
  • configuration, meta, helpers, etc. can be added as you need them
  • convert your markup using any external command that accepts a UNIX-style pipe (smu, asciidoc, discount, rst2html, etc)

SYNOPSIS

zod projectdir targetdir

INSTALL

git clone git://github.com/nuex/zodiac.git

Edit the config.mk file to customize the install paths. /usr/local is the default install prefix.

Run the following (as root if necessary):

make install

DESCRIPTION

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

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:

this: that
title: Contact
author: Me

Each 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.

Templates

Templates come in two forms, page templates and layout templates. Metadata can be bound to templates by using the {{key}} notation in your pages and layout files.

Page templates can have any extension that zodiac can convert. Out of the box, page templates can have an md, htm, or html extension. Other extensions and markup types can be supported if they are configured in the .zod/config file in the project directory.

The main.layout file wraps HTML content around a page template. A main.layout file could 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>

{{{yield}}} is a special tag that renders the page content within the layout. {{{yield}}} can only be used in the main.layout file.

Partials

Partials are reusable snippets that can be included in different areas of your site. Partials must have the .partial extension and must be in the root of your project directory. Partials are called using two curly brackets and a greater than sign.

<body>
  <h1>Welcome!</h1>

  {{> nav}}

  <p>Thanks for checking out my site!</p>
</body>

The nav.partial file could have the following contents:

<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/blog">Blog</a></li>
    <li><a href="/about">About</a></li>
  </ul>
</nav>

This would make the above template expand to:

<body>
  <h1>Welcome!</h1>

  <nav>
    <ul>
      <li><a href="/">Home</a></li>
      <li><a href="/blog">Blog</a></li>
      <li><a href="/about">About</a></li>
    </ul>
  </nav>

  <p>Thanks for checking out my site!</p>
</body>

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 peek 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"] " - " data["site_title"]
  } else {
    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.

Config

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 -

[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 Makefile will be ignored and not copied.

Conversion programs must accept a UNIX-style pipe and send converted data to stdout.

CREDITS

  • zsw: for the introduction to parameter expansion and other shell scripting techniques

LICENSE

MIT

zodiac's People

Contributors

dhempy avatar nuex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zodiac's Issues

Help with helpers.awk

Hello,
I hope it is okay to ask a more general question here. As far as I can tell from the example, creating a list of blog entries on the home or blog page is a manual process. I would like to autmate this using a helper function.

This is, what I have right now:

function list_blogs(  list) {
  CMD="ls -lD\"%Y-%d-%m\" site/blog/*"
  while ((CMD | getline) > 0) {
    sub("site", "")
    sub(".md|.adoc|.rst", ".html")
    list = list"<br><a href=\""$7"\">"$6"</a>"
  }
  return list
}

It kind of works. However... let's assum the CMD output lists 5 files. I'll end up with 6 entries on the page. 5 of them are correctly parsed and one entry is just the raw CMD output. This confuses me...

On a side note, I think what I'm doing here is pretty ugly. If there's a better way, I'd appreceate a bump into the right direction.

An alternative way to do this would be a shell script and assigning .sh with the shell in the zod config.

How are you creating the document lists on your blog?

Thanks and best regards,
Stefan

Support multiline codeblocks

It looks like a single backtick ` is to be used for code blocks:
https://github.com/nuex/zodiac/blob/master/lib/markdown.awk#L104

An example such as this works as expected:

`env | grep FOO`

becomes:

<p><code>env | grep FOO</code></p>

But I cannot seem to get a multiline code block to work. For example, this:

`if [ ! -f ./conf.sh ]; then
	redln "No conf file found"
	echo "Create ./conf.sh"
	exit 2
fi`

becomes:

<p><code>if [ ! -f ./conf.sh ]; then	redln "No conf file found"	echo "Create ./conf.sh"	exit 2fi</code></p>

empty parentheses

On my system I get:

$ find "site" -type f ( ) -exec zod-render "/usr/local/lib/zodiac" "site" "www" {} ;
find: invalid expression; empty parentheses are not allowed.

I don't really understand what the parentheses are supposed to contain - according to Posix a parenthesized expression is true if the expression inside is true?

illegal reference to array ignore

After installing Zodiac, I try to make the example site.
Unfortunately, I got this error :

awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 10: illegal reference to array ignore
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 16: illegal reference to array exts
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 21: illegal reference to array exts
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 26: illegal reference to array opts
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 10: illegal reference to array ignore
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 16: illegal reference to array exts
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 21: illegal reference to array exts
awk: Apps/zodiac/lib/zodiac/find_cmd.awk: line 26: illegal reference to array opts

I use Dash 0.5.7 and mawk 1.3.3.

BusyBox’s implementation of Awk does not work

Steps to reproduce (using Docker):

docker run -it --rm alpine:3.7

Inside the container:

apk update
apk add git make
git clone https://github.com/nuex/zodiac.git --depth 1
cd zodiac
make install
cd example
make

The error which occurs is:

zod site www
awk: bad regex '{{{yield}}}': Repetition not preceded by valid expression
awk: bad regex '{{{yield}}}': Repetition not preceded by valid expression
awk: bad regex '{{{yield}}}': Repetition not preceded by valid expression

apk add gawk fixes the problem. According to GNU’s manual on Awk implementations, “BusyBox […] includes a full implementation of POSIX awk.”.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.