mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
Rename Path fields to Permalink
This commit is contained in:
parent
c4a282eba7
commit
78e5bf51c6
|
@ -5,7 +5,7 @@ urls = ["gemini://example.com"]
|
|||
"/" = "Example feed"
|
||||
|
||||
[permalinks]
|
||||
"/" = '/{{ .Date.Format "2006/01/02" }}/{{ path.Base .Path }}/'
|
||||
"/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Permalink }}/"
|
||||
|
||||
[[tasks]]
|
||||
input = [".gmi"]
|
||||
|
|
34
dir.go
34
dir.go
|
@ -18,7 +18,7 @@ import (
|
|||
|
||||
// Dir represents a directory.
|
||||
type Dir struct {
|
||||
Path string
|
||||
Permalink string
|
||||
Pages []*Page
|
||||
Dirs []*Dir
|
||||
index *Page // The index page.
|
||||
|
@ -30,7 +30,7 @@ type Page struct {
|
|||
Title string
|
||||
Date time.Time
|
||||
Weight int
|
||||
Path string `yaml:"-"`
|
||||
Permalink string `yaml:"-"`
|
||||
FilePath string `yaml:"-"`
|
||||
Content string `yaml:"-"`
|
||||
Params map[string]interface{}
|
||||
|
@ -57,7 +57,7 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error {
|
|||
continue
|
||||
}
|
||||
// Gather directory data
|
||||
dir := &Dir{Path: "/" + path + "/"}
|
||||
dir := &Dir{Permalink: "/" + path + "/"}
|
||||
if err := dir._read(srcDir, path, task, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error {
|
|||
page.FilePath = path
|
||||
|
||||
if namePrefix == "_index" {
|
||||
page.Path = d.Path
|
||||
page.Permalink = d.Permalink
|
||||
d.index = page
|
||||
} else {
|
||||
if namePrefix == "index" {
|
||||
|
@ -134,11 +134,11 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Site) error {
|
|||
path += "/"
|
||||
}
|
||||
}
|
||||
page.Path = path
|
||||
if permalink, ok := cfg.permalinks[d.Path]; ok {
|
||||
page.Permalink = path
|
||||
if permalink, ok := cfg.permalinks[d.Permalink]; ok {
|
||||
var b strings.Builder
|
||||
permalink.Execute(&b, page)
|
||||
page.Path = b.String()
|
||||
page.Permalink = b.String()
|
||||
}
|
||||
d.Pages = append(d.Pages, page)
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func (d *Dir) process(cfg *Site, task *Task) error {
|
|||
if task.TemplateExt != "" {
|
||||
// Create index
|
||||
if d.index != nil {
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Path, "index"+task.TemplateExt)
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "index"+task.TemplateExt)
|
||||
if ok {
|
||||
var b strings.Builder
|
||||
if err := tmpl.Execute(&b, d); err != nil {
|
||||
|
@ -165,7 +165,7 @@ func (d *Dir) process(cfg *Site, task *Task) error {
|
|||
// Process pages
|
||||
for i := range d.Pages {
|
||||
var b strings.Builder
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Path, "page"+task.TemplateExt)
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "page"+task.TemplateExt)
|
||||
if ok {
|
||||
if err := tmpl.Execute(&b, d.Pages[i]); err != nil {
|
||||
return err
|
||||
|
@ -178,21 +178,21 @@ func (d *Dir) process(cfg *Site, task *Task) error {
|
|||
// Feed represents a feed.
|
||||
type Feed struct {
|
||||
Title string // Feed title.
|
||||
Path string // Feed path.
|
||||
Permalink string // Feed permalink.
|
||||
Updated time.Time // Last updated time.
|
||||
Entries []*Page // Feed entries.
|
||||
}
|
||||
|
||||
// Create feeds
|
||||
if title, ok := cfg.Feeds[d.Path]; ok {
|
||||
if title, ok := cfg.Feeds[d.Permalink]; ok {
|
||||
var b bytes.Buffer
|
||||
feed := &Feed{
|
||||
Title: title,
|
||||
Path: d.Path,
|
||||
Permalink: d.Permalink,
|
||||
Updated: time.Now(),
|
||||
Entries: d.Pages,
|
||||
}
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Path, "atom.xml")
|
||||
tmpl, ok := cfg.templates.FindTemplate(d.Permalink, "atom.xml")
|
||||
if ok {
|
||||
if err := tmpl.Execute(&b, feed); err != nil {
|
||||
return err
|
||||
|
@ -214,7 +214,7 @@ func (d *Dir) process(cfg *Site, task *Task) error {
|
|||
|
||||
// write writes the directory's contents to the provided destination path.
|
||||
func (d *Dir) write(dstDir string, task *Task) error {
|
||||
dirPath := pathpkg.Join(dstDir, d.Path)
|
||||
dirPath := pathpkg.Join(dstDir, d.Permalink)
|
||||
|
||||
// Write pages
|
||||
pages := d.Pages
|
||||
|
@ -222,7 +222,7 @@ func (d *Dir) write(dstDir string, task *Task) error {
|
|||
pages = append(pages, d.index)
|
||||
}
|
||||
for _, page := range pages {
|
||||
path := page.Path
|
||||
path := page.Permalink
|
||||
if !task.UglyURLs || page == d.index {
|
||||
path = pathpkg.Join(path, "index"+task.OutputExt)
|
||||
}
|
||||
|
@ -321,11 +321,11 @@ func (d *Dir) Params() map[string]interface{} {
|
|||
|
||||
func (d *Dir) getDir(path string) *Dir {
|
||||
// XXX: This is inefficient
|
||||
if d.Path == path {
|
||||
if d.Permalink == path {
|
||||
return d
|
||||
}
|
||||
for _, dir := range d.Dirs {
|
||||
if dir.Path == path {
|
||||
if dir.Permalink == path {
|
||||
return dir
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ content/blog/2021-05-12-hello-world.gmi will have a path of
|
|||
|
||||
```
|
||||
[permalinks]
|
||||
"/blog/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Path }}"
|
||||
"/blog/" = "/{{ .Date.Format `2006/01/02` }}/{{ path.Base .Permalink }}"
|
||||
```
|
||||
|
||||
For more information on templates, see *TEMPLATES*.
|
||||
|
@ -627,8 +627,8 @@ Page templates are provided with the following data:
|
|||
: The title of the page
|
||||
| Date
|
||||
: The date of the page
|
||||
| Path
|
||||
: Path to the page
|
||||
| Permalink
|
||||
: The permanent link to this page
|
||||
| Content
|
||||
: The contents of the page
|
||||
| Params
|
||||
|
@ -654,8 +654,8 @@ Feed templates are provided with the following data:
|
|||
:[ *Description*
|
||||
| Title
|
||||
: Title of the feed
|
||||
| Path
|
||||
: Path to the feed directory
|
||||
| Permalink
|
||||
: The permanent link to the feed directory
|
||||
| Entries
|
||||
: List of pages in this feed
|
||||
|
||||
|
|
2
main.go
2
main.go
|
@ -71,7 +71,7 @@ func (site *Site) run() error {
|
|||
|
||||
func (s *Site) runTask(task *Task) error {
|
||||
// Read content
|
||||
s.root = &Dir{Path: "/"}
|
||||
s.root = &Dir{Permalink: "/"}
|
||||
if err := s.root.read("content", task, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
{{ `<?xml version="1.0" encoding="utf-8"?>` | safeHTML }}
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<id>{{ index site.URLs 0 }}{{ .Path }}</id>
|
||||
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
||||
<title>{{ .Title }}</title>
|
||||
<updated>{{ .Updated.Format "2006-01-02T15:04:05Z07:00" }}</updated>
|
||||
<link href="{{ index site.URLs 0 | safeURL }}{{ .Path }}" rel="alternate"/>
|
||||
<link href="{{ index site.URLs 0 | safeURL }}{{ .Permalink }}" rel="alternate"/>
|
||||
{{ range .Entries }}<entry>
|
||||
<id>{{ index site.URLs 0 }}{{ .Path }}</id>
|
||||
<id>{{ index site.URLs 0 }}{{ .Permalink }}</id>
|
||||
<title>{{ .Title }}</title>
|
||||
<updated>{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}</updated>
|
||||
{{- $path := .Path }}
|
||||
{{- $permalink := .Permalink }}
|
||||
{{- range site.URLs }}
|
||||
<link href="{{ . | safeURL }}{{ $path }}" rel="alternate"/>
|
||||
<link href="{{ . | safeURL }}{{ $permalink }}" rel="alternate"/>
|
||||
{{- end }}
|
||||
</entry>
|
||||
{{ end -}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# {{ .Title }}
|
||||
{{ if .Content }}
|
||||
{{ .Content }}{{ end }}
|
||||
{{ range .Pages }}=> {{ .Path }} {{ if not .Date.IsZero -}}
|
||||
{{ range .Pages }}=> {{ .Permalink }} {{ if not .Date.IsZero -}}
|
||||
{{.Date.Format "2006-01-02"}} {{end}}{{.Title}}
|
||||
{{ end -}}
|
||||
|
|
Loading…
Reference in a new issue