Articles can specify metadata (“headers”) in the form of key:value pairs at the top of an article.
Following is a list of header fields that are special to lanyon. These header fields will use a default value if not specified, and are thus always available in the template context.
You can also specify your own custom header fields and access them in the template.
Example:
title: Hello World!
date: 2009-12-12
tags: example, helloworld
url: 2009/dec/12/
foo: bar
Hello, World!
There are several ways to specify an output URL/directory. The simplest one is to write it in the article itself:
url: 2009/05/05/foobar.html
or, in case you want to hide the .html extension, append a slash at the end:
url: 2009/05/05/foobar/
The rendered article will then be written to a index.html file in the foobar directory.
You can use variables in the URL header. They must be prefixed by a dollar sign. Example:
url: $year/$month/$day/$slug.$ext
The following variables are available:
You can use names to refer to url patterns:
url: pretty
If you don’t specify an url, the “default” rule is used. The following named url patterns are available:
Custom url patterns go into the urls.py file inside the project directory.
Here’s an example that defines a slug_only url pattern (the function name is used as the pattern name). This url will write articles into the root output directory:
from os.path import basename, splitext
from lanyon.url import register
@register
def slug_only(**kwargs):
path = kwargs['path']
output_ext = kwargs['extension']
filename, ext = splitext(basename(path))
url = filename + '.' + output_ext
return url
You can now use the slug_only url pattern in your articles:
url: slug_only
The following values are available in the keyword argument kwargs:
Bonus tip: You can use the same variables as described above:
from lanyon.url import register
@register
def slug_only(**kwargs):
return '$slug.$ext'
The register decorator optionally takes a match argument. This argument allows you to specify a URL for files that match a specific input path. The value of the match argument must be a fnmatch pattern like articles/*. If no match argument is specified the default value * is used.
Here is an example that will override the default URL pattern and write all articles to writing/$slug/ unless they are in the old/ directory, in which case they will be written to $year/$month/$day/$slug/:
from lanyon.url import register
@register
def default(**kwargs):
return 'writing/$slug/'
@register(match='articles/old/*')
def default(**kwargs):
return '$year/$month/$day/$slug/'