kiln/docs/kiln.1.scd

667 lines
17 KiB
Plaintext
Raw Normal View History

2020-11-11 00:35:56 +00:00
kiln(1)
# NAME
2021-04-12 04:23:27 +00:00
kiln - a simple static site generator
2020-11-11 00:35:56 +00:00
# SYNOPSIS
2021-05-10 19:09:23 +00:00
*kiln* build [-c _config_]
2021-04-20 20:00:39 +00:00
*kiln* new _path_
*kiln* version
# DESCRIPTION
*kiln build* builds a kiln site.
*kiln new* creates a new kiln site at the given path.
2021-05-10 19:09:23 +00:00
*kiln version* prints version information for the kiln program.
2020-11-20 17:07:38 +00:00
# OPTIONS
2021-04-20 20:00:39 +00:00
## kiln build
*-c* _config_
2021-04-12 04:23:27 +00:00
Specifies the configuration file to use. Defaults to "config.toml".
2020-11-11 00:35:56 +00:00
2021-04-12 04:23:27 +00:00
# OVERVIEW
2021-05-21 20:41:35 +00:00
A kiln site is built in one or more steps called *tasks*. Tasks read content
from the content directory, process the content, and write the content to the
output directory. Tasks can also be configured to copy static content to the
output directory.
2021-04-12 04:23:27 +00:00
2021-04-21 01:37:05 +00:00
The following directories are common to all tasks:
2020-11-11 00:35:56 +00:00
2021-04-24 18:11:22 +00:00
[[ *Directory*
2020-11-11 00:35:56 +00:00
:[ *Description*
2021-02-28 17:17:10 +00:00
| content/
2021-04-12 04:23:27 +00:00
: Content directory
2021-03-20 06:18:15 +00:00
| templates/
2021-04-26 18:49:39 +00:00
: Templates directory
# CONTENT DIRECTORY
The content directory contains site content files, called *pages*, optionally
nested in subdirectories. Any file or directory in the content directory whose
2021-05-21 20:41:35 +00:00
name begins with "\_" will be ignored, with the exception of pages with the name
"\_index" (e.g. "\_index.gmi").
2021-04-26 18:49:39 +00:00
Pages may be preprocessed, run through templates, and postprocessed (in that
order). Each operation takes the output of the last operation as input.
Pages can specify dates in their filenames. For example, the page
content/2020-11-20-Hello-world.gmi will have a path of /Hello-world/ and a date
of November 20, 2020.
2021-05-21 20:41:35 +00:00
Pages with the name "\_index" are index pages and are treated specially.
2021-04-26 18:49:39 +00:00
## FRONTMATTER
2021-05-21 20:41:35 +00:00
Pages can specify additional metadata in frontmatter. Frontmatter is delimited
by "---" and is specified in YAML. Newlines after the closing delimiter are
removed from the content.
2021-04-26 18:49:39 +00:00
Example:
```
---
title: Page title
date: 2021-04-24
params:
custom: value
---
Page content
```
The following keys are supported:
2021-05-21 20:53:05 +00:00
*title*
The title of the page.
Example:
```
---
title: My first post
---
```
*date*
The date of the page. Pages are sorted by date in reverse order, so newer
pages will be placed above older pages.
Example:
```
---
date: 2021-05-21
---
```
*weight*
The weight of the page. Pages are sorted by weight in increasing order, so
pages with a smaller weight will be placed above pages with a larger weight.
Example:
```
---
weight: 1
---
```
*params*
Specifies extra parameters to be provided to templates.
Example:
```
---
params:
key: value
---
```
## SORTING
Pages are sorted automatically. Pages are first ordered by weight in increasing
order, then by date from newest to oldest, and then by filename in alphabetical
order.
2021-04-26 18:49:39 +00:00
# TEMPLATES DIRECTORY
The templates directory contains templates for use when building the site.
Templates use the Go templating language. The following templates are supported:
[[ *Template*
:[ *Description*
| page.ext
: Page template
| index.ext
: Directory index template
2021-05-21 20:41:35 +00:00
| base.ext
: Base template from which the page and index templates inherit
2021-04-26 18:49:39 +00:00
| atom.xml
: Atom feed template
The extension of page and index templates is configurable and will replace
".ext" above. See *CONFIGURATION*.
The scope of a template is limited by the directory it is placed in. For
example, a template in the templates/blog directory will only apply to files in
content/blog.
Fallback templates can be specified in the templates/\_default directory. These
2021-05-21 20:41:35 +00:00
templates will apply to any directory which does not have its own templates
specified in the template directory.
2021-04-26 18:49:39 +00:00
For more information on the Go templating language, see
https://golang.org/pkg/text/template/.
2021-04-12 04:23:27 +00:00
# CONFIGURATION
2020-11-11 00:35:56 +00:00
2021-04-26 18:49:39 +00:00
By default, kiln looks for a configuration file named "config.toml". An
alternative configuration file can be specified with the *-c* flag. See
*OPTIONS*.
2021-05-21 20:41:35 +00:00
The configuration file uses the _TOML_ format.
2020-11-22 20:51:07 +00:00
2021-04-12 04:23:27 +00:00
The following keys are supported:
2021-04-24 18:11:22 +00:00
[[ *Key*
2021-04-12 04:23:27 +00:00
:[ *Description*
| title
: Site title
| urls
: A list of site URLs
2020-11-11 00:35:56 +00:00
2021-04-12 04:23:27 +00:00
Site URLs may contain paths, but should not end with a trailing slash. Multiple
site URLs may be specified for sites that are available at multiple locations.
2021-04-26 18:49:39 +00:00
## FEEDS
Feeds can be specified in the [feeds] table of the configuration file. Keys
denote the path to the feed directory and values denote the title of the feed.
Feeds are written to the output directory plus the feed directory plus
"atom.xml".
Example feed configuration:
```
# This will generate a feed which will be written to public/blog/atom.xml
[feeds]
"/blog/" = "My blog"
```
2021-05-14 04:28:41 +00:00
## PERMALINKS
Permalinks can be used to rewrite page paths. Permalinks are specified in the
\[permalinks] table of the configuration file. Keys denote a path to a directory,
2021-05-14 04:28:41 +00:00
and values use the Go templating language to rewrite the final path of pages in
that directory. The templates have the same data that page templates have
available to them (see *PAGE TEMPLATES*).
The following configuration will rewrite the paths of pages in the content/blog
directory to /YYYY/MM/DD/slug. For example, the file
content/blog/2021-05-12-hello-world.gmi will have a path of
/2021/05/12/hello-world/.
```
[permalinks]
2021-05-21 21:08:36 +00:00
"/blog/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Permalink }}"
2021-05-14 04:28:41 +00:00
```
For more information on templates, see *TEMPLATES*.
2021-04-12 15:09:14 +00:00
## TASKS
2021-05-21 20:41:35 +00:00
Tasks can be specified in the [[tasks]] array of tables.
2021-04-12 15:09:14 +00:00
2021-05-21 20:41:35 +00:00
The following configuration options are supported per task:
2021-04-12 15:09:14 +00:00
2021-05-21 20:41:35 +00:00
*input*
A list of input file extensions. Files in the content directory with a
matching extension will be processed.
Example:
```
[[tasks]]
input = [".gmi", ".md"]
```
*output*
The output file extension. Files written to the output directory will use
this extension.
Example:
```
[[tasks]]
output = ".html"
```
*template*
The template file extension. Templates with this file extension will be used
to format the content. If unset, no templates will be used.
Example:
```
[[tasks]]
template = ".gmi"
```
*preprocess*
Maps file extensions to preprocess commands. Preprocess commands will run
before templating. The commands will be provided the content of the page as
standard input and should write the processed content to standard output.
Example:
```
[[tasks]]
input = [".gmi", ".md"]
output = ".html"
preprocess.gmi = "gmnitohtml"
preprocess.md = "mdtohtml"
```
*postprocess*
Specifies a command which will run after templating and before content is
written to the output directory. It will be provided the content of the page
as standard input and should write the processed content to standard output.
Example:
```
[[tasks]]
input = [".gmi"]
output = ".html"
template = ".gmi"
postprocess = "gmnitohtml"
```
*static_dir*
Specifies a directory from which to read static content. All files in this
directory will be copied to the output directory without modificiation.
Static assets like images should be stored in this directory. If unset, no
static content directory will be used.
Example:
```
[[tasks]]
static_dir = "static"
```
*output_dir*
Specifies the directory to which output files will be written.
Example:
```
[[tasks]]
output_dir = "public"
```
*ugly_urls*
Specifies whether page permalinks will contain file extensions. By default,
clean URLs without any extension are used.
Example:
```
[[tasks]]
ugly_urls = true
```
The following configuration builds a simple Gemini site.
```
[[tasks]]
input = [".gmi"]
output = ".gmi"
template = ".gmi"
output_dir = "public"
```
2021-04-12 15:09:14 +00:00
The following configuration generates a Gemini text site and also exports an
2021-04-24 18:11:22 +00:00
HTML version of the site. This configuration makes use of the *gmnitohtml*(1)
2021-04-12 15:09:14 +00:00
command to convert Gemini text to HTML.
```
# Build the site
2021-05-10 19:09:23 +00:00
[[tasks]]
2021-05-10 16:47:38 +00:00
input = [".gmi"]
output = ".gmi"
template = ".gmi"
2021-04-12 15:09:14 +00:00
static_dir = "static"
output_dir = "public"
# Export an HTML version of the site
2021-05-10 19:09:23 +00:00
[[tasks]]
2021-05-10 16:47:38 +00:00
input = [".gmi"]
output = ".html"
template = ".gmi"
2021-04-24 18:11:22 +00:00
postprocess = "gmnitohtml"
2021-04-12 15:09:14 +00:00
static_dir = "static"
output_dir = "public.html"
```
The following configuration generates an HTML site from Markdown files in the
2021-04-26 18:49:39 +00:00
content directory and HTML templates in the templates directory. This
2021-04-12 15:09:14 +00:00
configuration makes use of the *markdown*(1) comand to convert Markdown to HTML.
```
2021-05-10 19:09:23 +00:00
[[tasks]]
2021-05-10 16:47:38 +00:00
input_ext = [".md"]
2021-04-12 15:09:14 +00:00
output_ext = ".html"
2021-04-24 18:11:22 +00:00
template_ext = ".html"
2021-05-10 16:47:38 +00:00
preprocess.md = "markdown"
2021-04-12 15:09:14 +00:00
static_dir = "static"
output_dir = "public"
```
2021-04-26 18:49:39 +00:00
# TEMPLATES
2021-04-24 18:11:22 +00:00
2021-04-26 18:49:39 +00:00
Templates have certain data and functions available to them.
2021-04-12 04:23:27 +00:00
2021-04-26 18:49:39 +00:00
## TEMPLATE FUNCTIONS
2020-11-20 17:07:38 +00:00
All templates have the following functions available to them:
2021-05-17 16:41:37 +00:00
*and* _args..._
Returns the boolean AND of its arguments by returning the
first empty argument or the last argument, that is,
"and x y" behaves as "if x then y else x". All the
arguments are evaluated.
*call* _function_, _args..._
Returns the result of calling the first argument, which
must be a function, with the remaining arguments as parameters.
Thus "call .X.Y 1 2" is, in Go notation, dot.X.Y(1, 2) where
Y is a func-valued field, map entry, or the like.
The first argument must be the result of an evaluation
that yields a value of function type (as distinct from
a predefined function such as print). The function must
return either one or two result values, the second of which
is of type error. If the arguments don't match the function
or the returned error value is non-nil, execution stops.
*eq* _arg1_, _arg2_
Returns the boolean truth of _arg1_ == _arg2_.
*ge* _arg1_, _arg2_
Returns the boolean truth of _arg1_ >= _arg2_.
*gt* _arg1_, _arg2_
Returns the boolean truth of _arg1_ > _arg2_.
*html* _args..._
Returns the escaped HTML equivalent of the textual
representation of its arguments. This function is unavailable
in HTML templates, with a few exceptions.
*index* _collection_, _args..._
Returns the result of indexing its first argument by the
following arguments. Thus "index x 1 2 3" is, in Go syntax,
x[1][2][3]. Each indexed item must be a map, slice, or array.
*js* _args..._
Returns the escaped JavaScript equivalent of the textual
representation of its arguments.
*le* _arg1_, _arg2_
Returns the boolean truth of _arg1_ <= _arg2_.
*len* _list_
Returns the integer length of its argument.
*lt* _arg1_, _arg2_
Returns the boolean truth of _arg1_ < _arg2_.
*ne* _arg1_, _arg2_
Returns the boolean truth of _arg1_ != _arg2_.
*not* _arg_
Returns the boolean negation of its single argument.
*or* _args..._
Returns the boolean OR of its arguments by returning the
first non-empty argument or the last argument, that is,
"or x y" behaves as "if x then x else y". All the
arguments are evaluated.
2021-05-21 20:41:35 +00:00
*partial* _name_, _data_
Executes the named partial template with the provided data. See *PARTIAL
TEMPLATES*.
Example:
```
{{ partial "header.gmi" . }}
```
2021-05-10 16:47:38 +00:00
*path.Base* _path_
2021-05-17 16:25:51 +00:00
Returns the last element of _path_.
2021-05-10 16:47:38 +00:00
*path.Clean* _path_
2021-05-17 16:25:51 +00:00
Returns the shortest path name equivalent to _path_.
2021-05-10 16:47:38 +00:00
*path.Dir* _path_
2021-05-17 16:25:51 +00:00
Returns all but the last element of _path_, typically the path's directory.
2021-05-10 16:47:38 +00:00
*path.Ext* _path_
2021-05-17 16:25:51 +00:00
Returns the filename extension used by _path_.
2021-05-10 16:47:38 +00:00
*path.Join* _elem..._
Joins any number of path elements into a single path.
2021-05-17 16:41:37 +00:00
*print* _args..._
Formats using the default formats for its operands and returns the resulting
string. Spaces are added between operands when neither is a string.
*printf* _format_, _args..._
Formats according to a format specifier and returns the resulting string.
*println* _args..._
Formats using the default formats for its operands and returns the resulting
string. Spaces are always added between operands and a newline is appended.
2021-05-17 16:25:51 +00:00
*reverse* _list_
Returns a reversed copy of the provided slice or array.
*safeCSS* _css_
Encapsulates known safe CSS content.
2021-05-10 16:47:38 +00:00
*safeHTML* _html_
Encapsulates a known safe HTML document fragment.
*safeHTMLAttr* _attr_
Encapsulates an HTML attribute from a trusted source.
*safeJS* _js_
Encapsulates a known safe JavaScript expression.
*safeURL* _url_
Encapsulates a known safe URL or URL substring.
2020-11-20 17:07:38 +00:00
2021-05-17 16:25:51 +00:00
*site*
Returns site metadata (see *SITE METADATA*).
2021-05-17 16:41:37 +00:00
*slice* _list_, _args..._
slice returns the result of slicing its first argument by the
remaining arguments. Thus "slice x 1 2" is, in Go syntax, x[1:2],
while "slice x" is x[:], "slice x 1" is x[1:], and "slice x 1 2 3"
is x[1:2:3]. The first argument must be a string, slice, or array.
2021-05-17 16:25:51 +00:00
*strings.Count* _string_, _substr_
Counts the number of non-overlapping instances of _substr_ in _string_.
If _substr_ is an empty string, Count returns 1 + the number of Unicode code
points in _string_.
*strings.HasPrefix* _string_, _prefix_
Reports whether _string_ begins with _prefix_.
*strings.HasSuffix* _string_, _suffix_
Reports whether _string_ ends with _suffix_.
*strings.Join* _elems_, _sep_
Concatenates the elements of its first argument to create a single string.
The separator string _sep_ is placed between elements in the resulting
string.
*strings.Repeat* _string_, _count_
Returns a new string consisting of _count_ copies of _string_.
It panics if _count_ is negative or if the result of
(len(_string_) \* _count_) overflows.
*strings.Replace* _string_, _old_, _new_, _n_
Returns a copy of _string_ with the first _n_ non-overlapping instances of
_old_ replaced by _new_. If _old_ is empty, it matches at the beginning of
the string and after each UTF-8 sequence, yielding up to k+1 replacements
for a k-rune string. If _n_ < 0, there is no limit on the number of
replacements.
*strings.ReplaceAll* _string_, _old_, _new_
Returns a copy of _string_ with all non-overlapping instances of _old_
replaced by _new_. If _old_ is empty, it matches at the beginning of the
string and after each UTF-8 sequence, yielding up to k+1 replacements for a
k-rune string.
*strings.Split* _string_, _sep_
Slices _string_ into all substrings separated by _sep_ and returns a slice
of the substrings between those separators.
If _string_ does not contain _sep_ and _sep_ is not empty, Split returns a
slice of length 1 whose only element is _string_.
If _sep_ is empty, Split splits after each UTF-8 sequence. If both _string_
and _sep_ are empty, Split returns an empty slice.
*strings.Title* _string_
Returns a copy of the string with all Unicode letters that begin words
mapped to their Unicode title case.
*BUG:* The rule Title uses for word boundaries does not handle Unicode
punctuation properly.
*strings.ToLower* _string_
Returns _string_ with all Unicode letters mapped to their lower case.
*strings.ToUpper* _string_
Returns _string_ with all Unicode letters mapped to their upper case.
*strings.Trim* _string_, _cutset_
Returns a slice of _string_ with all leading and trailing Unicode code
points contained in _cutset_ removed.
*strings.TrimLeft* _string_, _cutset_
Returns a slice of _string_ with all leading Unicode code points contained
in _cutset_ removed.
To remove a prefix, use *strings.TrimPrefix* instead.
*strings.TrimPrefix* _string_, _prefix_
Returns _string_ without the provided leading _prefix_ string. If _string_
doesn't start with _prefix_, it is returned unchanged.
*strings.TrimRight* _string_, _cutset_
Returns a slice of _string_ with all trailing Unicode code points contained
in _cutset_ removed.
To remove a suffix, use *strings.TrimSuffix* instead.
*strings.TrimSpace* _string_
Returns a slice of _string_ with all leading and trailing white space
removed, as defined by Unicode.
*strings.TrimSuffix* _string_, _suffix_
Returns _string_ without the provided trailing _suffix_ string. If _string_
doesn't end with _suffix_, it is returned unchanged.
2021-05-17 16:41:37 +00:00
*urlquery* _args..._
Returns the escaped value of the textual representation of
its arguments in a form suitable for embedding in a URL query.
This function is unavailable in HTML templates, with a few
exceptions.
2020-11-20 17:07:38 +00:00
## SITE METADATA
2021-04-12 04:23:27 +00:00
Site metadata contains the following data:
2020-11-20 17:07:38 +00:00
2021-05-21 20:41:35 +00:00
package main
import (
"fmt"
"path"
)
func main() {
fmt.Println(path.Join("https://example.com", "hello-world"))
}
2021-04-24 18:11:22 +00:00
[[ *Variable*
2020-11-20 17:07:38 +00:00
:[ *Description*
| Title
2020-11-22 20:51:07 +00:00
: The title of the site.
2020-12-21 21:41:05 +00:00
| URLs
: The URLs of the site.
2020-11-22 20:51:07 +00:00
To configure these variables, see *CONFIGURATION*.
2020-11-11 00:35:56 +00:00
## PAGE TEMPLATES
2021-04-12 04:23:27 +00:00
Page templates are provided with the following data:
2020-11-11 00:35:56 +00:00
2021-04-24 18:11:22 +00:00
[[ *Variable*
2020-11-11 00:35:56 +00:00
:[ *Description*
| Title
: The title of the page
| Date
: The date of the page
2021-05-21 21:08:36 +00:00
| Permalink
: The permanent link to this page
2020-11-11 00:35:56 +00:00
| Content
: The contents of the page
2021-04-26 18:49:39 +00:00
| Params
: Extra parameters specified in frontmatter
2020-11-11 00:35:56 +00:00
## INDEX TEMPLATES
2021-04-26 18:49:39 +00:00
Index templates are provided with all the data that page templates are provided,
plus the following data:
2020-11-11 00:35:56 +00:00
2021-04-24 18:11:22 +00:00
[[ *Variable*
2020-11-11 00:35:56 +00:00
:[ *Description*
| Pages
: List of pages in this directory
2020-11-20 17:07:38 +00:00
| Dirs
2020-11-11 00:35:56 +00:00
: List of subdirectories
2020-11-20 17:07:38 +00:00
## FEED TEMPLATES
2020-11-11 00:35:56 +00:00
2021-04-26 18:49:39 +00:00
Feed templates are provided with the following data:
2020-11-11 00:35:56 +00:00
2021-04-24 18:11:22 +00:00
[[ *Variable*
2020-11-20 17:07:38 +00:00
:[ *Description*
| Title
: Title of the feed
2021-05-21 21:08:36 +00:00
| Permalink
: The permanent link to the feed directory
2020-11-20 17:07:38 +00:00
| Entries
2020-11-22 20:51:07 +00:00
: List of pages in this feed
2020-11-11 00:35:56 +00:00
2021-05-21 20:41:35 +00:00
## PARTIAL TEMPLATES
Partial templates can be specified in the templates/\_partials directory.
Partial templates can be executed from any other template with the *partial*
function. See *TEMPLATE FUNCTIONS*.