From 6d5e72513b82fcf145604a6eda18b2e2a07fa0a3 Mon Sep 17 00:00:00 2001 From: adnano Date: Wed, 23 Sep 2020 13:50:25 -0400 Subject: [PATCH] Update README.md --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kiln.go | 4 +++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9be3688..d0be136 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,29 @@ Page templates are provided with the following information: - `Permalink`: Permalink to the page - `Content`: The contents of the file (including the title) +Pages can specify dates in their filenames. kiln will recognize the date and +remove it from the permalink. + +Pages can also specify titles in their content. kiln will parse and remove the +title from the content. Example: + +``` +$ cat src/hello-world.gmi +# Hello, world! + +This is some content. + +$ cat templates/page.gmi +Title: {{ .Title }} +Content: +{{ .Content }} + +$ cat dst/hello-world.gmi +Title: Hello, world! +Content: +This is some content. +``` + ## Directories Directory templates are provided with the following information: @@ -55,6 +78,24 @@ Directory templates are provided with the following information: - `Pages`: The pages in this directory - `Directories`: The subdirectories of this directory +Directory templates are written to `index.gmi` in the corresponding directory. +Example: + +``` +$ ls src/posts/ +src/posts/post-1.gmi +src/posts/post-2.gmi + +$ cat templates/directory.gmi +{{ range .Pages }} +=> .Permalink +{{ end }} + +$ cat dst/posts/index.gmi +=> /posts/post-1.gmi +=> /posts/post-2.gmi +``` + ## Templates Templates are located in the `templates` directory. @@ -63,3 +104,28 @@ There are currently two supported templates: - `page.gmi`: The template used for pages - `directory.gmi`: The template used for directories + +If `page.gmi` does not exist, kiln will simply copy pages from source to +destination. If `directory.gmi` does not exist, directory index files will not +be created. + +## Permalinks + +Every page and directory in the site is assigned a path and a permalink. + +``` +file: src/posts/2020-09-22-hello-world.gmi +path: posts/2020-09-22-hello-world.gmi +permalink: /posts/hello-world.gmi +``` + +Paths are relative and point to the source file. +Permalinks are absolute and point to the destination file. + +Here is an example of a directory: + +``` +directory: src/posts/ +path: posts +permalink: /posts/ +``` diff --git a/kiln.go b/kiln.go index 016dfbe..d22264b 100644 --- a/kiln.go +++ b/kiln.go @@ -10,6 +10,7 @@ import ( "time" ) +// Site represents a kiln site. type Site struct { Static map[string][]byte // Static files Directory *Directory // Site directory @@ -127,6 +128,7 @@ type Page struct { var titleRE = regexp.MustCompile("^# ?([^#\r\n]+)\r?\n?\r?\n?") +// NewPage returns a new Page with the given path and content. func NewPage(path string, content string) *Page { // Try to parse the date from the page filename var date time.Time @@ -185,7 +187,7 @@ type Directory struct { Index *Page } -// NewSection returns a new Section with the given path. +// NewDirectory returns a new Directory with the given path. func NewDirectory(path string) *Directory { var permalink string if path == "" {