cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
cmd.Flags().BoolP("ignoreCache", "", false, "ignores the cache directory")
cmd.Flags().Bool("enableGitInfo", false, "add Git revision, date, author, and CODEOWNERS info to the pages")
+ cmd.Flags().Bool("enableGitPurismInfo", false, "grab meta (tags, categories) from Git notes")
cmd.Flags().StringP("layoutDir", "l", "", "filesystem path to layout directory")
_ = cmd.MarkFlagDirname("layoutDir")
cmd.Flags().BoolVar(&r.gc, "gc", false, "enable to run some cleanup tasks (remove unused cache files) after the build")
// <docsmeta>{"identifiers": ["Page"] }</docsmeta>
EnableGitInfo bool
+ // When enabled, Hugo will attempt to grab tags and categories from Git notes.
+ // <docsmeta>{"identifiers": ["Page"] }</docsmeta>
+ EnableGitPurismInfo bool
+
// Enable to track, calculate and print metrics.
TemplateMetrics bool
markdownTitleInfo *markdownTitleInfo
+ gitPurismInfo *gitPurismInfo
+
// As loaded from the /data dirs
data map[string]any
gitInfo hsync.FuncResetter
markdownTitleInfo hsync.FuncResetter
+
+ gitPurismInfo hsync.FuncResetter
}
func (h *HugoSites) Data() map[string]any {
return h.markdownTitleInfo.forPage(p), nil
}
+func (h *HugoSites) gitPurismInfoForPage(p page.Page) (*GitPurismInfo, error) {
+ if err := h.init.gitPurismInfo.Do(context.Background()); err != nil {
+ return nil, err
+ }
+
+ if h.gitPurismInfo == nil {
+ return nil, nil
+ }
+
+ return h.gitPurismInfo.forPage(p), nil
+}
+
func (h *HugoSites) reportProgress(f func() (state terminal.ProgressState, progress float64)) {
h.progressReporter.mu.Lock()
defer h.progressReporter.mu.Unlock()
func (h *HugoSites) loadMarkdownTitleInfo() error {
// TODO: Make it configurable
// if h.Configs.Base.EnableMarkdownTitle {
- // cfg := gitInfoConfig{
- // Deps: h.Deps,
- // Modules: h.Configs.Modules,
- // GitInfoCache: h.Configs.FileCaches.ModuleGitInfoCache(),
- // Logger: h.Log,
- // }
mt, err := newMarkdownTitleInfo(h.Deps.Conf.DirsBase().ContentDir)
if err != nil {
return err
return nil
}
+func (h *HugoSites) loadGitPurismInfo() error {
+ if h.Configs.Base.EnableGitPurismInfo {
+ gpi, err := newGitPurismInfo(h.Deps.Conf.DirsBase().ContentDir)
+ if err != nil {
+ return err
+ } else {
+ h.gitPurismInfo = gpi
+ }
+ }
+ return nil
+}
+
// Reset resets the sites and template caches etc., making it ready for a full rebuild.
func (h *HugoSites) reset() {
h.fatalErrorHandler = &fatalErrorHandler{
return p.markdownTitleInfo
}
+func (p *pageState) GitPurismInfo() *GitPurismInfo {
+ return p.gitPurismInfo
+}
+
// GetTerms gets the terms defined on this page in the given taxonomy.
// The pages returned will be ordered according to the front matter.
func (ps *pageState) GetTerms(taxonomy string) page.Pages {
codeowners []string
markdownTitleInfo *MarkdownTitleInfo
+ gitPurismInfo *GitPurismInfo
// Positional navigation
posNextPrev *nextPrev
}
}
+ if ps.gitPurismInfo != nil {
+ if len(ps.gitPurismInfo.Categories) > 0 {
+ if existing, ok := pcfg.Params["categories"]; ok {
+ switch v := existing.(type) {
+ case []string:
+ pcfg.Params["categories"] = append(v, ps.gitPurismInfo.Categories...)
+ case []interface{}:
+ existingStrings := make([]string, 0, len(v))
+ for _, iv := range v {
+ if s, ok := iv.(string); ok {
+ existingStrings = append(existingStrings, s)
+ }
+ }
+ pcfg.Params["categories"] = append(existingStrings, ps.gitPurismInfo.Categories...)
+ default:
+ pcfg.Params["categories"] = ps.gitPurismInfo.Categories
+ }
+ } else {
+ pcfg.Params["categories"] = ps.gitPurismInfo.Categories
+ }
+ }
+
+ if len(ps.gitPurismInfo.Tags) > 0 {
+ if existing, ok := pcfg.Params["tags"]; ok {
+ switch v := existing.(type) {
+ case []string:
+ pcfg.Params["tags"] = append(v, ps.gitPurismInfo.Tags...)
+ case []interface{}:
+ existingStrings := make([]string, 0, len(v))
+ for _, iv := range v {
+ if s, ok := iv.(string); ok {
+ existingStrings = append(existingStrings, s)
+ }
+ }
+ pcfg.Params["tags"] = append(existingStrings, ps.gitPurismInfo.Tags...)
+ default:
+ pcfg.Params["tags"] = ps.gitPurismInfo.Tags
+ }
+ } else {
+ pcfg.Params["tags"] = ps.gitPurismInfo.Tags
+ }
+ }
+ }
+
for k, v := range userParams {
pcfg.Params[strings.ToLower(k)] = v
}
return nil, fmt.Errorf("failed to load MarkdownTitle data: %w", err)
}
ps.markdownTitleInfo = mt
+
+ gpi, err := s.h.gitPurismInfoForPage(ps)
+ if err != nil {
+ return nil, fmt.Errorf("failed to load GitPurism data: %w", err)
+
+ }
+ ps.gitPurismInfo = gpi
}
ps.pageMenus = &pageMenus{p: ps}
return h.loadMarkdownTitleInfo()
})
+ h.init.gitPurismInfo = hsync.OnceMoreFunc(func(ctx context.Context) error {
+ return h.loadGitPurismInfo()
+ })
return h, nil
}