@@ 20,6 20,7 @@ require (
require (
github.com/BurntSushi/toml v1.2.0 // indirect
github.com/PuerkitoBio/goquery v1.8.0 // indirect
+ github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
@@ 7,6 7,8 @@ github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0g
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
github.com/adrg/frontmatter v0.2.0 h1:/DgnNe82o03riBd1S+ZDjd43wAmC6W35q67NHeLkPd4=
github.com/adrg/frontmatter v0.2.0/go.mod h1:93rQCj3z3ZlwyxxpQioRKC1wDLto4aXHrbqIsnH9wmE=
+github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 h1:HnuAxArB0uUxqjRvZdjhBxE3uPXNeJvNNbuaV4QhHMU=
+github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81/go.mod h1:jk5mJ+KFznfxbCEsOPgmJkozvBfVGeaqIMs31NhXlv0=
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
@@ 13,6 13,7 @@ import (
"git.sr.ht/~artemis/cap/parsing"
"git.sr.ht/~artemis/cap/util"
"github.com/adrg/frontmatter"
+ "github.com/akrennmair/slice"
"github.com/go-playground/validator"
"github.com/pelletier/go-toml/v2"
)
@@ 127,17 128,56 @@ func ListFiles(root string, idx *domain.Index, opts *FileListOpts) (domain.Secti
page.RelativePath = relativeToRoot
idx.Files[path] = domain.ObjectTypePage
- if util.Includes(info.Name(), "index.gmi", "index.md") {
+ if util.Includes(info.Name(), "index.gmi", "index.md", "index.html") {
if page.Template == "" {
page.Template = "section"
}
- currentSection.Page = page
+
+ if currentSection.Page != nil {
+ // If the found page isn't gemini
+ if page.Format != domain.FileFormatGemini {
+ // If the current section's page is already defined and we encounter a new page that is not gemini
+ if currentSection.Page.Format == domain.FileFormatGemini {
+ // If the curent section's page is gemini-formatted, replace it with the newly found one
+ currentSection.Page = page
+ } else {
+ // Else, there are two non-gemini index pages, warn and ignore
+ domain.L.Warnf("Two non-gemini index pages were found; this creates a conflict. %s is retained, %s is ignored", currentSection.Page.RelativePath, page.RelativePath)
+ }
+ }
+ } else {
+ currentSection.Page = page
+ }
} else {
if page.Template == "" {
page.Template = "page"
}
- currentSection.Pages = append(currentSection.Pages, page)
+ // If there is already a page with the same permalink,
+ var foundPage *domain.Page
+ if maybePages := slice.Filter(
+ currentSection.Pages,
+ func(p *domain.Page) bool {
+ matched := p.Permalink == page.Permalink
+ if matched && foundPage == nil {
+ foundPage = p
+ }
+ return !matched
+ },
+ ); len(maybePages) < len(currentSection.Pages) {
+ // If the new page isn't gemini
+ if page.Format != domain.FileFormatGemini {
+ if foundPage.Format == domain.FileFormatGemini {
+ // If the found page is gemini-formatted, replace it with the newly found one
+ currentSection.Pages = append(maybePages, page)
+ } else {
+ // Else, there are two non-gemini pages, warn and ignore
+ domain.L.Warnf("Two non-gemini pages were found; this creates a conflict. %s is retained, %s is ignored", foundPage.RelativePath, page.RelativePath)
+ }
+ }
+ } else {
+ currentSection.Pages = append(currentSection.Pages, page)
+ }
}
// If we should also copy the original files (for gemini, and ...)