From 5916b61be94e9c552173038853a37c346eabae6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 27 Jan 2026 18:46:52 +0100 Subject: [PATCH] Remove disableDate and disableLatLong from MetaConfig Since the meta config is new (and exif config is deprecated), remove these options from MetaConfig. The fields filter controls which metadata is extracted, including Date and GPS fields. The existing exif config options are preserved for backward compatibility. Closes #14437 Co-Authored-By: Claude Opus 4.5 --- hugolib/config_test.go | 2 +- resources/images/config.go | 8 ---- resources/images/image.go | 2 - resources/images/meta/meta.go | 21 +--------- .../images/meta/meta_integration_test.go | 41 +++++++++++++++---- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 2273c6afd..8af31a632 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -21,9 +21,9 @@ import ( "github.com/bep/logg" "github.com/gohugoio/hugo/common/hmaps" - "github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config/allconfig" + "github.com/gohugoio/hugo/htesting" qt "github.com/frankban/quicktest" "github.com/spf13/afero" diff --git a/resources/images/config.go b/resources/images/config.go index 42e07450d..c4e5f0c29 100644 --- a/resources/images/config.go +++ b/resources/images/config.go @@ -573,14 +573,6 @@ type MetaConfig struct { // Use ["**"] to include all fields. Fields []string - // Hugo extracts the "photo taken" date/time into .Date by default. - // Set this to true to turn it off. - DisableDate bool - - // Hugo extracts the "photo taken where" (GPS latitude and longitude) into - // .Long and .Lat. Set this to true to turn it off. - DisableLatLong bool - // Which metadata sources to include. // Valid values are "exif", "iptc", "xmp". // Default is ["exif", "iptc"] (XMP is excluded for performance reasons). diff --git a/resources/images/image.go b/resources/images/image.go index dfdae20c5..80648f5f2 100644 --- a/resources/images/image.go +++ b/resources/images/image.go @@ -139,8 +139,6 @@ func NewImageProcessor(warnl logg.LevelLogger, wasmDispatchers *warpc.Dispatcher m := cfg.Config.Imaging.Meta metaDecoder, err := meta.NewDecoder( - meta.WithDateDisabled(m.DisableDate), - meta.WithLatLongDisabled(m.DisableLatLong), meta.WithFields(m.Fields), meta.WithSources(m.Sources...), meta.WithWarnLogger(warnl), diff --git a/resources/images/meta/meta.go b/resources/images/meta/meta.go index f76b5d74e..54a711755 100644 --- a/resources/images/meta/meta.go +++ b/resources/images/meta/meta.go @@ -313,15 +313,6 @@ func (d *Decoder) DecodeMeta(filename string, format imagemeta.ImageFormat, r io } shouldHandleTag := func(ti imagemeta.TagInfo) bool { - // Always include time and GPS tags (needed for Date, Lat, Long extraction). - // These may be in EXIF, XMP, or IPTC depending on the image. - if !d.noDate && isTimeTag(ti.Tag) { - return true - } - if !d.noLatLong && isGPSTag(ti.Tag) { - return true - } - // For EXIF, only include tags from IFD0 (skip thumbnail data). if ti.Source == imagemeta.EXIF { if !strings.HasPrefix(ti.Namespace, "IFD0") { @@ -359,16 +350,8 @@ func (d *Decoder) DecodeMeta(filename string, format imagemeta.ImageFormat, r io return nil, err } - var tm time.Time - var lat, long float64 - - if !d.noDate { - tm, _ = tagInfos.GetDateTime() - } - - if !d.noLatLong { - lat, long, _ = tagInfos.GetLatLong() - } + tm, _ := tagInfos.GetDateTime() + lat, long, _ := tagInfos.GetLatLong() exifTags := make(map[string]any) iptcTags := make(map[string]any) diff --git a/resources/images/meta/meta_integration_test.go b/resources/images/meta/meta_integration_test.go index 4936faf5a..c44a186e1 100644 --- a/resources/images/meta/meta_integration_test.go +++ b/resources/images/meta/meta_integration_test.go @@ -14,6 +14,7 @@ func TestMeta(t *testing.T) { files := ` -- hugo.toml -- [imaging.meta] +fields = ['**'] sources = ['exif', 'iptc', 'xmp'] -- assets/sunset.jpg -- sourcefilename: ../../testdata/sunset.jpg @@ -87,8 +88,6 @@ func TestMetaConfig(t *testing.T) { -- hugo.toml -- [imaging] [imaging.meta] -disableDate = true -disableLatLong = true fields = ['! *{Model,ColorSpace,Metering}*'] sources = ['exif', 'iptc'] -- assets/sunset.jpg -- @@ -110,11 +109,9 @@ XMPCity: {{ with .XMP.City }}{{ . }}{{ else }}NOT_IN_SOURCE{{ end }} b := hugolib.Test(t, files) b.AssertFileContent("public/index.html", - // disableLatLong = true - "Lat: 0", - "Long: 0", - // disableDate = true - "Date: 0001-01-01", + "Lat: 36.597441", + "Long: -4.50846", + "Date: 2017-10-27", // Exif is included "ExifMake: RICOH IMAGING COMPANY, LTD.", // Model is excluded by fields pattern '! *Model*' @@ -126,6 +123,36 @@ XMPCity: {{ with .XMP.City }}{{ . }}{{ else }}NOT_IN_SOURCE{{ end }} ) } +func TestMetaFieldsFilterDateAndGPS(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +[imaging.meta] +fields = ['! GPS*', '! *Date*', '! *Time*'] +-- assets/sunset.jpg -- +sourcefilename: ../../testdata/sunset.jpg +-- layouts/home.html -- +{{ $img := resources.Get "sunset.jpg" }} +{{ $meta := $img.Meta }} +{{ with $meta }} +Lat: {{ .Lat }} +Long: {{ .Long }} +Date: {{ .Date.Format "2006-01-02" }} +ExifMake: {{ .Exif.Make }} +{{ end }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/index.html", + "Lat: 0", + "Long: 0", + "Date: 0001-01-01", + "ExifMake: RICOH IMAGING COMPANY, LTD.", + ) +} + // TestMetaXMPOnly verifies behavior when only XMP is configured as a source. // Note: Date and Lat/Long are extracted from whichever configured source contains them. // The test image has GPS/Date in EXIF only, so with XMP-only sources they will be empty. -- 2.39.5