Fixed build.

This commit is contained in:
Elf M. Sternberg 2022-05-13 12:18:44 -07:00
parent e8041c74df
commit 461f851a72
6 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,67 @@
+++
title = "Zola Cookbook"
description = "Snippets I've developed that I want to keep"
date = 2022-04-27T18:00:00+00:00
updated = 2022-04-27T18:00:00+00:00
template = "docs/section.html"
sort_by = "weight"
weight = 5
draft = false
[taxonomies]
documentation=["Reference"]
categories=["Web Development", "Static Site Generation", "Zola"]
+++
[Zola](../zola) is the static site generator I use for most of my websites that
don't require much dynamic functionality.
## Generating Nested Lists from Data
Example data:
```html
{
"definitions": [
{ "dt": "undefined", "dd": " the thing is undefined." },
{ "dt": "defined", "dd": " the thing is defined.", definitions: [
{ "dt": "truthy", "dd": "the defined thing is truthy" },
{ "dt": "falsy", "dd": "the defined thing is falsy" }
]}
]
}
```
Tera macro to render a nested list:
```
{% macro definition_body(source) %}
<dl>
{% for entry in source %}
<dt><kbd>{{ entry.dt | safe }}</kbd></dt>
<dd>
{{ entry.dd | safe }}
{% if entry.definitions %}
{{ self::definition_body(source=entry.definitions) }}
{% endif %}
</dd>
{% endfor %}
</dl>
{% endmacro %}
```
Zola shortcode to import the macro template into Markdown and start the render:
```
{%- import 'macros/definition_body.html' as renderer -%}
<div>
{% set content = load_data(path=source) %}
{{ renderer::definition_body(source=content.definitions) }}
</div>
```
Invocation in Markdown file, providing the data source:
```
{ { definition_list(source="docs/zola/definitions.json") }}
```

View File

@ -107,6 +107,8 @@ Conditional statements are managed with `if/is ... else ... endif`
The list of `is` tests that are shipped with Zola are:
{{ definition_list(source="docs/zola/predicates.json") }}
- `defined`: the given variable is defined.
- `undefined`: the given variable is undefined.
- `odd`: the given variable is an odd number.

View File

@ -0,0 +1,40 @@
{
"definitions": [
{ "dt": "defined", "dd": " the given variable is defined." },
{ "dt": "undefined", "dd": " the given variable is undefined." },
{ "dt": "odd", "dd": " the given variable is an odd number." },
{ "dt": "even", "dd": " the given variable is an even number." },
{ "dt": "string", "dd": " the given variable is a string." },
{ "dt": "number", "dd": " the given variable is a number." },
{ "dt": "divisibleby", "dd": " the given expression is divisible by the arg given." },
{
"dt": "iterable",
"dd": " Returns true if the given variable can be iterated over in Tera (i.e. is an array/tuple or an object)."
},
{
"dt": "object",
"dd": " Returns true if the given variable is an object (i.e. can be iterated over key, value)."
},
{
"dt": "starting_with(string)",
"dd": " Returns true if the given variable is a string and starts with the arg given."
},
{
"dt": "ending_with(string)",
"dd": " Returns true if the given variable is a string and ends with the arg given."
},
{
"dt": "containing(val)",
"dd": " Returns true if the given variable contains the arg given.",
"definitions": [
{ "dt": "strings", "dd": " is the arg a substring?" },
{ "dt": "arrays", "dd": " is the arg one of the members of the array?" },
{ "dt": "maps", "dd": " is the arg a key of the map?" }
]
},
{
"dt": "matching(regexp)",
"dd": " Returns true if the given variable is a string and matches the regex in the argument."
}
]
}

View File

@ -0,0 +1,52 @@
---
definitions:
-
dt: "defined"
dd: " the given variable is defined."
-
dt: "undefined"
dd: " the given variable is undefined."
-
dt: "odd"
dd: " the given variable is an odd number."
-
dt: "even"
dd: " the given variable is an even number."
-
dt: "string"
dd: " the given variable is a string."
-
dt: "number"
dd: " the given variable is a number."
-
dt: "divisibleby"
dd: " the given expression is divisible by the arg given."
-
dt: "iterable"
dd: " Returns true if the given variable can be iterated over in Tera (i.e. is an array/tuple or an object)."
-
dt: "object"
dd: " Returns true if the given variable is an object (i.e. can be iterated over key, value)."
-
dt: "starting_with(string)"
dd: " Returns true if the given variable is a string and starts with the arg given."
-
dt: "ending_with(string)"
dd: " Returns true if the given variable is a string and ends with the arg given."
-
dt: "containing(val)"
dd: " Returns true if the given variable contains the arg given."
definitions:
-
dt: "strings"
dd: " is the arg a substring?"
-
dt: "arrays"
dd: " is the arg one of the members of the array?"
-
dt: "maps"
dd: " is the arg a key of the map?"
-
dt: "matching(regexp)"
dd: " Returns true if the given variable is a string and matches the regex in the argument."

View File

@ -0,0 +1,9 @@
{% macro definition_body(source) %}
<dl>
{% for entry in source %}
<dt><kbd>{{ entry.dt | safe }}</kbd></dt>
<dd>{{ entry.dd | safe }}</dd>
{% if entry.definitions %}{{ self::definition_body(source=entry.definitions) }}{% endif %}
{% endfor %}
</dl>
{% endmacro %}

View File

@ -0,0 +1,5 @@
{%- import 'macros/definition_body.html' as renderer -%}
<div>
{% set content = load_data(path=source) %}
{{ renderer::definition_body(source=content.definitions) }}
</div>