Repository: gohugoio/hugo (language: go)

Issue:
 Non-content entry to a menu with a relative URL produces a rendering error 
There is a bug in non-content menu implementation that results in a broken link to a file if a relative URL is used in a config file menu entry. For example, if the `config.toml` file looks as follows:

```
baseurl = "http://my_site.com"
CanonifyUrls = true
[[menu.extramedia]]
    name = "Presentation: Three Steps to Enrollment"
    url = "/media/enrollment-sessions.ppt"
    weight = -120
    identifier = "PowerPoint"
```

the rendered link to the .ppt file looks like

```
http://my_site.com/media/enrollment-sessions/index.ppt/
```

However, if the absolute URL is used instead of the relative one, the resulting URL is OK. i.e. 

```
baseurl = "http://my_site.com"
CanonifyUrls = true
[[menu.extramedia]]
    name = "Presentation: Three Steps to Enrollment"
    url = "http://my_site.com/media/enrollment-sessions.ppt"
    weight = -120
    identifier = "PowerPoint"
```

renders to 

```
http://my_site.com/media/enrollment-sessions.ppt/
```

Related thread in Hugo Discussion is [here](http://discuss.gohugo.io/t/non-content-entry-to-a-menu-rendering-error/1386).

Browser does not refresh after changing Sass collected with Match
The issue title is imperfect... it is certainly not true in the general sense. There's something about ranging through a slice of Sass files that's triggering this.

Reference: <https://discourse.gohugo.io/t/scss-changes-do-not-reload-live/49591>

This works as expected in v0.122.0, but fails with v0.123.0 and later.

```text
git clone --single-branch -b hugo-forum-topic-49591 https://github.com/jmooring/hugo-testing hugo-forum-topic-49591
cd hugo-forum-topic-49591
hugo server
```

Browse to http://localhost:1313/, then make changes to assets/dir/b.scss.

Results:

- Expected: home page shows changes.
- Actual: no change.

Note that changes to assets/a.scss are shown immediately.

---

```text
assets/
├── dir/
│   └── b.scss
└── a.scss
```

layouts/partials/css.html

```text
{{ $a := slice (resources.Get "a.scss") }}
{{ $b := resources.Match "dir/*.scss" }}

{{/* Add styles in a specific order. */}}
{{ $styles := slice $a $b }}

{{ $stylesheets := slice }}
  {{ range $styles }}
  {{ $stylesheets = $stylesheets | collections.Append . }}
{{ end }}

{{ range $stylesheets }}
  {{ with . | resources.ToCSS | fingerprint }}
    <link as="style"  href="{{ .RelPermalink }}" rel="preload stylesheet">
  {{ end }}
{{ end }}
```



Discussion / hints:
@spf13 - I think I'm gonna remove the transformation of the menu urls. It is a slightly breaking change, but it was a bad idea in the first place. People are smart enough to get the URLs correct. Agree?

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
That looks like an odd construct, but I will have a look at it and fix it. 

Note that most of these issues can be worked around with a cache buster entry.


Fix patch:
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index c96629cd6fd..6a9afee9994 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -23,11 +23,9 @@ import (
 	"path"
 	"path/filepath"
 	"strings"
-	"sync"
 	"time"
 
 	"github.com/bep/logg"
-	"github.com/gohugoio/hugo/cache/dynacache"
 	"github.com/gohugoio/hugo/deps"
 	"github.com/gohugoio/hugo/hugofs"
 	"github.com/gohugoio/hugo/hugofs/files"
@@ -47,7 +45,6 @@ import (
 	"github.com/gohugoio/hugo/resources/page"
 	"github.com/gohugoio/hugo/resources/page/siteidentities"
 	"github.com/gohugoio/hugo/resources/postpub"
-	"github.com/gohugoio/hugo/resources/resource"
 
 	"github.com/spf13/afero"
 
@@ -764,48 +761,8 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
 				}
 			}
 		case files.ComponentFolderAssets:
-			p := pathInfo.Path()
-			logger.Println("Asset changed", p)
-
-			var matches []any
-			var mu sync.Mutex
-
-			h.MemCache.ClearMatching(
-				func(k string, pm dynacache.PartitionManager) bool {
-					// Avoid going through everything.
-					return strings.HasPrefix(k, "/res")
-				},
-				func(k, v any) bool {
-					if strings.Contains(k.(string), p) {
-						mu.Lock()
-						defer mu.Unlock()
-						switch vv := v.(type) {
-						case resource.Resources:
-							// GetMatch/Match.
-							for _, r := range vv {
-								matches = append(matches, r)
-							}
-							return true
-						default:
-							matches = append(matches, vv)
-							return true
-
-						}
-					}
-					return false
-				})
-
-			var hasID bool
-			for _, r := range matches {
-				identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool {
-					hasID = true
-					changes = append(changes, rid)
-					return false
-				})
-			}
-			if !hasID {
-				changes = append(changes, pathInfo)
-			}
+			logger.Println("Asset changed", pathInfo.Path())
+			changes = append(changes, pathInfo)
 		case files.ComponentFolderData:
 			logger.Println("Data changed", pathInfo.Path())
 
