Support PostProcess for all file types

Not just HTML.

Fixes #10269
This commit is contained in:
Bjørn Erik Pedersen
2022-09-14 11:58:45 +02:00
parent 1fd4c562af
commit 74daca6b30
9 changed files with 265 additions and 24 deletions

20
deps/deps.go vendored
View File

@@ -16,6 +16,7 @@ import (
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/postpub"
"github.com/gohugoio/hugo/metrics"
"github.com/gohugoio/hugo/output"
@@ -78,6 +79,10 @@ type Deps struct {
// All the output formats available for the current site.
OutputFormatsConfig output.Formats
// FilenameHasPostProcessPrefix is a set of filenames in /public that
// contains a post-processing prefix.
FilenameHasPostProcessPrefix []string
templateProvider ResourceProvider
WithTemplate func(templ tpl.TemplateManager) error `json:"-"`
@@ -202,6 +207,7 @@ func New(cfg DepsCfg) (*Deps, error) {
var (
logger = cfg.Logger
fs = cfg.Fs
d *Deps
)
if cfg.TemplateProvider == nil {
@@ -239,6 +245,18 @@ func New(cfg DepsCfg) (*Deps, error) {
}
execHelper := hexec.New(securityConfig)
var filenameHasPostProcessPrefixMu sync.Mutex
cb := func(name string, match bool) {
if !match {
return
}
filenameHasPostProcessPrefixMu.Lock()
d.FilenameHasPostProcessPrefix = append(d.FilenameHasPostProcessPrefix, name)
filenameHasPostProcessPrefixMu.Unlock()
}
fs.PublishDir = hugofs.NewHasBytesReceiver(fs.PublishDir, cb, []byte(postpub.PostProcessPrefix))
ps, err := helpers.NewPathSpec(fs, cfg.Language, logger)
if err != nil {
return nil, fmt.Errorf("create PathSpec: %w", err)
@@ -274,7 +292,7 @@ func New(cfg DepsCfg) (*Deps, error) {
logDistinct := helpers.NewDistinctLogger(logger)
d := &Deps{
d = &Deps{
Fs: fs,
Log: ignorableLogger,
LogDistinct: logDistinct,