Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 20, 2023
1 parent 8f55893 commit 3e39d23
Show file tree
Hide file tree
Showing 33 changed files with 143 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion commands/commandeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c *commandeer) loadConfig() error {
if configPath == "" {
configPath = dir
}
res, err := hugolib.LoadConfigNew(
res, err := hugolib.LoadConfig(
hugolib.ConfigSourceDescriptor{
Flags: c.Cfg,
Fs: sourceFs,
Expand Down
2 changes: 1 addition & 1 deletion common/urls/baseURL.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (b BaseURL) URL() *url.URL {
return &c
}

func newBaseURLFromString(b string) (BaseURL, error) {
func NewBaseURLFromString(b string) (BaseURL, error) {
var result BaseURL

base, err := url.Parse(b)
Expand Down
10 changes: 5 additions & 5 deletions common/urls/baseURL_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func TestBaseURL(t *testing.T) {
c := qt.New(t)
b, err := newBaseURLFromString("http://example.com")
b, err := NewBaseURLFromString("http://example.com")
c.Assert(err, qt.IsNil)
c.Assert(b.String(), qt.Equals, "http://example.com")

Expand All @@ -36,7 +36,7 @@ func TestBaseURL(t *testing.T) {
_, err = b.WithProtocol("mailto:")
c.Assert(err, qt.Not(qt.IsNil))

b, err = newBaseURLFromString("mailto:hugo@rules.com")
b, err = NewBaseURLFromString("mailto:hugo@rules.com")
c.Assert(err, qt.IsNil)
c.Assert(b.String(), qt.Equals, "mailto:hugo@rules.com")

Expand All @@ -51,16 +51,16 @@ func TestBaseURL(t *testing.T) {

// Test with "non-URLs". Some people will try to use these as a way to get
// relative URLs working etc.
b, err = newBaseURLFromString("/")
b, err = NewBaseURLFromString("/")
c.Assert(err, qt.IsNil)
c.Assert(b.String(), qt.Equals, "/")

b, err = newBaseURLFromString("")
b, err = NewBaseURLFromString("")
c.Assert(err, qt.IsNil)
c.Assert(b.String(), qt.Equals, "")

// BaseURL with sub path
b, err = newBaseURLFromString("http://example.com/sub")
b, err = NewBaseURLFromString("http://example.com/sub")
c.Assert(err, qt.IsNil)
c.Assert(b.String(), qt.Equals, "http://example.com/sub")
c.Assert(b.HostURL(), qt.Equals, "http://example.com")
Expand Down
17 changes: 15 additions & 2 deletions config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/privacy"
"github.com/gohugoio/hugo/config/security"
"github.com/gohugoio/hugo/config/services"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugolib/paths"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/markup/markup_config"
"github.com/gohugoio/hugo/media"
Expand Down Expand Up @@ -163,8 +163,14 @@ func (c *Config) Compile() error {
disabledLangs[lang] = true
}

baseURL, err := urls.NewBaseURLFromString(c.BaseURL)
if err != nil {
return err
}

c.C = ConfigCompiled{
Timeout: timeout,
BaseURL: baseURL,
DisabledKinds: disabledKinds,
DisabledLanguages: disabledLangs,
KindOutputFormats: kindOutputFormats,
Expand All @@ -185,7 +191,7 @@ func (c Config) IsLangDisabled(lang string) bool {
// ConfigCompiled holds values and functions that are derived from the config.
type ConfigCompiled struct {
Timeout time.Duration
BaseURL paths.BaseURL
BaseURL urls.BaseURL
KindOutputFormats map[string]output.Formats
DisabledKinds map[string]bool
DisabledLanguages map[string]bool
Expand Down Expand Up @@ -333,6 +339,10 @@ type RootConfig struct {
// It defaults to AP Stylebook for title casing, but you can also set it to Chicago or Go (every word starts with a capital letter).
TitleCaseStyle string

// TODO1 doc these. Move?
Watch bool
DisableLiveReload bool

// The odd constructs below are kept for backwards compatibility.
// Deprecated: Use module mount config instead.
// TODO1 handle strings.
Expand Down Expand Up @@ -580,6 +590,9 @@ func decodeConfigFromParams(fs afero.Fs, bcfg config.BaseConfig, cfg maps.Params
},
"params": func() error {
all.Params = cfg.GetStringMap("params")
if all.Params == nil {
all.Params = make(map[string]interface{})
}
return nil
},
"permalinks": func() error {
Expand Down
117 changes: 0 additions & 117 deletions config/compositeConfig.go

This file was deleted.

40 changes: 0 additions & 40 deletions config/compositeConfig_test.go

This file was deleted.

23 changes: 0 additions & 23 deletions helpers/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import (
"strings"
"testing"

"github.com/spf13/afero"

"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/config"

qt "github.com/frankban/quicktest"
)

Expand Down Expand Up @@ -63,24 +58,6 @@ func TestBytesToHTML(t *testing.T) {
c.Assert(BytesToHTML([]byte("dobedobedo")), qt.Equals, template.HTML("dobedobedo"))
}

func TestNewContentSpec(t *testing.T) {
cfg := config.NewWithTestDefaults()
c := qt.New(t)

cfg.Set("summaryLength", 32)
cfg.Set("buildFuture", true)
cfg.Set("buildExpired", true)
cfg.Set("buildDrafts", true)

spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil)

c.Assert(err, qt.IsNil)
c.Assert(spec.summaryLength, qt.Equals, 32)
c.Assert(spec.BuildFuture, qt.Equals, true)
c.Assert(spec.BuildExpired, qt.Equals, true)
c.Assert(spec.BuildDrafts, qt.Equals, true)
}

var benchmarkTruncateString = strings.Repeat("This is a sentence about nothing.", 20)

func BenchmarkTestTruncateWordsToWholeSentence(b *testing.B) {
Expand Down
2 changes: 1 addition & 1 deletion helpers/pathspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewPathSpecWithBaseBaseFsProvided(fs *hugofs.Fs, cfg config.AllProvider, lo
ProcessingStats: NewProcessingStats(p.Lang()),
}

basePath := ps.BaseURL.Path()
basePath := cfg.BaseURL().Path()
if basePath != "" && basePath != "/" {
ps.BasePath = basePath
}
Expand Down
Loading

0 comments on commit 3e39d23

Please sign in to comment.