aboutsummaryrefslogtreecommitdiffstats
path: root/man/ssg-templates.5
diff options
context:
space:
mode:
Diffstat (limited to 'man/ssg-templates.5')
-rw-r--r--man/ssg-templates.5131
1 files changed, 67 insertions, 64 deletions
diff --git a/man/ssg-templates.5 b/man/ssg-templates.5
index 8f31920..156eef9 100644
--- a/man/ssg-templates.5
+++ b/man/ssg-templates.5
@@ -1,83 +1,86 @@
-.TH SSG-TEMPLATES 5 "2026-01-01" "ssg" "File Formats Manual"
-.SH NAME
-ssg-templates \- ssg template format
-.SH DESCRIPTION
-ssg templates use Go's
-.B html/template
-syntax. Each HTML file in the templates directory is processed and rendered
-to the output directory with the same filename.
-.SH DATA
-Data from JSON files in the data directory is made available to templates.
-Each file becomes a template variable named after the file (without the
-.I .json
+.Dd January 2, 2026
+.Dt SSG-TEMPLATES 5
+.Os
+.Sh NAME
+.Nm ssg-templates
+.Nd ssg template format
+.Sh DESCRIPTION
+Templates use Go's
+.Lk https://pkg.go.dev/html/template html/template
+syntax. Each HTML file in the templates directory (default:
+.Pa templates/ )
+is processed and rendered to
+the output directory with the same filename and directory structure.
+.Sh DATA
+Data from JSON files in the data directory (default:
+.Pa data/ )
+is made available to templates. Each file becomes a template variable named
+after the file (without the
+.Pa .json
extension).
-.PP
+.Pp
For example, if
-.I data/projects.json
+.Pa data/projects.json
contains:
-.PP
-.RS
-.nf
+.Bd -literal -offset indent
[
{"name": "foo", "url": "https://example.com/foo", "featured": true},
{"name": "bar", "url": "https://example.com/bar", "featured": false}
]
-.fi
-.RE
-.PP
+.Ed
+.Pp
It can be accessed in templates as
-.BR .projects :
-.PP
-.RS
-.nf
+.Va .projects :
+.Bd -literal -offset indent
{{range .projects}}
<li><a href="{{.url}}">{{.name}}</a></li>
{{end}}
-.fi
-.RE
-.SH FUNCTIONS
-.SS filter
-The
-.B filter
-function returns items from an array where a field equals a value.
-.PP
-.RS
-.nf
-{{range filter .projects "featured" true}}
- <li>{{.name}}</li>
-{{end}}
-.fi
-.RE
-.PP
-This would output only "foo" since it has
-.B featured
-set to
-.BR true .
-.SH SYNTAX
+.Ed
+.Sh SYNTAX
Templates use Go's text/template syntax:
-.TP
-.B {{.field}}
+.Bl -tag -width Ds
+.It Li {{.field}}
Output a field value.
-.TP
-.B {{range .items}}...{{end}}
+.It Li {{range .items}}...{{end}}
Iterate over a list.
-.TP
-.B {{if .condition}}...{{end}}
+.It Li {{if .condition}}...{{end}}
Conditional rendering.
-.TP
-.B {{with .object}}...{{end}}
+.It Li {{with .object}}...{{end}}
Set dot to the object for the block.
-.PP
+.El
+.Pp
See the Go
-.B html/template
+.Lk https://pkg.go.dev/html/template html/template
documentation for full syntax details.
-.SH FILES
-.TP
-.I data/*.json
-JSON data files. Each becomes a template variable.
-.TP
-.I templates/*.html
+.Sh FUNCTIONS
+In addition to Go's built-in template functions, the following
+functions are available.
+.Pp
+All examples use data from
+.Sx DATA .
+.Ss filter
+.Bd -literal
+filter <array> <field> <value>
+.Ed
+.Pp
+Returns items from an array where a field equals a value.
+.Bd -literal -offset indent
+{{range filter .projects "featured" true}}
+ <li>{{.name}}</li>
+{{end}}
+.Ed
+.Pp
+This would output only "foo" since it has
+.Va featured
+set to
+.Li true .
+.Sh FILES
+.Bl -tag -width Ds
+.It Pa templates/*.html
HTML templates to render.
-.SH SEE ALSO
-.BR ssg (1),
-.BR ssg-build (1)
+.It Pa data/*.json
+JSON data files. Each becomes a template variable.
+.El
+.Sh SEE ALSO
+.Xr ssg 1 ,
+.Xr ssg-build 1