Add hugo.Deps

Fixes #8949
This commit is contained in:
Bjørn Erik Pedersen
2022-01-11 15:07:04 +01:00
parent d82cef5c53
commit 7396aa945a
6 changed files with 130 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ import (
"time"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/modules"
"golang.org/x/text/unicode/norm"
"github.com/gohugoio/hugo/common/paths"
@@ -1333,6 +1334,32 @@ func (s *Site) initializeSiteInfo() error {
}
}
// Assemble dependencies to be used in hugo.Deps.
// TODO(bep) another reminder: We need to clean up this Site vs HugoSites construct.
var deps []*hugo.Dependency
var depFromMod func(m modules.Module) *hugo.Dependency
depFromMod = func(m modules.Module) *hugo.Dependency {
dep := &hugo.Dependency{
Path: m.Path(),
Version: m.Version(),
Time: m.Time(),
Vendor: m.Vendor(),
}
// These are pointers, but this all came from JSON so there's no recursive navigation,
// so just create new values.
if m.Replace() != nil {
dep.Replace = depFromMod(m.Replace())
}
if m.Owner() != nil {
dep.Owner = depFromMod(m.Owner())
}
return dep
}
for _, m := range s.Paths.AllModules {
deps = append(deps, depFromMod(m))
}
s.Info = &SiteInfo{
title: lang.GetString("title"),
Author: lang.GetStringMap("author"),
@@ -1351,7 +1378,7 @@ func (s *Site) initializeSiteInfo() error {
permalinks: permalinks,
owner: s.h,
s: s,
hugoInfo: hugo.NewInfo(s.Cfg.GetString("environment")),
hugoInfo: hugo.NewInfo(s.Cfg.GetString("environment"), deps),
}
rssOutputFormat, found := s.outputFormats[page.KindHome].GetByName(output.RSSFormat.Name)