diff --git a/resources/transform.go b/resources/transform.go
index b498924f584..9adec38cca9 100644
--- a/resources/transform.go
+++ b/resources/transform.go
@@ -49,6 +49,7 @@ var (
 	_ resource.ReadSeekCloserResource    = (*resourceAdapter)(nil)
 	_ resource.Resource                  = (*resourceAdapter)(nil)
 	_ resource.Staler                    = (*resourceAdapterInner)(nil)
+	_ identity.IdentityGroupProvider     = (*resourceAdapterInner)(nil)
 	_ resource.Source                    = (*resourceAdapter)(nil)
 	_ resource.Identifier                = (*resourceAdapter)(nil)
 	_ resource.ResourceNameTitleProvider = (*resourceAdapter)(nil)
@@ -657,6 +658,10 @@ type resourceAdapterInner struct {
 	*publishOnce
 }
 
+func (r *resourceAdapterInner) GetIdentityGroup() identity.Identity {
+	return r.target.GetIdentityGroup()
+}
+
 func (r *resourceAdapterInner) StaleVersion() uint32 {
 	// Both of these are incremented on change.
 	return r.Staler.StaleVersion() + r.target.StaleVersion()


Test patch:
diff --git a/resources/resource_transformers/tocss/scss/scss_integration_test.go b/resources/resource_transformers/tocss/scss/scss_integration_test.go
index 02e2b920000..46946387202 100644
--- a/resources/resource_transformers/tocss/scss/scss_integration_test.go
+++ b/resources/resource_transformers/tocss/scss/scss_integration_test.go
@@ -1,4 +1,4 @@
-// Copyright 2021 The Hugo Authors. All rights reserved.
+// Copyright 2024 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.
@@ -328,6 +328,7 @@ Styles: {{ $r.RelPermalink }}
 	b.AssertFileContent("public/index.html", "Styles: /scss/main.css")
 }
 
+// Issue #1239.
 func TestRebuildAssetGetMatch(t *testing.T) {
 	t.Parallel()
 	if !scss.Supports() {
@@ -358,3 +359,61 @@ T1: {{ $r.Content }}
 
 	b.AssertFileContent("public/index.html", `color: blue`)
 }
+
+func TestRebuildAssetMatchIssue12456(t *testing.T) {
+	t.Parallel()
+	if !scss.Supports() {
+		t.Skip()
+	}
+
+	files := `
+-- hugo.toml --
+disableKinds = ["term", "taxonomy", "section", "page"]
+disableLiveReload = true
+-- assets/a.scss --
+h1 {
+	color: red;
+}
+-- assets/dir/b.scss --
+h2 {
+	color: blue;
+}
+-- assets/dir/c.scss --
+h3 {
+	color: green;
+}
+-- layouts/index.html --
+{{ $a := slice (resources.Get "a.scss") }}
+{{ $b := resources.Match "dir/*.scss" }}
+
+{{/* Add styles in a specific order. */}}
+{{ $styles := slice $a $b }}
+
+{{ $stylesheets := slice }}
+  {{ range $styles }}
+  {{ $stylesheets = $stylesheets | collections.Append . }}
+{{ end }}
+
+
+{{ range $stylesheets }}
+  {{ with . | resources.ToCSS | fingerprint }}
+    <link as="style"  href="{{ .RelPermalink }}" rel="preload stylesheet">
+  {{ end }}
+{{ end }}
+	`
+
+	b := hugolib.NewIntegrationTestBuilder(
+		hugolib.IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+			NeedsOsFS:   true,
+			Running:     true,
+			// LogLevel:    logg.LevelTrace,
+		}).Build()
+
+	b.AssertFileContent("public/index.html", `b.60a9f3bdc189ee8a857afd5b7e1b93ad1644de0873761a7c9bc84f781a821942.css`)
+
+	b.EditFiles("assets/dir/b.scss", `h2 { color: orange; }`).Build()
+
+	b.AssertFileContent("public/index.html", `b.46b2d77c7ffe37ee191678f72df991ecb1319f849957151654362f09b0ef467f.css`)
+}