]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Misc doc, code refactoring to improve documentation
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 30 Dec 2022 08:20:58 +0000 (09:20 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 4 Jan 2023 17:01:26 +0000 (18:01 +0100)
48 files changed:
codegen/methods.go
commands/config.go
common/docs.go [new file with mode: 0644]
common/maps/scratch.go
common/paths/path.go
common/text/position.go
config/security/whitelist.go
hugofs/fileinfo.go
hugolib/content_map_page.go
hugolib/gitinfo.go
hugolib/hugo_sites.go
hugolib/page.go
hugolib/page__common.go
hugolib/page__meta.go
hugolib/site.go
hugolib/taxonomy.go [deleted file]
langs/language.go
markup/converter/hooks/hooks.go
markup/highlight/highlight.go
markup/markup.go
media/mediaType.go
navigation/menu.go
navigation/menu_cache.go
output/outputFormat.go
resources/docs.go [new file with mode: 0644]
resources/images/exif/exif.go
resources/images/image_resource.go
resources/page/page.go
resources/page/page_marshaljson.autogen.go
resources/page/page_nop.go
resources/page/pagination.go
resources/page/site.go
resources/page/taxonomy.go [new file with mode: 0644]
resources/page/testhelpers_test.go
resources/resource/resources.go
resources/resource/resourcetypes.go
source/fileInfo.go
source/sourceSpec.go
tpl/diagrams/init.go
tpl/images/images.go
tpl/openapi/docs.go [new file with mode: 0644]
tpl/openapi/openapi3/openapi3.go
tpl/os/os_test.go
tpl/path/path.go
tpl/path/path_test.go
tpl/resources/resources.go
tpl/strings/truncate.go
tpl/template.go

index 9bc80cc3e25b9fa3d3953640ff66a0ec08314a33..65a7cc2b7520ab5e41ae898ca49e34b3a6c85957 100644 (file)
@@ -452,12 +452,16 @@ func collectMethodsRecursive(pkg string, f []*ast.Field) []string {
                }
 
                if ident, ok := m.Type.(*ast.Ident); ok && ident.Obj != nil {
-                       // Embedded interface
-                       methodNames = append(
-                               methodNames,
-                               collectMethodsRecursive(
-                                       pkg,
-                                       ident.Obj.Decl.(*ast.TypeSpec).Type.(*ast.InterfaceType).Methods.List)...)
+                       switch tt := ident.Obj.Decl.(*ast.TypeSpec).Type.(type) {
+                       case *ast.InterfaceType:
+                               // Embedded interface
+                               methodNames = append(
+                                       methodNames,
+                                       collectMethodsRecursive(
+                                               pkg,
+                                               tt.Methods.List)...)
+                       }
+
                } else {
                        // Embedded, but in a different file/package. Return the
                        // package.Name and deal with that later.
index 7fda2d40e97f6dd97ed24cc21b60f876b4bff519..a5d8aab22fee8fda8e708536815c1d62ca934c81 100644 (file)
@@ -126,6 +126,7 @@ type modMount struct {
        Lang   string `json:"lang,omitempty"`
 }
 
+// MarshalJSON is for internal use only.
 func (m *modMounts) MarshalJSON() ([]byte, error) {
        var mounts []modMount
 
diff --git a/common/docs.go b/common/docs.go
new file mode 100644 (file)
index 0000000..041a62a
--- /dev/null
@@ -0,0 +1,2 @@
+// Package common provides common helper functionality for Hugo.
+package common
index d4745d27c3b2b3dab5741400343db106d3ce0bbe..e9f412540b29e30979a1b860377707071f953166 100644 (file)
@@ -30,6 +30,7 @@ type Scratch struct {
 
 // Scratcher provides a scratching service.
 type Scratcher interface {
+       // Scratch returns a "scratch pad" that can be used to store state.
        Scratch() *Scratch
 }
 
index 3a7f3e7908a6a8bb2baf4a46e846090e93b6c095..11d221bb153ff94d03118f0247b1d464844c1b13 100644 (file)
@@ -263,3 +263,14 @@ func (n NamedSlice) String() string {
        }
        return fmt.Sprintf("%s%s{%s}", n.Name, FilePathSeparator, strings.Join(n.Slice, ","))
 }
+
+// DirFile holds the result from path.Split.
+type DirFile struct {
+       Dir  string
+       File string
+}
+
+// Used in test.
+func (df DirFile) String() string {
+       return fmt.Sprintf("%s|%s", df.Dir, df.File)
+}
index cc1eda3540a9bafcdc1f6bbf1c8aee5e502ff1ec..eb9de5624ef46a4db8d9ae0eb486a2558a05ec75 100644 (file)
@@ -24,6 +24,8 @@ import (
 // Positioner represents a thing that knows its position in a text file or stream,
 // typically an error.
 type Positioner interface {
+       // Position returns the current position.
+       // Useful in error logging, e.g. {{ errorf "error in code block: %s" .Position }}.
        Position() Position
 }
 
index 0d2c187c6e506a73c6c67175e297893a0181e8f0..4aff9e9c479d3b80c12b1a90594c2d343d8df0bb 100644 (file)
@@ -33,6 +33,7 @@ type Whitelist struct {
        patternsStrings []string
 }
 
+// MarshalJSON is for internal use only.
 func (w Whitelist) MarshalJSON() ([]byte, error) {
        if w.acceptNone {
                return json.Marshal(acceptNoneKeyword)
index 1d46a74642c82f0ce5931c9f0456431824f6a6da..c339972785a223b2a0d53944992552394dcd25f9 100644 (file)
@@ -130,6 +130,7 @@ func (f *FileMeta) JoinStat(name string) (FileMetaInfo, error) {
 
 type FileMetaInfo interface {
        os.FileInfo
+       // Meta is for internal use.
        Meta() *FileMeta
 }
 
index 7e6b6e67040d21db9ca527cc8f84d07ce9c4379a..d8f28286cdf030b6a311393f1742da24f997f59f 100644 (file)
@@ -266,7 +266,7 @@ func (m *pageMap) newResource(fim hugofs.FileMetaInfo, owner *pageState) (resour
 }
 
 func (m *pageMap) createSiteTaxonomies() error {
-       m.s.taxonomies = make(TaxonomyList)
+       m.s.taxonomies = make(page.TaxonomyList)
        var walkErr error
        m.taxonomies.Walk(func(s string, v any) bool {
                n := v.(*contentNode)
@@ -275,7 +275,7 @@ func (m *pageMap) createSiteTaxonomies() error {
                viewName := t.name
 
                if t.termKey == "" {
-                       m.s.taxonomies[viewName.plural] = make(Taxonomy)
+                       m.s.taxonomies[viewName.plural] = make(page.Taxonomy)
                } else {
                        taxonomy := m.s.taxonomies[viewName.plural]
                        if taxonomy == nil {
@@ -285,7 +285,7 @@ func (m *pageMap) createSiteTaxonomies() error {
                        m.taxonomyEntries.WalkPrefix(s, func(ss string, v any) bool {
                                b2 := v.(*contentNode)
                                info := b2.viewInfo
-                               taxonomy.add(info.termKey, page.NewWeightedPage(info.weight, info.ref.p, n.p))
+                               taxonomy[info.termKey] = append(taxonomy[info.termKey], page.NewWeightedPage(info.weight, info.ref.p, n.p))
 
                                return false
                        })
index 17717ed529f8c06c63438108752db68e85fba573..d051b10bc51c9e153932c6ebd8a10f9576cd7dc4 100644 (file)
@@ -20,6 +20,7 @@ import (
        "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/resources/page"
+       "github.com/gohugoio/hugo/source"
 )
 
 type gitInfo struct {
@@ -27,11 +28,14 @@ type gitInfo struct {
        repo       *gitmap.GitRepo
 }
 
-func (g *gitInfo) forPage(p page.Page) *gitmap.GitInfo {
+func (g *gitInfo) forPage(p page.Page) source.GitInfo {
        name := strings.TrimPrefix(filepath.ToSlash(p.File().Filename()), g.contentDir)
        name = strings.TrimPrefix(name, "/")
-
-       return g.repo.Files[name]
+       gi, found := g.repo.Files[name]
+       if !found {
+               return source.GitInfo{}
+       }
+       return source.NewGitInfo(*gi)
 }
 
 func newGitInfo(cfg config.Provider) (*gitInfo, error) {
index 6be26d60e99e25333fa6e90ece2e454481d8652d..569c27be5c7363fd4ee14b4667687fb9b8bf7567 100644 (file)
@@ -41,7 +41,6 @@ import (
 
        "github.com/gohugoio/hugo/source"
 
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/config"
 
        "github.com/gohugoio/hugo/publisher"
@@ -202,13 +201,13 @@ func (h *HugoSites) Data() map[string]any {
        return h.data
 }
 
-func (h *HugoSites) gitInfoForPage(p page.Page) (*gitmap.GitInfo, error) {
+func (h *HugoSites) gitInfoForPage(p page.Page) (source.GitInfo, error) {
        if _, err := h.init.gitInfo.Do(); err != nil {
-               return nil, err
+               return source.GitInfo{}, err
        }
 
        if h.gitInfo == nil {
-               return nil, nil
+               return source.GitInfo{}, nil
        }
 
        return h.gitInfo.forPage(p), nil
index 5acfbc67720f60575124f3e7bb3a90965652ac95..97f1ed351ba3b5b1fdad981da557248891d05fc4 100644 (file)
@@ -31,8 +31,6 @@ import (
 
        "github.com/gohugoio/hugo/hugofs/files"
 
-       "github.com/bep/gitmap"
-
        "github.com/gohugoio/hugo/helpers"
 
        "github.com/gohugoio/hugo/common/herrors"
@@ -150,7 +148,7 @@ func (p *pageState) GetIdentity() identity.Identity {
        return identity.NewPathIdentity(files.ComponentFolderContent, filepath.FromSlash(p.Pathc()))
 }
 
-func (p *pageState) GitInfo() *gitmap.GitInfo {
+func (p *pageState) GitInfo() source.GitInfo {
        return p.gitInfo
 }
 
index 59f0bc77605f6097d4de4bab1de35d74d5ef4d19..0527a0682c576c6325379148dcd704843870ffce 100644 (file)
@@ -16,7 +16,6 @@ package hugolib
 import (
        "sync"
 
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/compare"
        "github.com/gohugoio/hugo/lazy"
@@ -24,6 +23,7 @@ import (
        "github.com/gohugoio/hugo/output"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/resource"
+       "github.com/gohugoio/hugo/source"
 )
 
 type treeRefProvider interface {
@@ -106,7 +106,7 @@ type pageCommon struct {
        shortcodeState *shortcodeHandler
 
        // Set if feature enabled and this is in a Git repo.
-       gitInfo    *gitmap.GitInfo
+       gitInfo    source.GitInfo
        codeowners []string
 
        // Positional navigation
index daf989f42ba50bfe281e21efa8f4d0152606308c..8d2495ddc175520e726a8fbe829ed1f5dd5ad258 100644 (file)
@@ -404,7 +404,7 @@ func (pm *pageMeta) setMetadata(parentBucket *pagesMapBucket, p *pageState, fron
        }
 
        var gitAuthorDate time.Time
-       if p.gitInfo != nil {
+       if !p.gitInfo.IsZero() {
                gitAuthorDate = p.gitInfo.AuthorDate
        }
 
index 8fb39a1eac8ab3d4cb5c09f5918f94293d549ea6..2ffc3a346f361e0604eb374ea33f40a471a5266f 100644 (file)
@@ -110,9 +110,9 @@ type Site struct {
 
        *PageCollections
 
-       taxonomies TaxonomyList
+       taxonomies page.TaxonomyList
 
-       Sections Taxonomy
+       Sections page.Taxonomy
        Info     *SiteInfo
 
        language   *langs.Language
@@ -172,7 +172,7 @@ type Site struct {
        init *siteInit
 }
 
-func (s *Site) Taxonomies() TaxonomyList {
+func (s *Site) Taxonomies() page.TaxonomyList {
        s.init.taxonomies.Do()
        return s.taxonomies
 }
@@ -708,7 +708,7 @@ func (s *SiteInfo) Menus() navigation.Menus {
 }
 
 // TODO(bep) type
-func (s *SiteInfo) Taxonomies() any {
+func (s *SiteInfo) Taxonomies() page.TaxonomyList {
        return s.s.Taxonomies()
 }
 
diff --git a/hugolib/taxonomy.go b/hugolib/taxonomy.go
deleted file mode 100644 (file)
index 6b3c2b9..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-// Copyright 2019 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package hugolib
-
-import (
-       "fmt"
-       "sort"
-
-       "github.com/gohugoio/hugo/compare"
-       "github.com/gohugoio/hugo/langs"
-
-       "github.com/gohugoio/hugo/resources/page"
-)
-
-// The TaxonomyList is a list of all taxonomies and their values
-// e.g. List['tags'] => TagTaxonomy (from above)
-type TaxonomyList map[string]Taxonomy
-
-func (tl TaxonomyList) String() string {
-       return fmt.Sprintf("TaxonomyList(%d)", len(tl))
-}
-
-// A Taxonomy is a map of keywords to a list of pages.
-// For example
-//    TagTaxonomy['technology'] = page.WeightedPages
-//    TagTaxonomy['go']  =  page.WeightedPages
-type Taxonomy map[string]page.WeightedPages
-
-// OrderedTaxonomy is another representation of an Taxonomy using an array rather than a map.
-// Important because you can't order a map.
-type OrderedTaxonomy []OrderedTaxonomyEntry
-
-// getOneOPage returns one page in the taxonomy,
-// nil if there is none.
-func (t OrderedTaxonomy) getOneOPage() page.Page {
-       if len(t) == 0 {
-               return nil
-       }
-       return t[0].Pages()[0]
-}
-
-// OrderedTaxonomyEntry is similar to an element of a Taxonomy, but with the key embedded (as name)
-// e.g:  {Name: Technology, page.WeightedPages: TaxonomyPages}
-type OrderedTaxonomyEntry struct {
-       Name string
-       page.WeightedPages
-}
-
-// Get the weighted pages for the given key.
-func (i Taxonomy) Get(key string) page.WeightedPages {
-       return i[key]
-}
-
-// Count the weighted pages for the given key.
-func (i Taxonomy) Count(key string) int { return len(i[key]) }
-
-func (i Taxonomy) add(key string, w page.WeightedPage) {
-       i[key] = append(i[key], w)
-}
-
-// TaxonomyArray returns an ordered taxonomy with a non defined order.
-func (i Taxonomy) TaxonomyArray() OrderedTaxonomy {
-       ies := make([]OrderedTaxonomyEntry, len(i))
-       count := 0
-       for k, v := range i {
-               ies[count] = OrderedTaxonomyEntry{Name: k, WeightedPages: v}
-               count++
-       }
-       return ies
-}
-
-// Alphabetical returns an ordered taxonomy sorted by key name.
-func (i Taxonomy) Alphabetical() OrderedTaxonomy {
-       ia := i.TaxonomyArray()
-       p := ia.getOneOPage()
-       if p == nil {
-               return ia
-       }
-       currentSite := p.Site().Current()
-       coll := langs.GetCollator(currentSite.Language())
-       coll.Lock()
-       defer coll.Unlock()
-       name := func(i1, i2 *OrderedTaxonomyEntry) bool {
-               return coll.CompareStrings(i1.Name, i2.Name) < 0
-       }
-       oiBy(name).Sort(ia)
-       return ia
-}
-
-// ByCount returns an ordered taxonomy sorted by # of pages per key.
-// If taxonomies have the same # of pages, sort them alphabetical
-func (i Taxonomy) ByCount() OrderedTaxonomy {
-       count := func(i1, i2 *OrderedTaxonomyEntry) bool {
-               li1 := len(i1.WeightedPages)
-               li2 := len(i2.WeightedPages)
-
-               if li1 == li2 {
-                       return compare.LessStrings(i1.Name, i2.Name)
-               }
-               return li1 > li2
-       }
-
-       ia := i.TaxonomyArray()
-       oiBy(count).Sort(ia)
-       return ia
-}
-
-// Pages returns the Pages for this taxonomy.
-func (ie OrderedTaxonomyEntry) Pages() page.Pages {
-       return ie.WeightedPages.Pages()
-}
-
-// Count returns the count the pages in this taxonomy.
-func (ie OrderedTaxonomyEntry) Count() int {
-       return len(ie.WeightedPages)
-}
-
-// Term returns the name given to this taxonomy.
-func (ie OrderedTaxonomyEntry) Term() string {
-       return ie.Name
-}
-
-// Reverse reverses the order of the entries in this taxonomy.
-func (t OrderedTaxonomy) Reverse() OrderedTaxonomy {
-       for i, j := 0, len(t)-1; i < j; i, j = i+1, j-1 {
-               t[i], t[j] = t[j], t[i]
-       }
-
-       return t
-}
-
-// A type to implement the sort interface for TaxonomyEntries.
-type orderedTaxonomySorter struct {
-       taxonomy OrderedTaxonomy
-       by       oiBy
-}
-
-// Closure used in the Sort.Less method.
-type oiBy func(i1, i2 *OrderedTaxonomyEntry) bool
-
-func (by oiBy) Sort(taxonomy OrderedTaxonomy) {
-       ps := &orderedTaxonomySorter{
-               taxonomy: taxonomy,
-               by:       by, // The Sort method's receiver is the function (closure) that defines the sort order.
-       }
-       sort.Stable(ps)
-}
-
-// Len is part of sort.Interface.
-func (s *orderedTaxonomySorter) Len() int {
-       return len(s.taxonomy)
-}
-
-// Swap is part of sort.Interface.
-func (s *orderedTaxonomySorter) Swap(i, j int) {
-       s.taxonomy[i], s.taxonomy[j] = s.taxonomy[j], s.taxonomy[i]
-}
-
-// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
-func (s *orderedTaxonomySorter) Less(i, j int) bool {
-       return s.by(&s.taxonomy[i], &s.taxonomy[j])
-}
index d6b30ec100535a0433273553aeacc084de0cc97f..42aefda5e0719683de77d880c1e3e83d3de2e723 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package langs contains the language related types and function.
 package langs
 
 import (
index a59da939e8b83481729fd51e7307280fcbb7e6a2..7eede07103341667935afb39c9d980334933f537 100644 (file)
@@ -26,30 +26,56 @@ import (
 var _ AttributesOptionsSliceProvider = (*attributes.AttributesHolder)(nil)
 
 type AttributesProvider interface {
+       // Attributes passed in from Markdown (e.g. { attrName1=attrValue1 attrName2="attr Value 2" }).
        Attributes() map[string]any
 }
 
 type LinkContext interface {
+       // The Page being rendered.
        Page() any
+
+       // The link URL.
        Destination() string
+
+       // The link title attribute.
        Title() string
+
+       // The rendered (HTML) text.
        Text() hstring.RenderedString
+
+       // The plain variant of Text.
        PlainText() string
 }
 
 type ImageLinkContext interface {
        LinkContext
+
+       // Returns true if this is a standalone image and the config option
+       // markup.goldmark.parser.wrapStandAloneImageWithinParagraph is disabled.
        IsBlock() bool
+
+       // Zero-based ordinal for all the images in the current document.
        Ordinal() int
 }
 
+// CodeblockContext is the context passed to a code block render hook.
 type CodeblockContext interface {
        AttributesProvider
        text.Positioner
+
+       // Chroma highlighting processing options. This will only be filled if Type is a known Chroma Lexer.
        Options() map[string]any
+
+       // The type of code block. This will be the programming language, e.g. bash, when doing code highlighting.
        Type() string
+
+       // The text between the code fences.
        Inner() string
+
+       // Zero-based ordinal for all code blocks in the current document.
        Ordinal() int
+
+       // The owning Page.
        Page() any
 }
 
index 010c941f74ae7ae4b2a8cf050f623cd1dd072cc3..b749977005511f732bbf8dda56b4fe45bed5e5f8 100644 (file)
@@ -157,10 +157,12 @@ type HightlightResult struct {
        highlighted template.HTML
 }
 
+// Wrapped returns the highlighted code wrapped in a <div>, <pre> and <code> tag.
 func (h HightlightResult) Wrapped() template.HTML {
        return h.highlighted
 }
 
+// Inner returns the highlighted code without the wrapping <div>, <pre> and <code> tag, suitable for inline use.
 func (h HightlightResult) Inner() template.HTML {
        return h.highlighted[h.innerLow:h.innerHigh]
 }
index 1345867f93da1fe7c2d2c0337aba8decc44f6336..aefa5086741181fe860cb62bc053d15c825cf354 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package markup contains the markup handling (e.g. Markdown).
 package markup
 
 import (
index e47acb1e34eff1fe5e354439073cf0577caa695c..cdfb1c6542bf9ebe1e77bcba890d7569e5246198 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package media containes Media Type (MIME type) related types and functions.
 package media
 
 import (
index 5e4996f39640db79df022f2f1435a4c5f5facb61..cb280823cbbc1e55451affc0afa32e6e9a01c247 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2019 The Hugo Authors. All rights reserved.
+// Copyright 2023 The Hugo Authors. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package navigation provides the menu functionality.
 package navigation
 
 import (
index 6a326643155b4b7dea738738caa392ad011c8499..4287ed87529a0c458bcd23a121496a3ef301434d 100644 (file)
@@ -10,7 +10,7 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-//
+
 package navigation
 
 import (
index 722079df9a7f360ab8b7a5f208b293c4ba4ed5c3..0bc08e4905d72b101fa4c40125c3b19961956468 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package output contains Output Format types and functions.
 package output
 
 import (
@@ -400,6 +401,7 @@ func (f Format) BaseFilename() string {
 }
 
 // MarshalJSON returns the JSON encoding of f.
+// For internal use only.
 func (f Format) MarshalJSON() ([]byte, error) {
        type Alias Format
        return json.Marshal(&struct {
diff --git a/resources/docs.go b/resources/docs.go
new file mode 100644 (file)
index 0000000..f992893
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2023 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package resources contains Resource related types.
+package resources
index 487f250d519b54da44ae67e06ead733c44d68e86..8df348b23dad0decfc549a8aa3df4317a00f9a50 100644 (file)
@@ -254,8 +254,10 @@ func init() {
        }
 }
 
+// Tags is a map of EXIF tags.
 type Tags map[string]any
 
+// UnmarshalJSON is for internal use only.
 func (v *Tags) UnmarshalJSON(b []byte) error {
        vv := make(map[string]any)
        if err := tcodec.Unmarshal(b, &vv); err != nil {
@@ -267,6 +269,7 @@ func (v *Tags) UnmarshalJSON(b []byte) error {
        return nil
 }
 
+// MarshalJSON is for internal use only.
 func (v Tags) MarshalJSON() ([]byte, error) {
        return tcodec.Marshal(v)
 }
index 4e66b010cbf981f8423e64cbc07db7d19186d735..8469590063a9fb99668886e4e7d2448840bf2c46 100644 (file)
@@ -29,6 +29,7 @@ type ImageResource interface {
 type ImageResourceOps interface {
        // Height returns the height of the Image.
        Height() int
+
        // Width returns the width of the Image.
        Width() int
 
@@ -37,8 +38,17 @@ type ImageResourceOps interface {
        // Use the anchor option to change the crop box anchor point.
        //    {{ $image := $image.Crop "600x400" }}
        Crop(spec string) (ImageResource, error)
+
+       // Fill scales the image to the smallest possible size that will cover the specified dimensions in spec,
+       // crops the resized image to the specified dimensions using the given anchor point.
+       // The spec is space delimited, e.g. `200x300 TopLeft`.
        Fill(spec string) (ImageResource, error)
+
+       // Fit scales down the image using the given spec.
        Fit(spec string) (ImageResource, error)
+
+       // Resize resizes the image to the given spec. If one of width or height is 0, the image aspect
+       // ratio is preserved.
        Resize(spec string) (ImageResource, error)
 
        // Filter applies one or more filters to an Image.
index 929f04d93713d71d23ffd9e6e21d1339d105d9cf..eeb2cdb280961686af7e6d8fa8d21c5884a532ad 100644 (file)
@@ -21,7 +21,6 @@ import (
        "github.com/gohugoio/hugo/identity"
        "github.com/gohugoio/hugo/markup/converter"
 
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/tpl"
 
@@ -61,18 +60,17 @@ type AuthorProvider interface {
 
 // ChildCareProvider provides accessors to child resources.
 type ChildCareProvider interface {
+       // Pages returns a list of pages of all kinds.
        Pages() Pages
 
        // RegularPages returns a list of pages of kind 'Page'.
-       // In Hugo 0.57 we changed the Pages method so it returns all page
-       // kinds, even sections. If you want the old behaviour, you can
-       // use RegularPages.
        RegularPages() Pages
 
        // RegularPagesRecursive returns all regular pages below the current
        // section.
        RegularPagesRecursive() Pages
 
+       // Resources returns a list of all resources.
        Resources() resource.Resources
 }
 
@@ -103,16 +101,21 @@ type ContentProvider interface {
        ReadingTime() int
 
        // Len returns the length of the content.
+       // This is for internal use only.
        Len() int
 }
 
 // ContentRenderer provides the content rendering methods for some content.
 type ContentRenderer interface {
+       // RenderContent renders the given content.
+       // For internal use only.
        RenderContent(content []byte, renderTOC bool) (converter.Result, error)
 }
 
 // FileProvider provides the source file.
 type FileProvider interface {
+       // File returns the source file for this Page,
+       // or a zero File if this Page is not backed by a file.
        File() source.File
 }
 
@@ -131,13 +134,17 @@ type GetPageProvider interface {
 
 // GitInfoProvider provides Git info.
 type GitInfoProvider interface {
-       GitInfo() *gitmap.GitInfo
+       // GitInfo returns the Git info for this object.
+       GitInfo() source.GitInfo
+       // CodeOwners returns the code owners for this object.
        CodeOwners() []string
 }
 
 // InSectionPositioner provides section navigation.
 type InSectionPositioner interface {
+       // NextInSection returns the next page in the same section.
        NextInSection() Page
+       // PrevInSection returns the previous page in the same section.
        PrevInSection() Page
 }
 
@@ -149,6 +156,7 @@ type InternalDependencies interface {
 
 // OutputFormatsProvider provides the OutputFormats of a Page.
 type OutputFormatsProvider interface {
+       // OutputFormats returns the OutputFormats for this Page.
        OutputFormats() OutputFormats
 }
 
@@ -229,6 +237,7 @@ type PageMetaProvider interface {
        SectionsPath() string
 
        // Sitemap returns the sitemap configuration for this page.
+       // This is for internal use only.
        Sitemap() config.Sitemap
 
        // Type is a discriminator used to select layouts etc. It is typically set
@@ -242,7 +251,15 @@ type PageMetaProvider interface {
 
 // PageRenderProvider provides a way for a Page to render content.
 type PageRenderProvider interface {
+       // Render renders the given layout with this Page as context.
        Render(layout ...string) (template.HTML, error)
+       // RenderString renders the first value in args with tPaginatorhe content renderer defined
+       // for this Page.
+       // It takes an optional map as a second argument:
+       //
+       // display (“inline”):
+       // - inline or block. If inline (default), surrounding <p></p> on short snippets will be trimmed.
+       // markup (defaults to the Page’s markup)
        RenderString(args ...any) (template.HTML, error)
 }
 
@@ -311,7 +328,9 @@ type PageWithoutContent interface {
 
 // Positioner provides next/prev navigation.
 type Positioner interface {
+       // Next points up to the next regular page (sorted by Hugo’s default sort).
        Next() Page
+       // Prev points down to the previous regular page (sorted by Hugo’s default sort).
        Prev() Page
 
        // Deprecated: Use Prev. Will be removed in Hugo 0.57
@@ -323,16 +342,19 @@ type Positioner interface {
 
 // RawContentProvider provides the raw, unprocessed content of the page.
 type RawContentProvider interface {
+       // RawContent returns the raw, unprocessed content of the page excluding any front matter.
        RawContent() string
 }
 
 // RefProvider provides the methods needed to create reflinks to pages.
 type RefProvider interface {
+       // Ref returns an absolute URl to a page.
        Ref(argsm map[string]any) (string, error)
 
        // RefFrom is for internal use only.
        RefFrom(argsm map[string]any, source any) (string, error)
 
+       // RelRef returns a relative URL to a page.
        RelRef(argsm map[string]any) (string, error)
 
        // RefFrom is for internal use only.
@@ -356,12 +378,15 @@ type ShortcodeInfoProvider interface {
 
 // SitesProvider provide accessors to get sites.
 type SitesProvider interface {
+       // Site returns the current site.
        Site() Site
+       // Sites returns all sites.
        Sites() Sites
 }
 
 // TableOfContentsProvider provides the table of contents for a Page.
 type TableOfContentsProvider interface {
+       // TableOfContents returns the table of contents for the page rendered as HTML.
        TableOfContents() template.HTML
 }
 
@@ -382,7 +407,7 @@ type TranslationsProvider interface {
 // TreeProvider provides section tree navigation.
 type TreeProvider interface {
 
-       // IsAncestor returns whether the current page is an ancestor of the given
+       // IsAncestor returns whether the current page is an ancestor of other.
        // Note that this method is not relevant for taxonomy lists and taxonomy terms pages.
        IsAncestor(other any) (bool, error)
 
@@ -390,7 +415,7 @@ type TreeProvider interface {
        // Note that this will return nil for pages that is not regular, home or section pages.
        CurrentSection() Page
 
-       // IsDescendant returns whether the current page is a descendant of the given
+       // IsDescendant returns whether the current page is a descendant of other.
        // Note that this method is not relevant for taxonomy lists and taxonomy terms pages.
        IsDescendant(other any) (bool, error)
 
@@ -398,7 +423,7 @@ type TreeProvider interface {
        // For the home page, this will return itself.
        FirstSection() Page
 
-       // InSection returns whether the given page is in the current section.
+       // InSection returns whether other is in the current section.
        // Note that this will always return false for pages that are
        // not either regular, home or section pages.
        InSection(other any) (bool, error)
index 0f73d81aec0758b6fde83d6d5a335825031d0a36..373257878eb5fcc1a5fcce1126c12f8e60a52fa9 100644 (file)
@@ -17,7 +17,6 @@ package page
 
 import (
        "encoding/json"
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/hugofs/files"
@@ -82,6 +81,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
        language := p.Language()
        file := p.File()
        gitInfo := p.GitInfo()
+       codeOwners := p.CodeOwners()
        outputFormats := p.OutputFormats()
        alternativeOutputFormats := p.AlternativeOutputFormats()
        menus := p.Menus()
@@ -89,10 +89,11 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
        isTranslated := p.IsTranslated()
        allTranslations := p.AllTranslations()
        translations := p.Translations()
+       store := p.Store()
        getIdentity := p.GetIdentity()
 
        s := struct {
-               Content                  any
+               Content                  interface{}
                Plain                    string
                PlainWords               []string
                Summary                  template.HTML
@@ -110,7 +111,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
                Name                     string
                Title                    string
                Params                   maps.Params
-               Data                     any
+               Data                     interface{}
                Date                     time.Time
                Lastmod                  time.Time
                PublishDate              time.Time
@@ -139,7 +140,8 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
                Weight                   int
                Language                 *langs.Language
                File                     source.File
-               GitInfo                  *gitmap.GitInfo
+               GitInfo                  source.GitInfo
+               CodeOwners               []string
                OutputFormats            OutputFormats
                AlternativeOutputFormats OutputFormats
                Menus                    navigation.PageMenus
@@ -147,6 +149,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
                IsTranslated             bool
                AllTranslations          Pages
                Translations             Pages
+               Store                    *maps.Scratch
                GetIdentity              identity.Identity
        }{
                Content:                  content,
@@ -197,6 +200,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
                Language:                 language,
                File:                     file,
                GitInfo:                  gitInfo,
+               CodeOwners:               codeOwners,
                OutputFormats:            outputFormats,
                AlternativeOutputFormats: alternativeOutputFormats,
                Menus:                    menus,
@@ -204,6 +208,7 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
                IsTranslated:             isTranslated,
                AllTranslations:          allTranslations,
                Translations:             translations,
+               Store:                    store,
                GetIdentity:              getIdentity,
        }
 
index 15f8c39508682163cf34aff3012c1fcc20e404ba..c4af3f554e0ae9b0fd680d067e5b9b6326d4cac6 100644 (file)
@@ -28,7 +28,6 @@ import (
 
        "github.com/gohugoio/hugo/hugofs"
 
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/navigation"
 
        "github.com/gohugoio/hugo/common/hugo"
@@ -200,8 +199,8 @@ func (p *nopPage) GetTerms(taxonomy string) Pages {
        return nil
 }
 
-func (p *nopPage) GitInfo() *gitmap.GitInfo {
-       return nil
+func (p *nopPage) GitInfo() source.GitInfo {
+       return source.GitInfo{}
 }
 
 func (p *nopPage) CodeOwners() []string {
index 9f4bfcff5663f389039437f3264d10e5b9fd0cb6..46d9fda82a956f90b92b1252e64a1d7453c81b58 100644 (file)
@@ -27,8 +27,10 @@ import (
 
 // PaginatorProvider provides two ways to create a page paginator.
 type PaginatorProvider interface {
+       // Paginator creates a paginator with the default page set.
        Paginator(options ...any) (*Pager, error)
-       Paginate(seq any, options ...any) (*Pager, error)
+       // Paginate creates a paginator with the given page set in pages.
+       Paginate(pages any, options ...any) (*Pager, error)
 }
 
 // Pager represents one of the elements in a paginator.
index f5806280c8f9aa7c1e78de66650692f62e2b4d61..8daff95aece2bc565f97f01549c5ebacbbb4b006 100644 (file)
@@ -26,8 +26,7 @@ import (
        "github.com/gohugoio/hugo/navigation"
 )
 
-// Site represents a site in the build. This is currently a very narrow interface,
-// but the actual implementation will be richer, see hugolib.SiteInfo.
+// Site represents a site. There can be multople sites in a multilingual setup.
 type Site interface {
        // Returns the Language configured for this Site.
        Language() *langs.Language
@@ -63,7 +62,7 @@ type Site interface {
        BaseURL() template.URL
 
        // Retuns a taxonomy map.
-       Taxonomies() any
+       Taxonomies() TaxonomyList
 
        // Returns the last modification date of the content.
        LastChange() time.Time
@@ -142,7 +141,7 @@ func (t testSite) Menus() navigation.Menus {
        return nil
 }
 
-func (t testSite) Taxonomies() any {
+func (t testSite) Taxonomies() TaxonomyList {
        return nil
 }
 
diff --git a/resources/page/taxonomy.go b/resources/page/taxonomy.go
new file mode 100644 (file)
index 0000000..f50152f
--- /dev/null
@@ -0,0 +1,168 @@
+// Copyright 2023 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package page
+
+import (
+       "fmt"
+       "sort"
+
+       "github.com/gohugoio/hugo/compare"
+       "github.com/gohugoio/hugo/langs"
+)
+
+// The TaxonomyList is a list of all taxonomies and their values
+// e.g. List['tags'] => TagTaxonomy (from above)
+type TaxonomyList map[string]Taxonomy
+
+func (tl TaxonomyList) String() string {
+       return fmt.Sprintf("TaxonomyList(%d)", len(tl))
+}
+
+// A Taxonomy is a map of keywords to a list of pages.
+// For example
+//
+//     TagTaxonomy['technology'] = WeightedPages
+//     TagTaxonomy['go']  =  WeightedPages
+type Taxonomy map[string]WeightedPages
+
+// OrderedTaxonomy is another representation of an Taxonomy using an array rather than a map.
+// Important because you can't order a map.
+type OrderedTaxonomy []OrderedTaxonomyEntry
+
+// getOneOPage returns one page in the taxonomy,
+// nil if there is none.
+func (t OrderedTaxonomy) getOneOPage() Page {
+       if len(t) == 0 {
+               return nil
+       }
+       return t[0].Pages()[0]
+}
+
+// OrderedTaxonomyEntry is similar to an element of a Taxonomy, but with the key embedded (as name)
+// e.g:  {Name: Technology, WeightedPages: TaxonomyPages}
+type OrderedTaxonomyEntry struct {
+       Name string
+       WeightedPages
+}
+
+// Get the weighted pages for the given key.
+func (i Taxonomy) Get(key string) WeightedPages {
+       return i[key]
+}
+
+// Count the weighted pages for the given key.
+func (i Taxonomy) Count(key string) int { return len(i[key]) }
+
+// TaxonomyArray returns an ordered taxonomy with a non defined order.
+func (i Taxonomy) TaxonomyArray() OrderedTaxonomy {
+       ies := make([]OrderedTaxonomyEntry, len(i))
+       count := 0
+       for k, v := range i {
+               ies[count] = OrderedTaxonomyEntry{Name: k, WeightedPages: v}
+               count++
+       }
+       return ies
+}
+
+// Alphabetical returns an ordered taxonomy sorted by key name.
+func (i Taxonomy) Alphabetical() OrderedTaxonomy {
+       ia := i.TaxonomyArray()
+       p := ia.getOneOPage()
+       if p == nil {
+               return ia
+       }
+       currentSite := p.Site().Current()
+       coll := langs.GetCollator(currentSite.Language())
+       coll.Lock()
+       defer coll.Unlock()
+       name := func(i1, i2 *OrderedTaxonomyEntry) bool {
+               return coll.CompareStrings(i1.Name, i2.Name) < 0
+       }
+       oiBy(name).Sort(ia)
+       return ia
+}
+
+// ByCount returns an ordered taxonomy sorted by # of pages per key.
+// If taxonomies have the same # of pages, sort them alphabetical
+func (i Taxonomy) ByCount() OrderedTaxonomy {
+       count := func(i1, i2 *OrderedTaxonomyEntry) bool {
+               li1 := len(i1.WeightedPages)
+               li2 := len(i2.WeightedPages)
+
+               if li1 == li2 {
+                       return compare.LessStrings(i1.Name, i2.Name)
+               }
+               return li1 > li2
+       }
+
+       ia := i.TaxonomyArray()
+       oiBy(count).Sort(ia)
+       return ia
+}
+
+// Pages returns the Pages for this taxonomy.
+func (ie OrderedTaxonomyEntry) Pages() Pages {
+       return ie.WeightedPages.Pages()
+}
+
+// Count returns the count the pages in this taxonomy.
+func (ie OrderedTaxonomyEntry) Count() int {
+       return len(ie.WeightedPages)
+}
+
+// Term returns the name given to this taxonomy.
+func (ie OrderedTaxonomyEntry) Term() string {
+       return ie.Name
+}
+
+// Reverse reverses the order of the entries in this taxonomy.
+func (t OrderedTaxonomy) Reverse() OrderedTaxonomy {
+       for i, j := 0, len(t)-1; i < j; i, j = i+1, j-1 {
+               t[i], t[j] = t[j], t[i]
+       }
+
+       return t
+}
+
+// A type to implement the sort interface for TaxonomyEntries.
+type orderedTaxonomySorter struct {
+       taxonomy OrderedTaxonomy
+       by       oiBy
+}
+
+// Closure used in the Sort.Less method.
+type oiBy func(i1, i2 *OrderedTaxonomyEntry) bool
+
+func (by oiBy) Sort(taxonomy OrderedTaxonomy) {
+       ps := &orderedTaxonomySorter{
+               taxonomy: taxonomy,
+               by:       by, // The Sort method's receiver is the function (closure) that defines the sort order.
+       }
+       sort.Stable(ps)
+}
+
+// Len is part of sort.Interface.
+func (s *orderedTaxonomySorter) Len() int {
+       return len(s.taxonomy)
+}
+
+// Swap is part of sort.Interface.
+func (s *orderedTaxonomySorter) Swap(i, j int) {
+       s.taxonomy[i], s.taxonomy[j] = s.taxonomy[j], s.taxonomy[i]
+}
+
+// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
+func (s *orderedTaxonomySorter) Less(i, j int) bool {
+       return s.by(&s.taxonomy[i], &s.taxonomy[j])
+}
index 22346c3895b606cb240b86bbc9585855b5b1c8de..e8275ba4050e5f9714acaedaa17f07eeef7326d8 100644 (file)
@@ -26,7 +26,6 @@ import (
 
        "github.com/gohugoio/hugo/modules"
 
-       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/helpers"
        "github.com/gohugoio/hugo/resources/resource"
 
@@ -250,8 +249,8 @@ func (p *testPage) GetRelatedDocsHandler() *RelatedDocsHandler {
        return relatedDocsHandler
 }
 
-func (p *testPage) GitInfo() *gitmap.GitInfo {
-       return nil
+func (p *testPage) GitInfo() source.GitInfo {
+       return source.GitInfo{}
 }
 
 func (p *testPage) CodeOwners() []string {
index a888d6fb4ba78cfc25a9bfab3c402429c549cee5..a877c8906389c779cdce6ba2bd5b51a3e2dd686e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2019 The Hugo Authors. All rights reserved.
+// Copyright 2023 The Hugo Authors. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package resource contains Resource related types.
 package resource
 
 import (
index 4ba95c170534df11cc382f5b9bdaea91a205a1db..4ef5fc5a0f8e5f80c72f2063d138dab82419a462 100644 (file)
@@ -64,6 +64,9 @@ type ResourceError interface {
 
 // ErrProvider provides an Err.
 type ErrProvider interface {
+
+       // Err returns an error if this resource is in an error state.
+       // This will currently only be set for resources obtained from resources.GetRemote.
        Err() ResourceError
 }
 
index f882eb898b04f810738ec65536051ff2049fdafa..9ce601b5bd2863e2827cec9b9b743563f32e17cc 100644 (file)
@@ -18,7 +18,9 @@ import (
        "path/filepath"
        "strings"
        "sync"
+       "time"
 
+       "github.com/bep/gitmap"
        "github.com/gohugoio/hugo/common/paths"
 
        "github.com/gohugoio/hugo/hugofs/files"
@@ -294,3 +296,31 @@ func (sp *SourceSpec) NewFileInfo(fi hugofs.FileMetaInfo) (*FileInfo, error) {
 
        return f, nil
 }
+
+func NewGitInfo(info gitmap.GitInfo) GitInfo {
+       return GitInfo(info)
+}
+
+// GitInfo provides information about a version controled source file.
+type GitInfo struct {
+       // Commit hash.
+       Hash string `json:"hash"`
+       // Abbreviated commit hash.
+       AbbreviatedHash string `json:"abbreviatedHash"`
+       // The commit message's subject/title line.
+       Subject string `json:"subject"`
+       // The author name, respecting .mailmap.
+       AuthorName string `json:"authorName"`
+       // The author email address, respecting .mailmap.
+       AuthorEmail string `json:"authorEmail"`
+       // The author date.
+       AuthorDate time.Time `json:"authorDate"`
+       // The commit date.
+       CommitDate time.Time `json:"commitDate"`
+}
+
+// IsZero returns true if the GitInfo is empty,
+// meaning it will also be falsy in the Go templates.
+func (g GitInfo) IsZero() bool {
+       return g.Hash == ""
+}
index 0b7306a7537576dc8d24cb7916551ea8d0990d62..954167f28ca1c544f045609dbba9db459d0d4538 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright 2017-present The Hugo Authors. All rights reserved.
+// Copyright 2023 The Hugo Authors. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package source contains the types and functions related to source files.
 package source
 
 import (
index 005e942b720e616eadc13b6ea93d24e53dfb0123..1ed308c57304ef52e7e5bbc68106fce6f8e6c087 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package diagrams provides template functions for generating diagrams.
 package diagrams
 
 import (
index 1abee1b0c409acde410fda9afc3c86016604c575..f4d9305708f01d5bede93526faa54fe9f60d0478 100644 (file)
@@ -91,6 +91,7 @@ func (ns *Namespace) Config(path any) (image.Config, error) {
        return config, nil
 }
 
+// Filter applies the given filters to the image given as the last element in args.
 func (ns *Namespace) Filter(args ...any) (images.ImageResource, error) {
        if len(args) < 2 {
                return nil, errors.New("must provide an image and one or more filters")
diff --git a/tpl/openapi/docs.go b/tpl/openapi/docs.go
new file mode 100644 (file)
index 0000000..bb7ed9c
--- /dev/null
@@ -0,0 +1,2 @@
+// Package openapi provides functions for generating OpenAPI (Swagger) documentation.
+package openapi
index 9b84e9fbe47f144e01de87c5f23befca343e60b2..31d56289ec82a555d1769123843eaf9dcfe6cf0e 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package openapi3 provides functions for generating OpenAPI v3 (Swagger) documentation.
 package openapi3
 
 import (
@@ -54,6 +55,7 @@ type OpenAPIDocument struct {
        *kopenapi3.T
 }
 
+// Unmarshal unmarshals the given resource into an OpenAPI 3 document.
 func (ns *Namespace) Unmarshal(r resource.UnmarshableResource) (*OpenAPIDocument, error) {
        key := r.Key()
        if key == "" {
index 98befa0618023885e937bb29f59fb7231fb7358c..399adb3749aa4056389f9d7e7cb57555ddce994f 100644 (file)
@@ -38,15 +38,15 @@ func TestReadFile(t *testing.T) {
        }{
                {filepath.FromSlash("/f/f1.txt"), "f1-content"},
                {filepath.FromSlash("f/f1.txt"), "f1-content"},
-               {filepath.FromSlash("../f2.txt"), false},
+               {filepath.FromSlash("../f2.txt"), ""},
                {"", false},
-               {"b", false},
+               {"b", ""},
        } {
 
                result, err := ns.ReadFile(test.filename)
 
                if bb, ok := test.expect.(bool); ok && !bb {
-                       b.Assert(err, qt.Not(qt.IsNil))
+                       b.Assert(err, qt.Not(qt.IsNil), qt.Commentf("filename: %q", test.filename))
                        continue
                }
 
index 378b97e0335a3e5793369f49d3cc4e2542d940cd..59add2152dab1edd079c898a5af42dabb7beb75f 100644 (file)
 package path
 
 import (
-       "fmt"
        _path "path"
        "path/filepath"
        "strings"
 
+       "github.com/gohugoio/hugo/common/paths"
        "github.com/gohugoio/hugo/deps"
        "github.com/spf13/cast"
 )
@@ -36,17 +36,6 @@ type Namespace struct {
        deps *deps.Deps
 }
 
-// DirFile holds the result from path.Split.
-type DirFile struct {
-       Dir  string
-       File string
-}
-
-// Used in test.
-func (df DirFile) String() string {
-       return fmt.Sprintf("%s|%s", df.Dir, df.File)
-}
-
 // Ext returns the file name extension used by path.
 // The extension is the suffix beginning at the final dot
 // in the final slash-separated element of path;
@@ -117,15 +106,15 @@ func (ns *Namespace) BaseName(path any) (string, error) {
 // The input path is passed into filepath.ToSlash converting any Windows slashes
 // to forward slashes.
 // The returned values have the property that path = dir+file.
-func (ns *Namespace) Split(path any) (DirFile, error) {
+func (ns *Namespace) Split(path any) (paths.DirFile, error) {
        spath, err := cast.ToStringE(path)
        if err != nil {
-               return DirFile{}, err
+               return paths.DirFile{}, err
        }
        spath = filepath.ToSlash(spath)
        dir, file := _path.Split(spath)
 
-       return DirFile{Dir: dir, File: file}, nil
+       return paths.DirFile{Dir: dir, File: file}, nil
 }
 
 // Join joins any number of path elements into a single path, adding a
index 599d8367a9747cca7eecbe029a9bc66d6649b25f..cc49bf28cff5663873d37cb99ef56e33a836dc7a 100644 (file)
@@ -18,6 +18,7 @@ import (
        "testing"
 
        qt "github.com/frankban/quicktest"
+       "github.com/gohugoio/hugo/common/paths"
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/deps"
 )
@@ -157,7 +158,7 @@ func TestJoin(t *testing.T) {
                        `baz/foo/bar.txt`,
                },
                {
-                       []any{"", "baz", DirFile{"big", "john"}, filepath.FromSlash(`foo/bar.txt`)},
+                       []any{"", "baz", paths.DirFile{Dir: "big", File: "john"}, filepath.FromSlash(`foo/bar.txt`)},
                        `baz/big|john/foo/bar.txt`,
                },
                {nil, ""},
@@ -186,10 +187,10 @@ func TestSplit(t *testing.T) {
                path   any
                expect any
        }{
-               {filepath.FromSlash(`foo/bar.txt`), DirFile{`foo/`, `bar.txt`}},
-               {filepath.FromSlash(`foo/bar/txt `), DirFile{`foo/bar/`, `txt `}},
-               {`foo.bar.txt`, DirFile{``, `foo.bar.txt`}},
-               {``, DirFile{``, ``}},
+               {filepath.FromSlash(`foo/bar.txt`), paths.DirFile{Dir: `foo/`, File: `bar.txt`}},
+               {filepath.FromSlash(`foo/bar/txt `), paths.DirFile{Dir: `foo/bar/`, File: `txt `}},
+               {`foo.bar.txt`, paths.DirFile{Dir: ``, File: `foo.bar.txt`}},
+               {``, paths.DirFile{Dir: ``, File: ``}},
                // errors
                {tstNoStringer{}, false},
        } {
index 9d663cb46d929d8b98916b868c11a6a7b48a47d1..85323f057f69330abb77e90be745a5a67f25dd43 100644 (file)
@@ -414,6 +414,7 @@ func (ns *Namespace) PostCSS(args ...any) (resource.Resource, error) {
        return ns.postcssClient.Process(r, m)
 }
 
+// PostProcess processes r after the build.
 func (ns *Namespace) PostProcess(r resource.Resource) (postpub.PostPublishedResource, error) {
        return ns.deps.ResourceSpec.PostProcess(r)
 }
index dd6267280fbda7383f75dcffe46b805cd91b8b27..e8da7b84b506aaee08e7e17fd312fcf5239492b8 100644 (file)
@@ -39,9 +39,9 @@ type htmlTag struct {
        openTag bool
 }
 
-// Truncate truncates a given string to the specified length.
-func (ns *Namespace) Truncate(a any, options ...any) (template.HTML, error) {
-       length, err := cast.ToIntE(a)
+// Truncate truncates the string in s to the specified length.
+func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {
+       length, err := cast.ToIntE(s)
        if err != nil {
                return "", err
        }
index 738750de70c35ac96c79201c1f7413b9947e1c1d..dd9249adef54d004776c4091ab59fbab710627f8 100644 (file)
@@ -11,6 +11,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+// Package tpl contains template functions and related types.
 package tpl
 
 import (