Skip to content

Commit e402d91

Browse files
committed
Misc doc, code refactoring to improve documentation
1 parent 3c51625 commit e402d91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+238
-95
lines changed

codegen/methods.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,16 @@ func collectMethodsRecursive(pkg string, f []*ast.Field) []string {
452452
}
453453

454454
if ident, ok := m.Type.(*ast.Ident); ok && ident.Obj != nil {
455-
// Embedded interface
456-
methodNames = append(
457-
methodNames,
458-
collectMethodsRecursive(
459-
pkg,
460-
ident.Obj.Decl.(*ast.TypeSpec).Type.(*ast.InterfaceType).Methods.List)...)
455+
switch tt := ident.Obj.Decl.(*ast.TypeSpec).Type.(type) {
456+
case *ast.InterfaceType:
457+
// Embedded interface
458+
methodNames = append(
459+
methodNames,
460+
collectMethodsRecursive(
461+
pkg,
462+
tt.Methods.List)...)
463+
}
464+
461465
} else {
462466
// Embedded, but in a different file/package. Return the
463467
// package.Name and deal with that later.

commands/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ type modMount struct {
126126
Lang string `json:"lang,omitempty"`
127127
}
128128

129+
// MarshalJSON is for internal use only.
129130
func (m *modMounts) MarshalJSON() ([]byte, error) {
130131
var mounts []modMount
131132

common/docs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package common provides common helper functionality for Hugo.
2+
package common

common/maps/scratch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Scratch struct {
3030

3131
// Scratcher provides a scratching service.
3232
type Scratcher interface {
33+
// Scratch returns a "scratch pad" that can be used to store state.
3334
Scratch() *Scratch
3435
}
3536

common/paths/path.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,14 @@ func (n NamedSlice) String() string {
263263
}
264264
return fmt.Sprintf("%s%s{%s}", n.Name, FilePathSeparator, strings.Join(n.Slice, ","))
265265
}
266+
267+
// DirFile holds the result from path.Split.
268+
type DirFile struct {
269+
Dir string
270+
File string
271+
}
272+
273+
// Used in test.
274+
func (df DirFile) String() string {
275+
return fmt.Sprintf("%s|%s", df.Dir, df.File)
276+
}

common/text/position.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
// Positioner represents a thing that knows its position in a text file or stream,
2525
// typically an error.
2626
type Positioner interface {
27+
// Position returns the current position.
28+
// Useful in error logging, e.g. {{ errorf "error in code block: %s" .Position }}.
2729
Position() Position
2830
}
2931

config/security/whitelist.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Whitelist struct {
3333
patternsStrings []string
3434
}
3535

36+
// MarshalJSON is for internal use only.
3637
func (w Whitelist) MarshalJSON() ([]byte, error) {
3738
if w.acceptNone {
3839
return json.Marshal(acceptNoneKeyword)

hugofs/fileinfo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (f *FileMeta) JoinStat(name string) (FileMetaInfo, error) {
130130

131131
type FileMetaInfo interface {
132132
os.FileInfo
133+
// Meta is for internal use.
133134
Meta() *FileMeta
134135
}
135136

hugolib/content_map_page.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (m *pageMap) newResource(fim hugofs.FileMetaInfo, owner *pageState) (resour
266266
}
267267

268268
func (m *pageMap) createSiteTaxonomies() error {
269-
m.s.taxonomies = make(TaxonomyList)
269+
m.s.taxonomies = make(page.TaxonomyList)
270270
var walkErr error
271271
m.taxonomies.Walk(func(s string, v any) bool {
272272
n := v.(*contentNode)
@@ -275,7 +275,7 @@ func (m *pageMap) createSiteTaxonomies() error {
275275
viewName := t.name
276276

277277
if t.termKey == "" {
278-
m.s.taxonomies[viewName.plural] = make(Taxonomy)
278+
m.s.taxonomies[viewName.plural] = make(page.Taxonomy)
279279
} else {
280280
taxonomy := m.s.taxonomies[viewName.plural]
281281
if taxonomy == nil {
@@ -285,7 +285,7 @@ func (m *pageMap) createSiteTaxonomies() error {
285285
m.taxonomyEntries.WalkPrefix(s, func(ss string, v any) bool {
286286
b2 := v.(*contentNode)
287287
info := b2.viewInfo
288-
taxonomy.add(info.termKey, page.NewWeightedPage(info.weight, info.ref.p, n.p))
288+
taxonomy[info.termKey] = append(taxonomy[info.termKey], page.NewWeightedPage(info.weight, info.ref.p, n.p))
289289

290290
return false
291291
})

hugolib/gitinfo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@ import (
2020
"github.com/bep/gitmap"
2121
"github.com/gohugoio/hugo/config"
2222
"github.com/gohugoio/hugo/resources/page"
23+
"github.com/gohugoio/hugo/source"
2324
)
2425

2526
type gitInfo struct {
2627
contentDir string
2728
repo *gitmap.GitRepo
2829
}
2930

30-
func (g *gitInfo) forPage(p page.Page) *gitmap.GitInfo {
31+
func (g *gitInfo) forPage(p page.Page) source.GitInfo {
3132
name := strings.TrimPrefix(filepath.ToSlash(p.File().Filename()), g.contentDir)
3233
name = strings.TrimPrefix(name, "/")
33-
34-
return g.repo.Files[name]
34+
gi, found := g.repo.Files[name]
35+
if !found {
36+
return source.GitInfo{}
37+
}
38+
return source.NewGitInfo(*gi)
3539
}
3640

3741
func newGitInfo(cfg config.Provider) (*gitInfo, error) {

0 commit comments

Comments
 (0)