mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00: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 {
|
for _, entry := range entries {
|
||||||
name := entry.Name()
|
name := entry.Name()
|
||||||
// Ignore names that start with "_"
|
|
||||||
if strings.HasPrefix(name, "_") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
path := pathpkg.Join(path, name)
|
path := pathpkg.Join(path, name)
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
|
// Ignore directories beginning with "_"
|
||||||
|
if strings.HasPrefix(name, "_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Gather directory data
|
// Gather directory data
|
||||||
dir := NewDir(path)
|
dir := NewDir(path)
|
||||||
if err := dir._read(srcDir, path, task, cfg); err != nil {
|
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)
|
d.Dirs = append(d.Dirs, dir)
|
||||||
} else if ext := pathpkg.Ext(name); task.Match(ext) {
|
} 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)
|
srcPath := pathpkg.Join(srcDir, path)
|
||||||
content, err := ioutil.ReadFile(srcPath)
|
content, err := ioutil.ReadFile(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -122,11 +128,15 @@ func (d *Dir) _read(srcDir, path string, task *Task, cfg *Config) error {
|
||||||
}
|
}
|
||||||
page.Content = string(content)
|
page.Content = string(content)
|
||||||
|
|
||||||
if strings.TrimSuffix(name, ext) == "index" {
|
if namePrefix == "_index" {
|
||||||
page.Path = d.Path
|
page.Path = d.Path
|
||||||
d.index = page
|
d.index = page
|
||||||
} else {
|
} else {
|
||||||
path = "/" + strings.TrimSuffix(path, ext)
|
if namePrefix == "index" {
|
||||||
|
path = "/" + strings.TrimSuffix(path, name)
|
||||||
|
} else {
|
||||||
|
path = "/" + strings.TrimSuffix(path, ext)
|
||||||
|
}
|
||||||
if task.UglyURLs {
|
if task.UglyURLs {
|
||||||
path += task.OutputExt
|
path += task.OutputExt
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue