mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-11-08 14:19:20 +01:00
Use _index for index pages
Pages with the name "index" will use the page template, and pages with the name "_index" will use the index template.
This commit is contained in:
parent
5fc28c9b78
commit
540181648b
22
dir.go
22
dir.go
@ -60,12 +60,12 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error {
|
||||
}
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
// Ignore names that start with "_"
|
||||
if strings.HasPrefix(name, "_") {
|
||||
continue
|
||||
}
|
||||
path := pathpkg.Join(path, name)
|
||||
if entry.IsDir() {
|
||||
// Ignore directories beginning with "_"
|
||||
if strings.HasPrefix(name, "_") {
|
||||
continue
|
||||
}
|
||||
// Gather directory data
|
||||
dir := NewDir(path)
|
||||
if err := dir._read(srcDir, path, task, cfg); err != nil {
|
||||
@ -73,6 +73,12 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error {
|
||||
}
|
||||
d.Dirs = append(d.Dirs, dir)
|
||||
} else if ext := pathpkg.Ext(name); task.Match(ext) {
|
||||
// Ignore pages beginning with "_" with the exception of _index pages
|
||||
namePrefix := strings.TrimSuffix(name, ext)
|
||||
if strings.HasPrefix(name, "_") && namePrefix != "_index" {
|
||||
continue
|
||||
}
|
||||
|
||||
srcPath := pathpkg.Join(srcDir, path)
|
||||
content, err := ioutil.ReadFile(srcPath)
|
||||
if err != nil {
|
||||
@ -122,11 +128,15 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error {
|
||||
}
|
||||
page.Content = string(content)
|
||||
|
||||
if strings.TrimSuffix(name, ext) == "index" {
|
||||
if namePrefix == "_index" {
|
||||
page.Path = d.Path
|
||||
d.index = page
|
||||
} else {
|
||||
path = "/" + strings.TrimSuffix(path, ext)
|
||||
if namePrefix == "index" {
|
||||
path = "/" + strings.TrimSuffix(path, name)
|
||||
} else {
|
||||
path = "/" + strings.TrimSuffix(path, ext)
|
||||
}
|
||||
if task.UglyURLs {
|
||||
path += task.OutputExt
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user