]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Some godoc adjustments and image struct renames
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 21 Apr 2022 08:59:13 +0000 (10:59 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 27 Apr 2022 21:53:56 +0000 (23:53 +0200)
23 files changed:
hugolib/collections.go
langs/language.go
media/mediaType.go
navigation/menu.go
resources/errorResource.go
resources/image.go
resources/image_test.go
resources/images/exif/exif.go
resources/images/exif/exif_test.go
resources/images/image.go
resources/images/image_resource.go [new file with mode: 0644]
resources/page/page.go
resources/page/pagegroup.go
resources/page/pages.go
resources/page/site.go
resources/page/weighted.go
resources/resource.go
resources/resource/dates.go
resources/resource/resourcetypes.go
resources/testhelpers_test.go
resources/transform.go
resources/transform_test.go
tpl/images/images.go

index 933f7dadc6714dcf8250517b47fddfc3633b2c36..898d2ba12b80cd812e954e4f82055b3cb650178b 100644 (file)
@@ -27,7 +27,7 @@ var (
 // here as it makes it easier to get an idea of "type coverage". These
 // implementations have no value on their own.
 
-// Slice is not meant to be used externally. It's a bridge function
+// Slice is for internal use.
 func (p *pageState) Slice(items any) (any, error) {
        return page.ToPages(items)
 }
index 244f6a743e0ca66cc97486da51c478f9c7aff10e..a0294a10341654a839d6d221e2a46d0533b0ae4e 100644 (file)
@@ -55,21 +55,26 @@ type Language struct {
        Title             string
        Weight            int
 
+       // For internal use.
        Disabled bool
 
        // If set per language, this tells Hugo that all content files without any
        // language indicator (e.g. my-page.en.md) is in this language.
        // This is usually a path relative to the working dir, but it can be an
        // absolute directory reference. It is what we get.
+       // For internal use.
        ContentDir string
 
        // Global config.
+       // For internal use.
        Cfg config.Provider
 
        // Language specific config.
+       // For internal use.
        LocalCfg config.Provider
 
        // Composite config.
+       // For internal use.
        config.Provider
 
        // These are params declared in the [params] section of the language merged with the
@@ -91,6 +96,7 @@ type Language struct {
        initErr error
 }
 
+// For internal use.
 func (l *Language) String() string {
        return l.Lang
 }
@@ -233,6 +239,7 @@ func (l Languages) IsMultihost() bool {
 
 // SetParam sets a param with the given key and value.
 // SetParam is case-insensitive.
+// For internal use.
 func (l *Language) SetParam(k string, v any) {
        l.paramsMu.Lock()
        defer l.paramsMu.Unlock()
@@ -245,6 +252,7 @@ func (l *Language) SetParam(k string, v any) {
 // GetLocal gets a configuration value set on language level. It will
 // not fall back to any global value.
 // It will return nil if a value with the given key cannot be found.
+// For internal use.
 func (l *Language) GetLocal(key string) any {
        if l == nil {
                panic("language not set")
@@ -256,6 +264,7 @@ func (l *Language) GetLocal(key string) any {
        return nil
 }
 
+// For internal use.
 func (l *Language) Set(k string, v any) {
        k = strings.ToLower(k)
        if globalOnlySettings[k] {
@@ -265,11 +274,13 @@ func (l *Language) Set(k string, v any) {
 }
 
 // Merge is currently not supported for Language.
+// For internal use.
 func (l *Language) Merge(key string, value any) {
        panic("Not supported")
 }
 
 // IsSet checks whether the key is set in the language or the related config store.
+// For internal use.
 func (l *Language) IsSet(key string) bool {
        key = strings.ToLower(key)
        if !globalOnlySettings[key] {
index 1627a9d52dd5fda1dc39de1092b260aaab90f6a9..69bb9182acdc3d1522dc2fbcacbd05ee5a4f107c 100644 (file)
@@ -163,6 +163,7 @@ func (m Type) Type() string {
        return m.MainType + "/" + m.SubType
 }
 
+// For internal use.
 func (m Type) String() string {
        return m.Type()
 }
@@ -510,11 +511,13 @@ func DecodeTypes(mms ...map[string]any) (Types, error) {
 }
 
 // IsZero reports whether this Type represents a zero value.
+// For internal use.
 func (m Type) IsZero() bool {
        return m.SubType == ""
 }
 
 // MarshalJSON returns the JSON encoding of m.
+// For internal use.
 func (m Type) MarshalJSON() ([]byte, error) {
        type Alias Type
        return json.Marshal(&struct {
index b9fb46e70385163ccdf7408689b82fde247eec0f..02e1f8fec3fedde88b02099453b59912d76948ec 100644 (file)
@@ -156,6 +156,7 @@ func (m *MenuEntry) isSamePage(p Page) bool {
        return false
 }
 
+// For internal use.
 func (m *MenuEntry) MarshallMap(ime map[string]any) error {
        var err error
        for k, v := range ime {
index 50f0be371e2e7530ecfba894f9303220ffa0ad41..81375cc485a38cefad965c999863bb70ad87ee30 100644 (file)
@@ -19,6 +19,7 @@ import (
        "github.com/gohugoio/hugo/common/hugio"
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/media"
+       "github.com/gohugoio/hugo/resources/images"
        "github.com/gohugoio/hugo/resources/images/exif"
        "github.com/gohugoio/hugo/resources/resource"
 )
@@ -26,7 +27,7 @@ import (
 var (
        _ error = (*errorResource)(nil)
        // Imnage covers all current Resource implementations.
-       _ resource.Image = (*errorResource)(nil)
+       _ images.ImageResource = (*errorResource)(nil)
        // The list of user facing and exported interfaces in resource.go
        // Note that if we're missing some interface here, the user will still
        // get an error, but not as pretty.
@@ -98,27 +99,27 @@ func (e *errorResource) Width() int {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Crop(spec string) (resource.Image, error) {
+func (e *errorResource) Crop(spec string) (images.ImageResource, error) {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Fill(spec string) (resource.Image, error) {
+func (e *errorResource) Fill(spec string) (images.ImageResource, error) {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Fit(spec string) (resource.Image, error) {
+func (e *errorResource) Fit(spec string) (images.ImageResource, error) {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Resize(spec string) (resource.Image, error) {
+func (e *errorResource) Resize(spec string) (images.ImageResource, error) {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Filter(filters ...any) (resource.Image, error) {
+func (e *errorResource) Filter(filters ...any) (images.ImageResource, error) {
        panic(e.ResourceError)
 }
 
-func (e *errorResource) Exif() *exif.Exif {
+func (e *errorResource) Exif() *exif.ExifInfo {
        panic(e.ResourceError)
 }
 
index 86cc3251a17df22dc120cd10765e64abaa42c45c..253caf735f353bddd6f0aef92b6668a5226d6c92 100644 (file)
@@ -49,12 +49,12 @@ import (
 )
 
 var (
-       _ resource.Image  = (*imageResource)(nil)
-       _ resource.Source = (*imageResource)(nil)
-       _ resource.Cloner = (*imageResource)(nil)
+       _ images.ImageResource = (*imageResource)(nil)
+       _ resource.Source      = (*imageResource)(nil)
+       _ resource.Cloner      = (*imageResource)(nil)
 )
 
-// ImageResource represents an image resource.
+// imageResource represents an image resource.
 type imageResource struct {
        *images.Image
 
@@ -70,14 +70,14 @@ type imageResource struct {
 }
 
 type imageMeta struct {
-       Exif *exif.Exif
+       Exif *exif.ExifInfo
 }
 
-func (i *imageResource) Exif() *exif.Exif {
+func (i *imageResource) Exif() *exif.ExifInfo {
        return i.root.getExif()
 }
 
-func (i *imageResource) getExif() *exif.Exif {
+func (i *imageResource) getExif() *exif.ExifInfo {
        i.metaInit.Do(func() {
                supportsExif := i.Format == images.JPEG || i.Format == images.TIFF
                if !supportsExif {
@@ -137,6 +137,7 @@ func (i *imageResource) getExif() *exif.Exif {
        return i.meta.Exif
 }
 
+// Cloneis for internal use.
 func (i *imageResource) Clone() resource.Resource {
        gr := i.baseResource.Clone().(baseResource)
        return &imageResource{
@@ -170,7 +171,7 @@ func (i *imageResource) cloneWithUpdates(u *transformationUpdate) (baseResource,
 // Resize resizes the image to the specified width and height using the specified resampling
 // filter and returns the transformed image. If one of width or height is 0, the image aspect
 // ratio is preserved.
-func (i *imageResource) Resize(spec string) (resource.Image, error) {
+func (i *imageResource) Resize(spec string) (images.ImageResource, error) {
        conf, err := i.decodeImageConfig("resize", spec)
        if err != nil {
                return nil, err
@@ -182,8 +183,8 @@ func (i *imageResource) Resize(spec string) (resource.Image, error) {
 }
 
 // Crop the image to the specified dimensions without resizing using the given anchor point.
-// Space delimited config: 200x300 TopLeft
-func (i *imageResource) Crop(spec string) (resource.Image, error) {
+// Space delimited config, e.g. `200x300 TopLeft`.
+func (i *imageResource) Crop(spec string) (images.ImageResource, error) {
        conf, err := i.decodeImageConfig("crop", spec)
        if err != nil {
                return nil, err
@@ -196,7 +197,7 @@ func (i *imageResource) Crop(spec string) (resource.Image, error) {
 
 // Fit scales down the image using the specified resample filter to fit the specified
 // maximum width and height.
-func (i *imageResource) Fit(spec string) (resource.Image, error) {
+func (i *imageResource) Fit(spec string) (images.ImageResource, error) {
        conf, err := i.decodeImageConfig("fit", spec)
        if err != nil {
                return nil, err
@@ -209,8 +210,8 @@ func (i *imageResource) Fit(spec string) (resource.Image, error) {
 
 // Fill scales the image to the smallest possible size that will cover the specified dimensions,
 // crops the resized image to the specified dimensions using the given anchor point.
-// Space delimited config: 200x300 TopLeft
-func (i *imageResource) Fill(spec string) (resource.Image, error) {
+// Space delimited config, e.g. `200x300 TopLeft`.
+func (i *imageResource) Fill(spec string) (images.ImageResource, error) {
        conf, err := i.decodeImageConfig("fill", spec)
        if err != nil {
                return nil, err
@@ -238,7 +239,7 @@ func (i *imageResource) Fill(spec string) (resource.Image, error) {
        return img, err
 }
 
-func (i *imageResource) Filter(filters ...any) (resource.Image, error) {
+func (i *imageResource) Filter(filters ...any) (images.ImageResource, error) {
        conf := images.GetDefaultImageConfig("filter", i.Proc.Cfg)
 
        var gfilters []gift.Filter
@@ -264,7 +265,7 @@ const imageProcWorkers = 1
 
 var imageProcSem = make(chan bool, imageProcWorkers)
 
-func (i *imageResource) doWithImageConfig(conf images.ImageConfig, f func(src image.Image) (image.Image, error)) (resource.Image, error) {
+func (i *imageResource) doWithImageConfig(conf images.ImageConfig, f func(src image.Image) (image.Image, error)) (images.ImageResource, error) {
        img, err := i.getSpec().imageCache.getOrCreate(i, conf, func() (*imageResource, image.Image, error) {
                imageProcSem <- true
                defer func() {
index a7577e0a6840ef93b5c56c511484e74cee003d64..0bfef1db09fae3c2e48a0659603d63d1252c4603 100644 (file)
@@ -40,7 +40,6 @@ import (
 
        "github.com/gohugoio/hugo/media"
        "github.com/gohugoio/hugo/resources/images"
-       "github.com/gohugoio/hugo/resources/resource"
        "github.com/google/go-cmp/cmp"
 
        "github.com/gohugoio/hugo/htesting/hqt"
@@ -76,7 +75,7 @@ func TestImageTransformBasic(t *testing.T) {
 
        fileCache := image.(specProvider).getSpec().FileCaches.ImageCache().Fs
 
-       assertWidthHeight := func(img resource.Image, w, h int) {
+       assertWidthHeight := func(img images.ImageResource, w, h int) {
                c.Helper()
                c.Assert(img, qt.Not(qt.IsNil))
                c.Assert(img.Width(), qt.Equals, w)
@@ -162,7 +161,7 @@ func TestImageTransformFormat(t *testing.T) {
 
        fileCache := image.(specProvider).getSpec().FileCaches.ImageCache().Fs
 
-       assertExtWidthHeight := func(img resource.Image, ext string, w, h int) {
+       assertExtWidthHeight := func(img images.ImageResource, ext string, w, h int) {
                c.Helper()
                c.Assert(img, qt.Not(qt.IsNil))
                c.Assert(paths.Ext(img.RelPermalink()), qt.Equals, ext)
@@ -210,13 +209,13 @@ func TestImagePermalinkPublishOrder(t *testing.T) {
                                os.Remove(workDir)
                        }()
 
-                       check1 := func(img resource.Image) {
+                       check1 := func(img images.ImageResource) {
                                resizedLink := "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_100x50_resize_q75_box.jpg"
                                c.Assert(img.RelPermalink(), qt.Equals, resizedLink)
                                assertImageFile(c, spec.PublishFs, resizedLink, 100, 50)
                        }
 
-                       check2 := func(img resource.Image) {
+                       check2 := func(img images.ImageResource) {
                                c.Assert(img.RelPermalink(), qt.Equals, "/a/sunset.jpg")
                                assertImageFile(c, spec.PublishFs, "a/sunset.jpg", 900, 562)
                        }
@@ -231,7 +230,7 @@ func TestImagePermalinkPublishOrder(t *testing.T) {
                        resized, err := orignal.Resize("100x50")
                        c.Assert(err, qt.IsNil)
 
-                       check1(resized.(resource.Image))
+                       check1(resized.(images.ImageResource))
 
                        if !checkOriginalFirst {
                                check2(orignal)
@@ -441,9 +440,9 @@ func TestImageExif(t *testing.T) {
        c := qt.New(t)
        fs := afero.NewMemMapFs()
        spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
-       image := fetchResourceForSpec(spec, c, "sunset.jpg").(resource.Image)
+       image := fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
 
-       getAndCheckExif := func(c *qt.C, image resource.Image) {
+       getAndCheckExif := func(c *qt.C, image images.ImageResource) {
                x := image.Exif()
                c.Assert(x, qt.Not(qt.IsNil))
 
@@ -464,22 +463,22 @@ func TestImageExif(t *testing.T) {
        }
 
        getAndCheckExif(c, image)
-       image = fetchResourceForSpec(spec, c, "sunset.jpg").(resource.Image)
+       image = fetchResourceForSpec(spec, c, "sunset.jpg").(images.ImageResource)
        // This will read from file cache.
        getAndCheckExif(c, image)
 }
 
 func BenchmarkImageExif(b *testing.B) {
-       getImages := func(c *qt.C, b *testing.B, fs afero.Fs) []resource.Image {
+       getImages := func(c *qt.C, b *testing.B, fs afero.Fs) []images.ImageResource {
                spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
-               images := make([]resource.Image, b.N)
+               imgs := make([]images.ImageResource, b.N)
                for i := 0; i < b.N; i++ {
-                       images[i] = fetchResourceForSpec(spec, c, "sunset.jpg", strconv.Itoa(i)).(resource.Image)
+                       imgs[i] = fetchResourceForSpec(spec, c, "sunset.jpg", strconv.Itoa(i)).(images.ImageResource)
                }
-               return images
+               return imgs
        }
 
-       getAndCheckExif := func(c *qt.C, image resource.Image) {
+       getAndCheckExif := func(c *qt.C, image images.ImageResource) {
                x := image.Exif()
                c.Assert(x, qt.Not(qt.IsNil))
                c.Assert(x.Long, qt.Equals, float64(-4.50846))
index 2841bd153bf43117c0ad47fe0fa89b58de455933..487f250d519b54da44ae67e06ead733c44d68e86 100644 (file)
@@ -32,10 +32,18 @@ import (
 
 const exifTimeLayout = "2006:01:02 15:04:05"
 
-type Exif struct {
-       Lat  float64
+// ExifInfo holds the decoded Exif data for an Image.
+type ExifInfo struct {
+       // GPS latitude in degrees.
+       Lat float64
+
+       // GPS longitude in degrees.
        Long float64
+
+       // Image creation date/time.
        Date time.Time
+
+       // A collection of the available Exif tags for this Image.
        Tags Tags
 }
 
@@ -106,7 +114,7 @@ func NewDecoder(options ...func(*Decoder) error) (*Decoder, error) {
        return d, nil
 }
 
-func (d *Decoder) Decode(r io.Reader) (ex *Exif, err error) {
+func (d *Decoder) Decode(r io.Reader) (ex *ExifInfo, err error) {
        defer func() {
                if r := recover(); r != nil {
                        err = fmt.Errorf("Exif failed: %v", r)
@@ -139,7 +147,7 @@ func (d *Decoder) Decode(r io.Reader) (ex *Exif, err error) {
                return
        }
 
-       ex = &Exif{Lat: lat, Long: long, Date: tm, Tags: walker.vals}
+       ex = &ExifInfo{Lat: lat, Long: long, Date: tm, Tags: walker.vals}
 
        return
 }
index 0cb9f67044929d50daf7e48f64e855f89f0dd8be..cd5961404296089dd13619c995b157cf5a0ec4eb 100644 (file)
@@ -56,7 +56,7 @@ func TestExif(t *testing.T) {
        // Verify that it survives a round-trip to JSON and back.
        data, err := json.Marshal(x)
        c.Assert(err, qt.IsNil)
-       x2 := &Exif{}
+       x2 := &ExifInfo{}
        err = json.Unmarshal(data, x2)
 
        c.Assert(x2, eq, x)
index 25deda9256d1d06c221c5be7e0f75b63917b59b2..e8cca7769886d1fe743fec157e9473418dc10a43 100644 (file)
@@ -192,7 +192,7 @@ type ImageProcessor struct {
        exifDecoder *exif.Decoder
 }
 
-func (p *ImageProcessor) DecodeExif(r io.Reader) (*exif.Exif, error) {
+func (p *ImageProcessor) DecodeExif(r io.Reader) (*exif.ExifInfo, error) {
        return p.exifDecoder.Decode(r)
 }
 
diff --git a/resources/images/image_resource.go b/resources/images/image_resource.go
new file mode 100644 (file)
index 0000000..e0fec15
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2022 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 images
+
+import (
+       "image"
+
+       "github.com/gohugoio/hugo/resources/images/exif"
+       "github.com/gohugoio/hugo/resources/resource"
+)
+
+// ImageResource represents an image resource.
+type ImageResource interface {
+       resource.Resource
+       ImageResourceOps
+}
+
+type ImageResourceOps interface {
+       // Height returns the height of the Image.
+       Height() int
+       // Width returns the width of the Image.
+       Width() int
+
+       // Crop an image to match the given dimensions without resizing.
+       // You must provide both width and height.
+       // Use the anchor option to change the crop box anchor point.
+       //    {{ $image := $image.Crop "600x400" }}
+       Crop(spec string) (ImageResource, error)
+       Fill(spec string) (ImageResource, error)
+       Fit(spec string) (ImageResource, error)
+       Resize(spec string) (ImageResource, error)
+
+       // Filter applies one or more filters to an Image.
+       //    {{ $image := $image.Filter (images.GaussianBlur 6) (images.Pixelate 8) }}
+       Filter(filters ...any) (ImageResource, error)
+
+       // Exif returns an ExifInfo object containing Image metadata.
+       Exif() *exif.ExifInfo
+
+       // Internal
+       DecodeImage() (image.Image, error)
+}
index 5ddacc8a6096bbf25d7b636ca4d95234653f6671..50459c4655fb4f8ef810ff6b62a486523a390029 100644 (file)
@@ -161,8 +161,7 @@ type PageMetaProvider interface {
        // Aliases forms the base for redirects generation.
        Aliases() []string
 
-       // BundleType returns the bundle type: "leaf", "branch" or an empty string if it is none.
-       // See https://gohugo.io/content-management/page-bundles/
+       // BundleType returns the bundle type: `leaf`, `branch` or an empty string.
        BundleType() files.ContentClass
 
        // A configured description.
index 1d9827907636921801ee7cb7baf8817fc8176066..3b32a1fae2dbacb83615b52bbefa5e450d972e96 100644 (file)
@@ -40,7 +40,10 @@ var (
 // PageGroup represents a group of pages, grouped by the key.
 // The key is typically a year or similar.
 type PageGroup struct {
+       // The key, typically a year or similar.
        Key any
+
+       // The Pages in this group.
        Pages
 }
 
@@ -361,6 +364,7 @@ func (p Pages) GroupByParamDate(key string, format string, order ...string) (Pag
 }
 
 // ProbablyEq wraps compare.ProbablyEqer
+// For internal use.
 func (p PageGroup) ProbablyEq(other any) bool {
        otherP, ok := other.(PageGroup)
        if !ok {
@@ -374,7 +378,7 @@ func (p PageGroup) ProbablyEq(other any) bool {
        return p.Pages.ProbablyEq(otherP.Pages)
 }
 
-// Slice is not meant to be used externally. It's a bridge function
+// Slice is for internal use.
 // for the template functions. See collections.Slice.
 func (p PageGroup) Slice(in any) (any, error) {
        switch items := in.(type) {
index 4db6a4f684b9e84233a99ead4f7680370987eb08..f47af5114758a06c06087a207d22d95d0d949e3a 100644 (file)
@@ -22,9 +22,11 @@ import (
        "github.com/gohugoio/hugo/resources/resource"
 )
 
-// Pages is a slice of pages. This is the most common list type in Hugo.
+// Pages is a slice of Page objects. This is the most common list type in Hugo.
 type Pages []Page
 
+// String returns a string representation of the list.
+// For internal use.
 func (ps Pages) String() string {
        return fmt.Sprintf("Pages(%d)", len(ps))
 }
@@ -37,7 +39,8 @@ func (ps Pages) shuffle() {
        }
 }
 
-// ToResources wraps resource.ResourcesConverter
+// ToResources wraps resource.ResourcesConverter.
+// For internal use.
 func (pages Pages) ToResources() resource.Resources {
        r := make(resource.Resources, len(pages))
        for i, p := range pages {
@@ -86,10 +89,12 @@ func ToPages(seq any) (Pages, error) {
        return nil, fmt.Errorf("cannot convert type %T to Pages", seq)
 }
 
+// Group groups the pages in in by key.
+// This implements collections.Grouper.
 func (p Pages) Group(key any, in any) (any, error) {
        pages, err := ToPages(in)
        if err != nil {
-               return nil, err
+               return PageGroup{}, err
        }
        return PageGroup{Key: key, Pages: pages}, nil
 }
@@ -100,6 +105,7 @@ func (p Pages) Len() int {
 }
 
 // ProbablyEq wraps compare.ProbablyEqer
+// For internal use.
 func (pages Pages) ProbablyEq(other any) bool {
        otherPages, ok := other.(Pages)
        if !ok {
index b84f179142c41a83adc8af178bd25adac6f69a89..f5806280c8f9aa7c1e78de66650692f62e2b4d61 100644 (file)
@@ -29,21 +29,52 @@ import (
 // Site represents a site in the build. This is currently a very narrow interface,
 // but the actual implementation will be richer, see hugolib.SiteInfo.
 type Site interface {
+       // Returns the Language configured for this Site.
        Language() *langs.Language
+
+       // Returns all the regular Pages in this Site.
        RegularPages() Pages
+
+       // Returns all Pages in this Site.
        Pages() Pages
+
+       // A shortcut to the home page.
        Home() Page
+
+       // Returns true if we're running in a server.
        IsServer() bool
+
+       // Returns the server port.
        ServerPort() int
+
+       // Returns the configured title for this Site.
        Title() string
+
+       // Returns all Sites for all languages.
        Sites() Sites
+
+       // Returns Site currently rendering.
        Current() Site
+
+       // Returns a struct with some information about the build.
        Hugo() hugo.Info
+
+       // Returns the BaseURL for this Site.
        BaseURL() template.URL
+
+       // Retuns a taxonomy map.
        Taxonomies() any
+
+       // Returns the last modification date of the content.
        LastChange() time.Time
+
+       // Returns the Menus for this site.
        Menus() navigation.Menus
+
+       // Returns the Params configured for this site.
        Params() maps.Params
+
+       // Returns a map of all the data inside /data.
        Data() map[string]any
 }
 
index 5ae2636d4a3768e3210c2c60eba58deced3fce77..39034d26c8fae15248873f54a5ed37d0a382d387 100644 (file)
@@ -63,7 +63,7 @@ func (w WeightedPage) String() string {
        return fmt.Sprintf("WeightedPage(%d,%q)", w.Weight, w.Page.Title())
 }
 
-// Slice is not meant to be used externally. It's a bridge function
+// Slice is for internal use.
 // for the template functions. See collections.Slice.
 func (p WeightedPage) Slice(in any) (any, error) {
        switch items := in.(type) {
index 77cc11ddecbd824e88784762437c433866417775..01f20f09d2f547ef52e91bd17f6438688ec0a3aa 100644 (file)
@@ -161,7 +161,7 @@ type baseResource interface {
 type commonResource struct {
 }
 
-// Slice is not meant to be used externally. It's a bridge function
+// Slice is for internal use.
 // for the template functions. See collections.Slice.
 func (commonResource) Slice(in any) (any, error) {
        switch items := in.(type) {
index f26c44787b48b5cd5b01c4c3f63c74225d0b8264..b43f35c641a79885d028a97d6a38df131edb2b4a 100644 (file)
@@ -20,9 +20,16 @@ var _ Dated = Dates{}
 // Dated wraps a "dated resource". These are the 4 dates that makes
 // the date logic in Hugo.
 type Dated interface {
+       // Date returns the date of the resource.
        Date() time.Time
+
+       // Lastmod returns the last modification date of the resource.
        Lastmod() time.Time
+
+       // PublishDate returns the publish date of the resource.
        PublishDate() time.Time
+
+       // ExpiryDate returns the expiration date of the resource.
        ExpiryDate() time.Time
 }
 
index a4f820188c1c70016dcf9e181e85cdd267dd19e2..e3251aabe2234e18fef89741bea1cfff7fa39bfd 100644 (file)
 package resource
 
 import (
-       "image"
-
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/langs"
        "github.com/gohugoio/hugo/media"
-       "github.com/gohugoio/hugo/resources/images/exif"
 
        "github.com/gohugoio/hugo/common/hugio"
 )
@@ -82,26 +79,6 @@ type Resource interface {
        ErrProvider
 }
 
-// Image represents an image resource.
-type Image interface {
-       Resource
-       ImageOps
-}
-
-type ImageOps interface {
-       Height() int
-       Width() int
-       Crop(spec string) (Image, error)
-       Fill(spec string) (Image, error)
-       Fit(spec string) (Image, error)
-       Resize(spec string) (Image, error)
-       Filter(filters ...any) (Image, error)
-       Exif() *exif.Exif
-
-       // Internal
-       DecodeImage() (image.Image, error)
-}
-
 type ResourceTypeProvider interface {
        // ResourceType is the resource type. For most file types, this is the main
        // part of the MIME type, e.g. "image", "application", "text" etc.
index 1f7e5f93cec822e80c14b23b70fd82a499f18e00..3a4e7e5805e4ae4080dc3586533fde04b94843c1 100644 (file)
@@ -20,6 +20,7 @@ import (
        "github.com/gohugoio/hugo/hugofs"
        "github.com/gohugoio/hugo/media"
        "github.com/gohugoio/hugo/output"
+       "github.com/gohugoio/hugo/resources/images"
        "github.com/gohugoio/hugo/resources/page"
        "github.com/gohugoio/hugo/resources/resource"
        "github.com/spf13/afero"
@@ -131,19 +132,19 @@ func newTestResourceOsFs(c *qt.C) (*Spec, string) {
        return spec, workDir
 }
 
-func fetchSunset(c *qt.C) resource.Image {
+func fetchSunset(c *qt.C) images.ImageResource {
        return fetchImage(c, "sunset.jpg")
 }
 
-func fetchImage(c *qt.C, name string) resource.Image {
+func fetchImage(c *qt.C, name string) images.ImageResource {
        spec := newTestResourceSpec(specDescriptor{c: c})
        return fetchImageForSpec(spec, c, name)
 }
 
-func fetchImageForSpec(spec *Spec, c *qt.C, name string) resource.Image {
+func fetchImageForSpec(spec *Spec, c *qt.C, name string) images.ImageResource {
        r := fetchResourceForSpec(spec, c, name)
 
-       img := r.(resource.Image)
+       img := r.(images.ImageResource)
 
        c.Assert(img, qt.Not(qt.IsNil))
        c.Assert(img.(specProvider).getSpec(), qt.Not(qt.IsNil))
index 9b69ee37a1244eefefd8f3812ba232a697ab653f..e269b7b10d61d31145c03cc6fb32d86b6dc27d6f 100644 (file)
@@ -26,6 +26,7 @@ import (
 
        "github.com/pkg/errors"
 
+       "github.com/gohugoio/hugo/resources/images"
        "github.com/gohugoio/hugo/resources/images/exif"
        "github.com/spf13/afero"
 
@@ -176,19 +177,19 @@ func (r *resourceAdapter) Data() any {
        return r.target.Data()
 }
 
-func (r *resourceAdapter) Crop(spec string) (resource.Image, error) {
+func (r *resourceAdapter) Crop(spec string) (images.ImageResource, error) {
        return r.getImageOps().Crop(spec)
 }
 
-func (r *resourceAdapter) Fill(spec string) (resource.Image, error) {
+func (r *resourceAdapter) Fill(spec string) (images.ImageResource, error) {
        return r.getImageOps().Fill(spec)
 }
 
-func (r *resourceAdapter) Fit(spec string) (resource.Image, error) {
+func (r *resourceAdapter) Fit(spec string) (images.ImageResource, error) {
        return r.getImageOps().Fit(spec)
 }
 
-func (r *resourceAdapter) Filter(filters ...any) (resource.Image, error) {
+func (r *resourceAdapter) Filter(filters ...any) (images.ImageResource, error) {
        return r.getImageOps().Filter(filters...)
 }
 
@@ -196,7 +197,7 @@ func (r *resourceAdapter) Height() int {
        return r.getImageOps().Height()
 }
 
-func (r *resourceAdapter) Exif() *exif.Exif {
+func (r *resourceAdapter) Exif() *exif.ExifInfo {
        return r.getImageOps().Exif()
 }
 
@@ -241,7 +242,7 @@ func (r *resourceAdapter) RelPermalink() string {
        return r.target.RelPermalink()
 }
 
-func (r *resourceAdapter) Resize(spec string) (resource.Image, error) {
+func (r *resourceAdapter) Resize(spec string) (images.ImageResource, error) {
        return r.getImageOps().Resize(spec)
 }
 
@@ -281,8 +282,8 @@ func (r *resourceAdapter) DecodeImage() (image.Image, error) {
        return r.getImageOps().DecodeImage()
 }
 
-func (r *resourceAdapter) getImageOps() resource.ImageOps {
-       img, ok := r.target.(resource.ImageOps)
+func (r *resourceAdapter) getImageOps() images.ImageResourceOps {
+       img, ok := r.target.(images.ImageResourceOps)
        if !ok {
                panic(fmt.Sprintf("%T is not an image", r.target))
        }
index cf0a7d421ac20bba81ba62cc0d77e73de391c382..af8ccbc1fe1d5b0e05ed3c141f8ab6dadd65b975 100644 (file)
@@ -29,6 +29,7 @@ import (
        "github.com/gohugoio/hugo/hugofs"
 
        "github.com/gohugoio/hugo/media"
+       "github.com/gohugoio/hugo/resources/images"
        "github.com/gohugoio/hugo/resources/internal"
 
        "github.com/gohugoio/hugo/helpers"
@@ -361,7 +362,7 @@ func TestTransform(t *testing.T) {
                c.Assert(err, qt.IsNil)
                c.Assert(tr.MediaType(), eq, media.PNGType)
 
-               img, ok := tr.(resource.Image)
+               img, ok := tr.(images.ImageResource)
                c.Assert(ok, qt.Equals, true)
 
                c.Assert(img.Width(), qt.Equals, 75)
index ad3b5d9b3a8555706d9b63365e1ce2542824ccf7..20af019cf61d605f799c942c2043f163832d5920 100644 (file)
@@ -21,7 +21,6 @@ import (
        "github.com/pkg/errors"
 
        "github.com/gohugoio/hugo/resources/images"
-       "github.com/gohugoio/hugo/resources/resource"
 
        // Importing image codecs for image.DecodeConfig
        _ "image/gif"
@@ -92,12 +91,12 @@ func (ns *Namespace) Config(path any) (image.Config, error) {
        return config, nil
 }
 
-func (ns *Namespace) Filter(args ...any) (resource.Image, error) {
+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")
        }
 
-       img := args[len(args)-1].(resource.Image)
+       img := args[len(args)-1].(images.ImageResource)
        filtersv := args[:len(args)-1]
 
        return img.Filter(filtersv...)