Skip to content

Commit

Permalink
parser: glue tape for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Nov 17, 2023
1 parent e65d8b4 commit 799ba83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 4 additions & 5 deletions cmd/eagle/broken-links.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
9 changes: 5 additions & 4 deletions core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 799ba83

Please sign in to comment.