Compare commits

..

1 commit

Author SHA1 Message Date
0xB10C 9beb61416c
Merge cf5d0c1f91 into bbc6888d02 2024-04-17 21:29:18 +09:00
15 changed files with 57 additions and 188 deletions

View file

@ -140,25 +140,16 @@ func (c *Cache) DrainEvictedIdentities() []identity.Identity {
} }
// ClearMatching clears all partition for which the predicate returns true. // ClearMatching clears all partition for which the predicate returns true.
func (c *Cache) ClearMatching(predicatePartition func(k string, p PartitionManager) bool, predicateValue func(k, v any) bool) { func (c *Cache) ClearMatching(predicate func(k, v any) bool) {
if predicatePartition == nil {
predicatePartition = func(k string, p PartitionManager) bool { return true }
}
if predicateValue == nil {
panic("nil predicateValue")
}
g := rungroup.Run[PartitionManager](context.Background(), rungroup.Config[PartitionManager]{ g := rungroup.Run[PartitionManager](context.Background(), rungroup.Config[PartitionManager]{
NumWorkers: len(c.partitions), NumWorkers: len(c.partitions),
Handle: func(ctx context.Context, partition PartitionManager) error { Handle: func(ctx context.Context, partition PartitionManager) error {
partition.clearMatching(predicateValue) partition.clearMatching(predicate)
return nil return nil
}, },
}) })
for k, p := range c.partitions { for _, p := range c.partitions {
if !predicatePartition(k, p) {
continue
}
g.Enqueue(p) g.Enqueue(p)
} }
@ -365,7 +356,6 @@ func GetOrCreatePartition[K comparable, V any](c *Cache, name string, opts Optio
trace: c.opts.Log.Logger().WithLevel(logg.LevelTrace).WithField("partition", name), trace: c.opts.Log.Logger().WithLevel(logg.LevelTrace).WithField("partition", name),
opts: opts, opts: opts,
} }
c.partitions[name] = partition c.partitions[name] = partition
return partition return partition

View file

@ -156,7 +156,7 @@ func TestClear(t *testing.T) {
cache = newTestCache(t) cache = newTestCache(t)
cache.ClearMatching(nil, func(k, v any) bool { cache.ClearMatching(func(k, v any) bool {
return k.(string) == "clearOnRebuild" return k.(string) == "clearOnRebuild"
}) })

View file

@ -128,7 +128,6 @@ type rootCommand struct {
verbose bool verbose bool
debug bool debug bool
quiet bool quiet bool
devMode bool // Hidden flag.
renderToMemory bool renderToMemory bool
@ -424,33 +423,29 @@ func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
func (r *rootCommand) createLogger(running bool) (loggers.Logger, error) { func (r *rootCommand) createLogger(running bool) (loggers.Logger, error) {
level := logg.LevelWarn level := logg.LevelWarn
if r.devMode { if r.logLevel != "" {
level = logg.LevelTrace switch strings.ToLower(r.logLevel) {
case "debug":
level = logg.LevelDebug
case "info":
level = logg.LevelInfo
case "warn", "warning":
level = logg.LevelWarn
case "error":
level = logg.LevelError
default:
return nil, fmt.Errorf("invalid log level: %q, must be one of debug, warn, info or error", r.logLevel)
}
} else { } else {
if r.logLevel != "" { if r.verbose {
switch strings.ToLower(r.logLevel) { hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
case "debug": hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
level = logg.LevelDebug level = logg.LevelInfo
case "info": }
level = logg.LevelInfo
case "warn", "warning":
level = logg.LevelWarn
case "error":
level = logg.LevelError
default:
return nil, fmt.Errorf("invalid log level: %q, must be one of debug, warn, info or error", r.logLevel)
}
} else {
if r.verbose {
hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
hugo.Deprecate("--verbose", "use --logLevel info", "v0.114.0")
level = logg.LevelInfo
}
if r.debug { if r.debug {
hugo.Deprecate("--debug", "use --logLevel debug", "v0.114.0") hugo.Deprecate("--debug", "use --logLevel debug", "v0.114.0")
level = logg.LevelDebug level = logg.LevelDebug
}
} }
} }
@ -510,13 +505,10 @@ Complete documentation is available at https://gohugo.io/.`
cmd.PersistentFlags().BoolVarP(&r.verbose, "verbose", "v", false, "verbose output") cmd.PersistentFlags().BoolVarP(&r.verbose, "verbose", "v", false, "verbose output")
cmd.PersistentFlags().BoolVarP(&r.debug, "debug", "", false, "debug output") cmd.PersistentFlags().BoolVarP(&r.debug, "debug", "", false, "debug output")
cmd.PersistentFlags().BoolVarP(&r.devMode, "devMode", "", false, "only used for internal testing, flag hidden.")
cmd.PersistentFlags().StringVar(&r.logLevel, "logLevel", "", "log level (debug|info|warn|error)") cmd.PersistentFlags().StringVar(&r.logLevel, "logLevel", "", "log level (debug|info|warn|error)")
_ = cmd.RegisterFlagCompletionFunc("logLevel", cobra.FixedCompletions([]string{"debug", "info", "warn", "error"}, cobra.ShellCompDirectiveNoFileComp)) _ = cmd.RegisterFlagCompletionFunc("logLevel", cobra.FixedCompletions([]string{"debug", "info", "warn", "error"}, cobra.ShellCompDirectiveNoFileComp))
cmd.Flags().BoolVarP(&r.buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed") cmd.Flags().BoolVarP(&r.buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
cmd.PersistentFlags().MarkHidden("devMode")
// Configure local flags // Configure local flags
applyLocalFlagsBuild(cmd, r) applyLocalFlagsBuild(cmd, r)

View file

@ -45,10 +45,9 @@ func newGenCommand() *genCommand {
genmandir string genmandir string
// Chroma flags. // Chroma flags.
style string style string
highlightStyle string highlightStyle string
lineNumbersInlineStyle string linesStyle string
lineNumbersTableStyle string
) )
newChromaStyles := func() simplecobra.Commander { newChromaStyles := func() simplecobra.Commander {
@ -64,11 +63,8 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
if highlightStyle != "" { if highlightStyle != "" {
builder.Add(chroma.LineHighlight, highlightStyle) builder.Add(chroma.LineHighlight, highlightStyle)
} }
if lineNumbersInlineStyle != "" { if linesStyle != "" {
builder.Add(chroma.LineNumbers, lineNumbersInlineStyle) builder.Add(chroma.LineNumbers, linesStyle)
}
if lineNumbersTableStyle != "" {
builder.Add(chroma.LineNumbersTable, lineNumbersTableStyle)
} }
style, err := builder.Build() style, err := builder.Build()
if err != nil { if err != nil {
@ -82,12 +78,10 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
cmd.ValidArgsFunction = cobra.NoFileCompletions cmd.ValidArgsFunction = cobra.NoFileCompletions
cmd.PersistentFlags().StringVar(&style, "style", "friendly", "highlighter style (see https://xyproto.github.io/splash/docs/)") cmd.PersistentFlags().StringVar(&style, "style", "friendly", "highlighter style (see https://xyproto.github.io/splash/docs/)")
_ = cmd.RegisterFlagCompletionFunc("style", cobra.NoFileCompletions) _ = cmd.RegisterFlagCompletionFunc("style", cobra.NoFileCompletions)
cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", `foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff"`) cmd.PersistentFlags().StringVar(&highlightStyle, "highlightStyle", "", "style used for highlighting lines (see https://github.com/alecthomas/chroma)")
_ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions) _ = cmd.RegisterFlagCompletionFunc("highlightStyle", cobra.NoFileCompletions)
cmd.PersistentFlags().StringVar(&lineNumbersInlineStyle, "lineNumbersInlineStyle", "", `foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff"`) cmd.PersistentFlags().StringVar(&linesStyle, "linesStyle", "", "style used for line numbers (see https://github.com/alecthomas/chroma)")
_ = cmd.RegisterFlagCompletionFunc("lineNumbersInlineStyle", cobra.NoFileCompletions) _ = cmd.RegisterFlagCompletionFunc("linesStyle", cobra.NoFileCompletions)
cmd.PersistentFlags().StringVar(&lineNumbersTableStyle, "lineNumbersTableStyle", "", `foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff"`)
_ = cmd.RegisterFlagCompletionFunc("lineNumbersTableStyle", cobra.NoFileCompletions)
}, },
} }
} }

View file

@ -17,7 +17,7 @@ package hugo
// This should be the only one. // This should be the only one.
var CurrentVersion = Version{ var CurrentVersion = Version{
Major: 0, Major: 0,
Minor: 125, Minor: 126,
PatchLevel: 2, PatchLevel: 0,
Suffix: "", Suffix: "-DEV",
} }

View file

@ -20,11 +20,10 @@ hugo gen chromastyles [flags] [args]
### Options ### Options
``` ```
-h, --help help for chromastyles -h, --help help for chromastyles
--highlightStyle string foreground and background colors for highlighted lines, e.g. --highlightStyle "#fff000 bg:#000fff" --highlightStyle string style used for highlighting lines (see https://github.com/alecthomas/chroma)
--lineNumbersInlineStyle string foreground and background colors for inline line numbers, e.g. --lineNumbersInlineStyle "#fff000 bg:#000fff" --linesStyle string style used for line numbers (see https://github.com/alecthomas/chroma)
--lineNumbersTableStyle string foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff" --style string highlighter style (see https://xyproto.github.io/splash/docs/) (default "friendly")
--style string highlighter style (see https://xyproto.github.io/splash/docs/) (default "friendly")
``` ```
### Options inherited from parent commands ### Options inherited from parent commands

View file

@ -16,7 +16,6 @@ package hqt
import ( import (
"errors" "errors"
"fmt" "fmt"
"math"
"reflect" "reflect"
"strings" "strings"
@ -39,11 +38,6 @@ var IsSameType qt.Checker = &typeChecker{
argNames: []string{"got", "want"}, argNames: []string{"got", "want"},
} }
// IsSameFloat64 asserts that two float64 values are equal within a small delta.
var IsSameFloat64 = qt.CmpEquals(cmp.Comparer(func(a, b float64) bool {
return math.Abs(a-b) < 0.0001
}))
type argNames []string type argNames []string
func (a argNames) ArgNames() []string { func (a argNames) ArgNames() []string {

View file

@ -1084,7 +1084,7 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
return b return b
} }
h.MemCache.ClearMatching(nil, shouldDelete) h.MemCache.ClearMatching(shouldDelete)
return ll, nil return ll, nil
}); err != nil { }); err != nil {

View file

@ -23,7 +23,6 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"sync"
"time" "time"
"github.com/bep/logg" "github.com/bep/logg"
@ -47,7 +46,6 @@ import (
"github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/page/siteidentities" "github.com/gohugoio/hugo/resources/page/siteidentities"
"github.com/gohugoio/hugo/resources/postpub" "github.com/gohugoio/hugo/resources/postpub"
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -760,45 +758,15 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
} }
} }
case files.ComponentFolderAssets: case files.ComponentFolderAssets:
p := pathInfo.Path() logger.Println("Asset changed", 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 var hasID bool
for _, r := range matches { r, _ := h.ResourceSpec.ResourceCache.Get(context.Background(), dynacache.CleanKey(pathInfo.Base()))
identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool { identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool {
hasID = true hasID = true
changes = append(changes, rid) changes = append(changes, rid)
return false return false
}) })
}
if !hasID { if !hasID {
changes = append(changes, pathInfo) changes = append(changes, pathInfo)
} }

View file

@ -676,37 +676,3 @@ menu: main
b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`) b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
b.AssertLogNotContains("WARN") b.AssertLogNotContains("WARN")
} }
func TestSectionPagesIssue12399(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['rss','sitemap','taxonomy','term']
capitalizeListTitles = false
pluralizeListTitles = false
sectionPagesMenu = 'main'
-- content/p1.md --
---
title: p1
---
-- content/s1/p2.md --
---
title: p2
menus: main
---
-- content/s1/p3.md --
---
title: p3
---
-- layouts/_default/list.html --
{{ range site.Menus.main }}<a href="{{ .URL }}">{{ .Name }}</a>{{ end }}
-- layouts/_default/single.html --
{{ .Title }}
`
b := Test(t, files)
b.AssertFileExists("public/index.html", true)
b.AssertFileContent("public/index.html", `<a href="/s1/p2/">p2</a><a href="/s1/">s1</a>`)
}

View file

@ -659,7 +659,7 @@ func (s *Site) assembleMenus() error {
if sectionPagesMenu != "" { if sectionPagesMenu != "" {
if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) { if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) {
if p.Kind() != kinds.KindSection || !p.m.shouldBeCheckedForMenuDefinitions() { if p.IsHome() || !p.m.shouldBeCheckedForMenuDefinitions() {
return false, nil return false, nil
} }

View file

@ -1,8 +1,7 @@
# Release env. # Release env.
# These will be replaced by script before release. # These will be replaced by script before release.
HUGORELEASER_TAG=v0.125.1 HUGORELEASER_TAG=v0.125.0
HUGORELEASER_COMMITISH=68c5ad638c2072969e47262926b912e80fd71a77 HUGORELEASER_COMMITISH=a32400b5f4e704daf7de19f44584baf77a4501ab

View file

@ -18,7 +18,6 @@ import (
"testing" "testing"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/htesting/hqt"
) )
func TestHexStringToColor(t *testing.T) { func TestHexStringToColor(t *testing.T) {
@ -120,8 +119,8 @@ func TestReplaceColorInPalette(t *testing.T) {
func TestColorLuminance(t *testing.T) { func TestColorLuminance(t *testing.T) {
c := qt.New(t) c := qt.New(t)
c.Assert(hexStringToColor("#000000").Luminance(), hqt.IsSameFloat64, 0.0) c.Assert(hexStringToColor("#000000").Luminance(), qt.Equals, 0.0)
c.Assert(hexStringToColor("#768a9a").Luminance(), hqt.IsSameFloat64, 0.24361603589088263) c.Assert(hexStringToColor("#768a9a").Luminance(), qt.Equals, 0.24361603589088263)
c.Assert(hexStringToColor("#d5bc9f").Luminance(), hqt.IsSameFloat64, 0.5261577672685374) c.Assert(hexStringToColor("#d5bc9f").Luminance(), qt.Equals, 0.5261577672685374)
c.Assert(hexStringToColor("#ffffff").Luminance(), hqt.IsSameFloat64, 1.0) c.Assert(hexStringToColor("#ffffff").Luminance(), qt.Equals, 1.0)
} }

View file

@ -327,34 +327,3 @@ Styles: {{ $r.RelPermalink }}
b.AssertFileContent("public/index.html", "Styles: /scss/main.css") b.AssertFileContent("public/index.html", "Styles: /scss/main.css")
} }
func TestRebuildAssetGetMatch(t *testing.T) {
t.Parallel()
if !scss.Supports() {
t.Skip()
}
files := `
-- assets/scss/main.scss --
b {
color: red;
}
-- layouts/index.html --
{{ $r := resources.GetMatch "scss/main.scss" | toCSS }}
T1: {{ $r.Content }}
`
b := hugolib.NewIntegrationTestBuilder(
hugolib.IntegrationTestConfig{
T: t,
TxtarString: files,
NeedsOsFS: true,
Running: true,
}).Build()
b.AssertFileContent("public/index.html", `color: red`)
b.EditFiles("assets/scss/main.scss", `b { color: blue; }`).Build()
b.AssertFileContent("public/index.html", `color: blue`)
}

View file

@ -22,7 +22,6 @@ Renders an embedded YouTube video.
*/}} */}}
{{- $pc := .Page.Site.Config.Privacy.YouTube }} {{- $pc := .Page.Site.Config.Privacy.YouTube }}
{{- $remoteErrID := "err-youtube-remote" }}
{{- if not $pc.Disable }} {{- if not $pc.Disable }}
{{- with $id := or (.Get "id") (.Get 0) }} {{- with $id := or (.Get "id") (.Get 0) }}
@ -32,12 +31,12 @@ Renders an embedded YouTube video.
{{- $data := dict }} {{- $data := dict }}
{{- with resources.GetRemote $url }} {{- with resources.GetRemote $url }}
{{- with .Err }} {{- with .Err }}
{{- erroridf $remoteErrID "The %q shortcode was unable to get remote resource %q. %s. See %s" $.Name $url . $.Position }} {{- errorf "The %q shortcode was unable to get remote resource %q. %s. See %s" $.Name $url . $.Position }}
{{- else }} {{- else }}
{{- $data = .Content | transform.Unmarshal }} {{- $data = .Content | transform.Unmarshal }}
{{- end }} {{- end }}
{{- else }} {{- else }}
{{- erroridf $remoteErrID "The %q shortcode was unable to get remote resource %q. See %s" $.Name $url $.Position }} {{- errorf "The %q shortcode was unable to get remote resource %q. See %s" $.Name $url $.Position }}
{{- end }} {{- end }}
{{/* Set defaults. */}} {{/* Set defaults. */}}