Skip to content

Commit

Permalink
Add integrity, fingerprint etc. filters for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jun 18, 2018
1 parent 187621a commit e8ab8f5
Show file tree
Hide file tree
Showing 34 changed files with 1,328 additions and 147 deletions.
38 changes: 37 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@
[[constraint]]
name = "github.com/bep/debounce"
version = "^1.1.0"

[[constraint]]
name = "github.com/tdewolff/minify"
version = "^2.3.5"


[[constraint]]
name = "github.com/tdewolff/parse"
version = "2.3.3"
8 changes: 6 additions & 2 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ func (c *commandeer) getDirList() ([]string, error) {
// SymbolicWalk will log anny ERRORs
// Also note that the Dirnames fetched below will contain any relevant theme
// directories.
for _, contentDir := range c.hugo.PathSpec.BaseFs.AbsContentDirs {
_ = helpers.SymbolicWalk(c.Fs.Source, contentDir.Value, symLinkWalker)
for _, contentDir := range c.hugo.PathSpec.BaseFs.Content.Dirnames {
_ = helpers.SymbolicWalk(c.Fs.Source, contentDir, symLinkWalker)
}

for _, staticDir := range c.hugo.PathSpec.BaseFs.Data.Dirnames {
Expand All @@ -574,6 +574,10 @@ func (c *commandeer) getDirList() ([]string, error) {
}
}

for _, assetDir := range c.hugo.PathSpec.BaseFs.Assets.Dirnames {
_ = helpers.SymbolicWalk(c.Fs.Source, assetDir, regularWalker)
}

if len(nested) > 0 {
for {

Expand Down
22 changes: 21 additions & 1 deletion deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/metrics"
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/source"
"github.com/gohugoio/hugo/tpl"
jww "github.com/spf13/jwalterweatherman"
Expand Down Expand Up @@ -42,6 +44,9 @@ type Deps struct {
// The SourceSpec to use
SourceSpec *source.SourceSpec `json:"-"`

// The Resource Spec to use
ResourceSpec *resource.Spec

// The configuration to use
Cfg config.Provider `json:"-"`

Expand Down Expand Up @@ -129,6 +134,11 @@ func New(cfg DepsCfg) (*Deps, error) {
return nil, err
}

resourceSpec, err := resource.NewSpec(ps, cfg.MediaTypes)
if err != nil {
return nil, err
}

contentSpec, err := helpers.NewContentSpec(cfg.Language)
if err != nil {
return nil, err
Expand All @@ -153,6 +163,7 @@ func New(cfg DepsCfg) (*Deps, error) {
PathSpec: ps,
ContentSpec: contentSpec,
SourceSpec: sp,
ResourceSpec: resourceSpec,
Cfg: cfg.Language,
Language: cfg.Language,
Timeout: time.Duration(timeoutms) * time.Millisecond,
Expand All @@ -167,7 +178,8 @@ func New(cfg DepsCfg) (*Deps, error) {

// ForLanguage creates a copy of the Deps with the language dependent
// parts switched out.
func (d Deps) ForLanguage(l *langs.Language) (*Deps, error) {
func (d Deps) ForLanguage(cfg DepsCfg) (*Deps, error) {
l := cfg.Language
var err error

d.PathSpec, err = helpers.NewPathSpecWithBaseBaseFsProvided(d.Fs, l, d.BaseFs)
Expand All @@ -180,6 +192,11 @@ func (d Deps) ForLanguage(l *langs.Language) (*Deps, error) {
return nil, err
}

d.ResourceSpec, err = resource.NewSpec(d.PathSpec, cfg.MediaTypes)
if err != nil {
return nil, err
}

d.Cfg = l
d.Language = l

Expand Down Expand Up @@ -212,6 +229,9 @@ type DepsCfg struct {
// The configuration to use.
Cfg config.Provider

// The media types configured.
MediaTypes media.Types

// Template handling.
TemplateProvider ResourceProvider
WithTemplate func(templ tpl.TemplateHandler) error
Expand Down
84 changes: 84 additions & 0 deletions hugofs/basepath_real_filename_fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2018 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 hugofs

import (
"os"

"github.com/spf13/afero"
)

// RealFilenameInfo is a thin wrapper around os.FileInfo adding the real filename.
type RealFilenameInfo interface {
os.FileInfo

// This is the real filename to the file in the underlying filesystem.
RealFilename() string
}

type realFilenameInfo struct {
os.FileInfo
realFilename string
}

func (f *realFilenameInfo) RealFilename() string {
return f.realFilename
}

func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
return &BasePathRealFilenameFs{BasePathFs: base}
}

// This is a thin wrapper around afero.BasePathFs that provides the real filename
// in Stat and LstatIfPossible.
type BasePathRealFilenameFs struct {
*afero.BasePathFs
}

func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
fi, err := b.BasePathFs.Stat(name)
if err != nil {
return nil, err
}

if _, ok := fi.(RealFilenameInfo); ok {
return fi, nil
}

filename, err := b.RealPath(name)
if err != nil {
return nil, &os.PathError{Op: "stat", Path: name, Err: err}
}

return &realFilenameInfo{FileInfo: fi, realFilename: filename}, nil
}

func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {

fi, ok, err := b.BasePathFs.LstatIfPossible(name)
if err != nil {
return nil, false, err
}

if _, ok := fi.(RealFilenameInfo); ok {
return fi, ok, nil
}

filename, err := b.RealPath(name)
if err != nil {
return nil, false, &os.PathError{Op: "lstat", Path: name, Err: err}
}

return &realFilenameInfo{FileInfo: fi, realFilename: filename}, ok, nil
}
2 changes: 1 addition & 1 deletion hugolib/alias_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Hugo Authors. All rights reserved.
// Copyright 2018 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.
Expand Down
1 change: 1 addition & 0 deletions hugolib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func loadDefaultSettingsFor(v *viper.Viper) error {
v.SetDefault("metaDataFormat", "toml")
v.SetDefault("contentDir", "content")
v.SetDefault("layoutDir", "layouts")
v.SetDefault("assetDir", "assets")
v.SetDefault("staticDir", "static")
v.SetDefault("resourceDir", "resources")
v.SetDefault("archetypeDir", "archetypes")
Expand Down
Loading

0 comments on commit e8ab8f5

Please sign in to comment.