plain html page template support
This commit is contained in:
parent
1f70ba70dc
commit
3728cb7b44
@ -49,7 +49,11 @@ Page metadata will always override global metadata of the same key.
|
|||||||
|
|
||||||
### Templates
|
### Templates
|
||||||
|
|
||||||
Templates come in two forms: markdown files with an `.md` extension or layout files with a `.layout` extension. Metadata can be bound to templates by using the `{{key}}` notation in your markdown and layout files. A `main.layout` file could look something like this:
|
Templates come in two forms, page templates and layout templates. Metadata can be bound to templates by using the `{{key}}` notation in your markdown and layout files.
|
||||||
|
|
||||||
|
Page templates can be either markdown files with an `.md` extension or plain HTML files with a `.html` extension.
|
||||||
|
|
||||||
|
The `main.layout` file wraps HTML content around a page template. A `main.layout` file could look something like this:
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@ -97,7 +101,6 @@ Just be sure to set the data array in the load_helpers() function at the top of
|
|||||||
|
|
||||||
## FUTURE
|
## FUTURE
|
||||||
|
|
||||||
- HTML content pages (i.e. no filtering)
|
|
||||||
- multiple filters support
|
- multiple filters support
|
||||||
- multiple layout support
|
- multiple layout support
|
||||||
- mustache support
|
- mustache support
|
||||||
|
15
bin/zod
15
bin/zod
@ -56,11 +56,16 @@ for f in $files; do
|
|||||||
targetpath=$target
|
targetpath=$target
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$(find $f -name *.md)" ]; then
|
file_basename=$(basename $f)
|
||||||
page_name=$(basename $f | sed 's/\.md//')
|
file_extension=$(echo $file_basename | awk -F . '{print $NF}')
|
||||||
|
file_name=$(echo $file_basename | sed -e 's/\.md//' -e 's/\.html//')
|
||||||
|
|
||||||
if [ -e $dir/$page_name.meta ]; then
|
# If the file's extension wasn't replaced (i.e. same as basename) then
|
||||||
page_meta_opts=$dir/$page_name.meta
|
# we know it isn't a template.
|
||||||
|
if [ $file_name != $file_basename ]; then
|
||||||
|
|
||||||
|
if [ -e $dir/$file_name.meta ]; then
|
||||||
|
page_meta_opts=$dir/$file_name.meta
|
||||||
fi
|
fi
|
||||||
|
|
||||||
awk -f $ZODLIB/render.awk \
|
awk -f $ZODLIB/render.awk \
|
||||||
@ -69,7 +74,7 @@ for f in $files; do
|
|||||||
$global_meta_opts \
|
$global_meta_opts \
|
||||||
$page_meta_opts \
|
$page_meta_opts \
|
||||||
$f \
|
$f \
|
||||||
$layout_opts > $targetpath/$page_name.html
|
$layout_opts > $targetpath/$file_name.html
|
||||||
|
|
||||||
else
|
else
|
||||||
cp $f $targetpath # Copying a non-template file
|
cp $f $targetpath # Copying a non-template file
|
||||||
|
@ -56,11 +56,16 @@ for f in $files; do
|
|||||||
targetpath=$target
|
targetpath=$target
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$(find $f -name *.md)" ]; then
|
file_basename=$(basename $f)
|
||||||
page_name=$(basename $f | sed 's/\.md//')
|
file_extension=$(echo $file_basename | awk -F . '{print $NF}')
|
||||||
|
file_name=$(echo $file_basename | sed -e 's/\.md//' -e 's/\.html//')
|
||||||
|
|
||||||
if [ -e $dir/$page_name.meta ]; then
|
# If the file's extension wasn't replaced (i.e. same as basename) then
|
||||||
page_meta_opts=$dir/$page_name.meta
|
# we know it isn't a template.
|
||||||
|
if [ $file_name != $file_basename ]; then
|
||||||
|
|
||||||
|
if [ -e $dir/$file_name.meta ]; then
|
||||||
|
page_meta_opts=$dir/$file_name.meta
|
||||||
fi
|
fi
|
||||||
|
|
||||||
awk -f $ZODLIB/render.awk \
|
awk -f $ZODLIB/render.awk \
|
||||||
@ -69,7 +74,7 @@ for f in $files; do
|
|||||||
$global_meta_opts \
|
$global_meta_opts \
|
||||||
$page_meta_opts \
|
$page_meta_opts \
|
||||||
$f \
|
$f \
|
||||||
$layout_opts > $targetpath/$page_name.html
|
$layout_opts > $targetpath/$file_name.html
|
||||||
|
|
||||||
else
|
else
|
||||||
cp $f $targetpath # Copying a non-template file
|
cp $f $targetpath # Copying a non-template file
|
||||||
|
@ -5,10 +5,22 @@ BEGIN {
|
|||||||
helpers_loaded = "no"
|
helpers_loaded = "no"
|
||||||
content = ""
|
content = ""
|
||||||
layout = ""
|
layout = ""
|
||||||
|
filter = "html"
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
action = action_from_filetype(FILENAME)
|
split(FILENAME, parts, ".")
|
||||||
|
ext = parts[length(parts)]
|
||||||
|
if (ext == "meta") action = "meta"
|
||||||
|
if (ext == "layout") action = "layout"
|
||||||
|
if (ext == "md") {
|
||||||
|
action = "page"
|
||||||
|
filter = "markdown"
|
||||||
|
}
|
||||||
|
if (ext == "html") {
|
||||||
|
action = "page"
|
||||||
|
filter = "html"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Process lines from meta files
|
# Process lines from meta files
|
||||||
@ -58,12 +70,6 @@ END {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
function bind_data(txt, tag, key) {
|
||||||
if (match(txt, /{{([^}]*)}}/)) {
|
if (match(txt, /{{([^}]*)}}/)) {
|
||||||
tag = substr(txt, RSTART, RLENGTH)
|
tag = substr(txt, RSTART, RLENGTH)
|
||||||
@ -77,7 +83,8 @@ function bind_data(txt, tag, key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function render_content(txt) {
|
function render_content(txt) {
|
||||||
return markdown(txt)
|
if (filter == "html") return txt
|
||||||
|
if (filter == "markdown") return markdown(txt)
|
||||||
}
|
}
|
||||||
|
|
||||||
function markdown(txt, rand_date, tmpfile, rendered_txt, date_cmd, markdown_cmd, line) {
|
function markdown(txt, rand_date, tmpfile, rendered_txt, date_cmd, markdown_cmd, line) {
|
||||||
|
Loading…
Reference in New Issue
Block a user