Add aliases support

This commit is contained in:
mzietlow 2023-03-19 10:57:58 +01:00
parent a7bc6ab3db
commit e9e83ce393
2 changed files with 9 additions and 0 deletions

View File

@ -35,6 +35,7 @@ type Content struct {
Content string `json:"content"` Content string `json:"content"`
LastModified time.Time `json:"lastmodified"` LastModified time.Time `json:"lastmodified"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Aliases []string `json:"aliases"`
} }
type ContentIndex = map[string]Content type ContentIndex = map[string]Content

View File

@ -17,6 +17,7 @@ type Front struct {
Title string `yaml:"title"` Title string `yaml:"title"`
Draft bool `yaml:"draft"` Draft bool `yaml:"draft"`
Tags []string `yaml:"tags"` Tags []string `yaml:"tags"`
Aliases []string `yaml:"aliases"`
} }
// recursively walk directory and return all files with given extension // recursively walk directory and return all files with given extension
@ -54,6 +55,7 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res []
Title: "Untitled Page", Title: "Untitled Page",
Draft: false, Draft: false,
Tags: []string{}, Tags: []string{},
Aliases: []string{},
} }
body = text body = text
} }
@ -74,12 +76,18 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res []
matter.Tags = []string{} matter.Tags = []string{}
} }
// default aliases
if matter.Aliases == nil {
matter.Aliases = []string{}
}
// add to content and link index // add to content and link index
i[source] = Content{ i[source] = Content{
LastModified: info.ModTime(), LastModified: info.ModTime(),
Title: title, Title: title,
Content: body, Content: body,
Tags: matter.Tags, Tags: matter.Tags,
Aliases: matter.Aliases,
} }
res = append(res, parse(s, root)...) res = append(res, parse(s, root)...)
} else { } else {