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 8788077
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 186 deletions.
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
10 changes: 8 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
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.

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
2 changes: 1 addition & 1 deletion hugolib/hugo_sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (cfg *BuildCfg) shouldRender(p *pageState) bool {
}

func (h *HugoSites) renderCrossSitesSitemap() error {
if !h.isMultiLingual() || h.IsMultihost() {
if !h.isMultiLingual() || h.Conf.IsMultihost() {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion hugolib/hugo_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestHello(t *testing.T) {
files := `
-- hugo.toml --
title: "Hello"
title = "Hello"
baseURL="https://example.org"
disableKinds = ["term", "taxonomy", "section", "page"]
-- content/p1.md --
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page__paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target
Kind: p.Kind(),
Sections: p.SectionsEntries(),
UglyURLs: false, // TODO1 s.uglyURLs(p),
ForcePrefix: s.h.IsMultihost() || alwaysInSubDir,
ForcePrefix: s.h.Conf.IsMultihost() || alwaysInSubDir,
Dir: dir,
URL: pm.urlPaths.URL,
}
Expand Down
11 changes: 6 additions & 5 deletions hugolib/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

hpaths "github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/common/urls"

"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/modules"
Expand All @@ -32,7 +33,7 @@ type Paths struct {
Fs *hugofs.Fs
Cfg config.AllProvider

BaseURL
// TODO1 get rid of these.
BaseURLString string
BaseURLNoPathString string

Expand All @@ -57,7 +58,7 @@ type Paths struct {

func New(fs *hugofs.Fs, cfg config.AllProvider) (*Paths, error) {
baseURLstr := "https://example.com" // TODOD1 cfg.GetString("baseURL")
baseURL, err := newBaseURLFromString(baseURLstr)
baseURL, err := urls.NewBaseURLFromString(baseURLstr)
if err != nil {
return nil, fmt.Errorf("Failed to create baseURL from %q:: %w", baseURLstr, err)
}
Expand Down Expand Up @@ -97,9 +98,9 @@ func New(fs *hugofs.Fs, cfg config.AllProvider) (*Paths, error) {
var baseURLNoPathString = baseURLNoPath.String()

p := &Paths{
Fs: fs,
Cfg: cfg,
BaseURL: baseURL,
Fs: fs,
Cfg: cfg,
// TODO1 BaseURL: baseURL,
BaseURLString: baseURLString,
BaseURLNoPathString: baseURLNoPathString,
AbsResourcesDir: absResourcesDir,
Expand Down
14 changes: 7 additions & 7 deletions hugolib/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ func (s *Site) createNodeMenuEntryURL(in string) string {
menuEntryURL := in
menuEntryURL = helpers.SanitizeURLKeepTrailingSlash(s.s.PathSpec.URLize(menuEntryURL))
if !s.conf.CanonifyURLs {
menuEntryURL = paths.AddContextRoot(s.s.PathSpec.BaseURL.String(), menuEntryURL)
menuEntryURL = paths.AddContextRoot(s.s.PathSpec.Cfg.BaseURL().String(), menuEntryURL)
}
return menuEntryURL
}
Expand Down Expand Up @@ -1214,7 +1214,7 @@ func (s *Site) assembleMenus() {

// get any language code to prefix the target file path with.
func (s *Site) getLanguageTargetPathLang(alwaysInSubDir bool) string {
if s.h.IsMultihost() {
if s.h.Conf.IsMultihost() {
return s.Language().Lang
}

Expand All @@ -1223,7 +1223,7 @@ func (s *Site) getLanguageTargetPathLang(alwaysInSubDir bool) string {

// get any lanaguagecode to prefix the relative permalink with.
func (s *Site) getLanguagePermalinkLang(alwaysInSubDir bool) string {
if !s.h.isMultiLingual() || s.h.IsMultihost() {
if !s.h.isMultiLingual() || s.h.Conf.IsMultihost() {
return ""
}

Expand Down Expand Up @@ -1316,15 +1316,15 @@ func (s *Site) GetPageWithTemplateInfo(info tpl.Info, ref ...string) (page.Page,
}

func (s *Site) permalink(link string) string {
return s.PathSpec.PermalinkForBaseURL(link, s.PathSpec.BaseURL.String())
return s.PathSpec.PermalinkForBaseURL(link, s.PathSpec.Cfg.BaseURL().String())
}

func (s *Site) absURLPath(targetPath string) string {
var path string
if s.conf.RelativeURLs {
path = helpers.GetDottedRelativePath(targetPath)
} else {
url := s.PathSpec.BaseURL.String()
url := s.PathSpec.Cfg.BaseURL().String()
if !strings.HasSuffix(url, "/") {
url += "/"
}
Expand Down Expand Up @@ -1401,8 +1401,8 @@ func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath s
pd.AbsURLPath = s.absURLPath(targetPath)
}

if s.running() && s.Cfg.GetBool("watch") && !s.Cfg.GetBool("disableLiveReload") {
pd.LiveReloadBaseURL = s.PathSpec.BaseURL.URL()
if s.running() && s.Cfg.GetBool("watch") && !s.Cfg.GetBool("disableLiveReload") { // TODOD1
pd.LiveReloadBaseURL = s.PathSpec.Cfg.BaseURL().URL()
if s.Cfg.GetInt("liveReloadPort") != -1 {
pd.LiveReloadBaseURL.Host = fmt.Sprintf("%s:%d", pd.LiveReloadBaseURL.Hostname(), s.Cfg.GetInt("liveReloadPort"))
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/site_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (s *Site) renderAliases() error {
// renderMainLanguageRedirect creates a redirect to the main language home,
// depending on if it lives in sub folder (e.g. /en) or not.
func (s *Site) renderMainLanguageRedirect() error {
if !s.h.isMultiLingual() || s.h.IsMultihost() {
if !s.h.isMultiLingual() || s.h.Conf.IsMultihost() {
// No need for a redirect
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions resources/page/page_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func (p TargetPaths) PermalinkForOutputFormat(s *helpers.PathSpec, f output.Form
var baseURL string
var err error
if f.Protocol != "" {
baseURL, err = s.BaseURL.WithProtocol(f.Protocol)
baseURL, err = s.Cfg.BaseURL().WithProtocol(f.Protocol)
if err != nil {
return ""
}
} else {
baseURL = s.BaseURL.String()
baseURL = s.Cfg.BaseURL().String()
}

return s.PermalinkForBaseURL(p.Link, baseURL)
Expand Down
Loading

0 comments on commit 8788077

Please sign in to comment.