diff --git a/cmd/eagle/broken-links.go b/cmd/eagle/broken-links.go index 83f2c057..4a7f95a7 100644 --- a/cmd/eagle/broken-links.go +++ b/cmd/eagle/broken-links.go @@ -66,11 +66,10 @@ var brokenLinksCmd = &cobra.Command{ parts := strings.Split(u.Path, "/") if len(parts) == 5 { - for _, section := range core.Sections { - _, err = fs.GetEntry("/" + section + "/" + parts[1] + "/" + parts[4]) - if err == nil { - return false, "", nil - } + // TODO: handle other permalinks (such as categories). + _, err = fs.GetEntry("/" + core.SpecialSection + "/" + parts[1] + "/" + parts[4]) + if err == nil { + return false, "", nil } } diff --git a/core/parser.go b/core/parser.go index d7dbb891..863b7373 100644 --- a/core/parser.go +++ b/core/parser.go @@ -6,12 +6,13 @@ import ( urlpkg "net/url" "strings" - "github.com/samber/lo" yaml "gopkg.in/yaml.v3" ) -// TODO: do not hardcode these. -var Sections = []string{"articles", "photos", "readings", "photos"} +// TODO: do not hardcore this. Instead, use Hugo's configuration to deduce +// and "back-engineer" how the permalinks are constructed. Then this can be used +// only in the parser code. +const SpecialSection = "posts" type Parser struct { baseURL string @@ -69,7 +70,7 @@ func (p *Parser) makePermalink(id string, fr *FrontMatter) (string, error) { } parts := strings.Split(id, "/") - if lo.Contains(Sections, parts[1]) && !fr.Date.IsZero() { + if parts[1] == SpecialSection && !fr.Date.IsZero() { url.Path = fmt.Sprintf("/%04d/%02d/%02d/%s/", fr.Date.Year(), fr.Date.Month(), fr.Date.Day(), parts[len(parts)-2]) } else { url.Path = id