Backtestshugorun-20261007-020926#14625
Make default baseUrl https://example.org/
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches make the default baseURL https://example.org/. Patch A puts it in `newDefaultConfig()`, the function that already holds Hugo's other defaults (taxonomies, sitemap, environment). User config, language config and the `--baseURL` flag then override it through the normal merge. Patch B instead overwrites an empty `c.BaseURL` inside `CompileConfig`. That works, but it replaces any empty value, including one the user set explicitly, and it hides a default inside compilation logic instead of the defaults table. It also leaves the raw config value empty for any code that reads it before compilation. Patch A's placement addresses the root cause more cleanly. Tests: Patch A adds focused integration tests for the default value (checking both `Configs.Base.BaseURL` and the per-site compiled BaseURL), the multilingual non-multihost case, and an explicit override. It also adds a command testscript covering the `--baseURL` flag and a server testscript showing the default is rewritten to localhost in `hugo server`. That is much broader scenario coverage. Patch B adds one simple test for set, unset and "/" cases. Its other test changes mostly pin `baseURL = "/"` to keep old expectations, which tests less of the new behaviour than A's approach of updating expectations to the new absolute URLs. Scope and craft: Patch B includes a lot of unrelated reformatting (splitting `AssertFileContent(` arguments onto new lines across many tests). This obscures the actual change and accounts for most of its diff. Patch A's diff is limited to the behaviour change and its test consequences.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
1h 10m
Wall-clock time in the container
Full test suite
No new failures
3,806 passed · 101 skipped · 3,909 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
225vs 284 merged
Changed lines, ours vs merged
The issue
View on GitHubIf I want to create a very basic site, the only reason I currently need to create a config file is to set the baseUrl.
So, having the baseURL default to https://example.org/ would be a slightly breaking change, but it would solve more issues than it introduces.
The two patches
config/allconfig/allconfig.goindex a84545edb..82f9b01a1 100644@@ -594,7 +594,7 @@ func (c *ConfigCompiled) SetServerInfo(baseURL, baseURLLiveReload urls.BaseURL, // RootConfig holds all the top-level configuration options in Hugo type RootConfig struct { // The base URL of the site.- // Note that the default value is empty, but Hugo requires a valid URL (e.g. "https://example.com/") to work properly.+ // The default value is "https://example.org/". // <docsmeta>{"identifiers": ["URL"] }</docsmeta> BaseURL string @@ -1011,6 +1011,7 @@ func (c Configs) GetByLang(lang string) config.AllProvider { func newDefaultConfig() *Config { return &Config{+ BaseURL: "https://example.org/", Taxonomies: map[string]string{"tag": "tags", "category": "categories"}, Sitemap: config.SitemapConfig{Priority: -1, Filename: "sitemap.xml"}, Environment: hugo.EnvironmentProduction,config/allconfig/allconfig_integration_test.goindex e6e213b2b..23253a9bd 100644@@ -421,3 +421,81 @@ func TestLegacyEmbeddedRenderHookEnablement(t *testing.T) { b, _ = hugolib.TestE(t, f) b.AssertLogContains("ERROR deprecated") }++func TestDefaultBaseURL(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "404", "robotsTXT"]+-- content/p1.md --+---+title: "p1"+---+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|Home: {{ .Permalink }}|+-- layouts/single.html --+Permalink: {{ .Permalink }}|RelPermalink: {{ .RelPermalink }}|+`++ b := hugolib.Test(t, files)++ b.Assert(b.H.Configs.Base.BaseURL, qt.Equals, "https://example.org/")+ b.Assert(b.H.Sites[0].Conf.BaseURL().String(), qt.Equals, "https://example.org/")+ b.AssertFileContent("public/index.html", "BaseURL: https://example.org/|Home: https://example.org/|")+ b.AssertFileContent("public/p1/index.html", "Permalink: https://example.org/p1/|RelPermalink: /p1/|")+}++func TestDefaultBaseURLMultilingual(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "rss", "sitemap", "404", "robotsTXT"]+defaultContentLanguage = "en"+[languages]+[languages.en]+weight = 1+[languages.sv]+weight = 2+-- content/p1.md --+---+title: "p1"+---+-- content/p1.sv.md --+---+title: "p1 sv"+---+-- layouts/single.html --+Permalink: {{ .Permalink }}|+`++ b := hugolib.Test(t, files)++ b.Assert(b.H.Configs.IsMultihost, qt.IsFalse)+ for _, s := range b.H.Sites {+ b.Assert(s.Conf.BaseURL().String(), qt.Equals, "https://example.org/")+ }+ b.AssertFileContent("public/p1/index.html", "Permalink: https://example.org/p1/|")+ b.AssertFileContent("public/sv/p1/index.html", "Permalink: https://example.org/sv/p1/|")+}++func TestDefaultBaseURLOverride(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = "https://example.net/docs/"+disableKinds = ["taxonomy", "term", "rss", "sitemap", "404", "robotsTXT"]+-- content/p1.md --+---+title: "p1"+---+-- layouts/single.html --+Permalink: {{ .Permalink }}|+`++ b := hugolib.Test(t, files)++ b.AssertFileContent("public/p1/index.html", "Permalink: https://example.net/docs/p1/|")+}hugolib/alias_test.goindex e9bfe8e6c..4ff581544 100644@@ -36,8 +36,8 @@ func TestAlias(t *testing.T) { {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com"}}, {"/index.html", "http://example.com/some/path", "/", map[string]any{"baseURL": "http://example.com/some/path"}}, {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com", "canonifyURLs": true}},- {"/index.html", "../..", "/", map[string]any{"relativeURLs": true}},- {".html", "", ".html", map[string]any{"uglyURLs": true}},+ {"/index.html", "../..", "/", map[string]any{"baseURL": "/", "relativeURLs": true}},+ {".html", "https://example.org", ".html", map[string]any{"uglyURLs": true}}, } for _, test := range tests {@@ -726,10 +726,10 @@ Output format: foo|Title: {{ .Title }} b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`) b.AssertFileContent("public/index.html", ` <head>- <title>/en/</title>- <link rel="canonical" href="/en/">+ <title>https://example.org/en/</title>+ <link rel="canonical" href="https://example.org/en/"> <meta charset="utf-8">- <meta http-equiv="refresh" content="0; url=/en/">+ <meta http-equiv="refresh" content="0; url=https://example.org/en/"> </head> `) @@ -743,10 +743,10 @@ Output format: foo|Title: {{ .Title }} b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`) b.AssertFileContent("public/index.html", ` <head>- <title>/en/</title>- <link rel="canonical" href="/en/">+ <title>https://example.org/en/</title>+ <link rel="canonical" href="https://example.org/en/"> <meta charset="utf-8">- <meta http-equiv="refresh" content="0; url=/en/">+ <meta http-equiv="refresh" content="0; url=https://example.org/en/"> </head> `) }@@ -822,46 +822,46 @@ aliases: [a, b.foo, c.html, d.htm, e.foo.html, f.foo.htm] b := Test(t, f) - b.AssertFileContent("public/s1/a/index.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/b.foo/index.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/c.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/d.htm", "url=/s1/p1/")- b.AssertFileContent("public/s1/e.foo.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/f.foo.htm", "url=/s1/p1/")+ b.AssertFileContent("public/s1/a/index.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/b.foo/index.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/c.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/d.htm", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/e.foo.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/f.foo.htm", "url=https://example.org/s1/p1/") r = strings.NewReplacer("UGLYURLS", "false", "SUFFIXES", "['htm', 'html']") f = r.Replace(files) b = Test(t, f) - b.AssertFileContent("public/s1/a/index.htm", "url=/s1/p1/")- b.AssertFileContent("public/s1/b.foo/index.htm", "url=/s1/p1/")- b.AssertFileContent("public/s1/c.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/d.htm", "url=/s1/p1/")- b.AssertFileContent("public/s1/e.foo.html", "url=/s1/p1/")- b.AssertFileContent("public/s1/f.foo.htm", "url=/s1/p1/")+ b.AssertFileContent("public/s1/a/index.htm", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/b.foo/index.htm", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/c.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/d.htm", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/e.foo.html", "url=https://example.org/s1/p1/")+ b.AssertFileContent("public/s1/f.foo.htm", "url=https://example.org/s1/p1/") r = strings.NewReplacer("UGLYURLS", "true", "SUFFIXES", "['html', 'htm']") f = r.Replace(files) b = Test(t, f) - b.AssertFileContent("public/s1/a.html", "url=/s1/p1.html")- b.AssertFileContent("public/s1/b.foo.html", "url=/s1/p1.html")- b.AssertFileContent("public/s1/c.html", "url=/s1/p1.html")- b.AssertFileContent("public/s1/d.htm", "url=/s1/p1.html")- b.AssertFileContent("public/s1/e.foo.html", "url=/s1/p1.html")- b.AssertFileContent("public/s1/f.foo.htm", "url=/s1/p1.html")+ b.AssertFileContent("public/s1/a.html", "url=https://example.org/s1/p1.html")+ b.AssertFileContent("public/s1/b.foo.html", "url=https://example.org/s1/p1.html")+ b.AssertFileContent("public/s1/c.html", "url=https://example.org/s1/p1.html")+ b.AssertFileContent("public/s1/d.htm", "url=https://example.org/s1/p1.html")+ b.AssertFileContent("public/s1/e.foo.html", "url=https://example.org/s1/p1.html")+ b.AssertFileContent("public/s1/f.foo.htm", "url=https://example.org/s1/p1.html") r = strings.NewReplacer("UGLYURLS", "true", "SUFFIXES", "['htm', 'html']") f = r.Replace(files) b = Test(t, f) - b.AssertFileContent("public/s1/a.htm", "url=/s1/p1.htm")- b.AssertFileContent("public/s1/b.foo.htm", "url=/s1/p1.htm")- b.AssertFileContent("public/s1/c.html", "url=/s1/p1.htm")- b.AssertFileContent("public/s1/d.htm", "url=/s1/p1.htm")- b.AssertFileContent("public/s1/e.foo.html", "url=/s1/p1.htm")- b.AssertFileContent("public/s1/f.foo.htm", "url=/s1/p1.htm")+ b.AssertFileContent("public/s1/a.htm", "url=https://example.org/s1/p1.htm")+ b.AssertFileContent("public/s1/b.foo.htm", "url=https://example.org/s1/p1.htm")+ b.AssertFileContent("public/s1/c.html", "url=https://example.org/s1/p1.htm")+ b.AssertFileContent("public/s1/d.htm", "url=https://example.org/s1/p1.htm")+ b.AssertFileContent("public/s1/e.foo.html", "url=https://example.org/s1/p1.htm")+ b.AssertFileContent("public/s1/f.foo.htm", "url=https://example.org/s1/p1.htm") }testscripts/commands/hugo__default_baseurl.txtnew file mode 100644index 000000000..7ed7970dc@@ -0,0 +1,20 @@+# Test that the baseURL defaults to https://example.org/ when not configured.++hugo+grep 'BaseURL: https://example.org/\|Permalink: https://example.org/p1/\|RelPermalink: /p1/\|' public/p1/index.html++# The --baseURL flag overrides the default.+hugo --baseURL https://example.net/docs/ -d public2+grep 'BaseURL: https://example.net/docs/\|Permalink: https://example.net/docs/p1/\|RelPermalink: /docs/p1/\|' public2/p1/index.html++-- hugo.toml --+title = "Default baseURL"+disableKinds = ["taxonomy", "term", "rss", "sitemap", "404", "robotsTXT"]+-- content/p1.md --+---+title: "p1"+---+-- layouts/home.html --+Home.+-- layouts/single.html --+BaseURL: {{ site.BaseURL }}|Permalink: {{ .Permalink }}|RelPermalink: {{ .RelPermalink }}|testscripts/server/server__default_baseurl.txtnew file mode 100644index 000000000..f8ffcb433@@ -0,0 +1,24 @@+# Test the hugo server command without a configured baseURL.+# The default baseURL (https://example.org/) is rewritten to http://localhost.++hugo server --renderToMemory &++waitServer++httpget $HUGOTEST_BASEURL_0 'BaseURL: http://localhost:\d{4,5}/\|'+httpget ${HUGOTEST_BASEURL_0}p1/ 'Permalink: http://localhost:\d{4,5}/p1/\|'++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Default BaseURL Test"+disableKinds = ["taxonomy", "term", "sitemap"]+-- content/p1.md --+---+title: "p1"+---+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|+-- layouts/single.html --+Permalink: {{ .Permalink }}|tpl/tplimpl/embedded_templates_integration_test.goindex 5790216cc..939ce0822 100644@@ -211,7 +211,7 @@ title: p0 b := hugolib.Test(t, files) b.AssertFileContent("public/s1/p1/index.html", `- <meta property="og:url" content="/s1/p1/">+ <meta property="og:url" content="https://example.org/s1/p1/"> <meta property="og:site_name" content="My Site"> <meta property="og:title" content="p1"> <meta property="og:description" content="a b and c can’t.">@@ -222,16 +222,16 @@ title: p0 <meta property="article:modified_time" content="2024-04-24T11:00:00-07:00"> <meta property="article:tag" content="t1"> <meta property="article:tag" content="t2">- <meta property="og:image" content="/a.jpg">- <meta property="og:image" content="/b.jpg">- <meta property="og:audio" content="/c.mp3">- <meta property="og:audio" content="/d.mp3">- <meta property="og:video" content="/e.mp4">- <meta property="og:video" content="/f.mp4">- <meta property="og:see_also" content="/s1/p2/">- <meta property="og:see_also" content="/s1/p3/">- <meta property="og:see_also" content="/s1/p4/">- <meta property="og:see_also" content="/s1/p5/">+ <meta property="og:image" content="https://example.org/a.jpg">+ <meta property="og:image" content="https://example.org/b.jpg">+ <meta property="og:audio" content="https://example.org/c.mp3">+ <meta property="og:audio" content="https://example.org/d.mp3">+ <meta property="og:video" content="https://example.org/e.mp4">+ <meta property="og:video" content="https://example.org/f.mp4">+ <meta property="og:see_also" content="https://example.org/s1/p2/">+ <meta property="og:see_also" content="https://example.org/s1/p3/">+ <meta property="og:see_also" content="https://example.org/s1/p4/">+ <meta property="og:see_also" content="https://example.org/s1/p5/"> <meta property="fb:admins" content="foo"> `, )@@ -269,7 +269,7 @@ title: p0 // Term page b.AssertFileContent("public/series/series-1/index.html",- `<meta property="og:url" content="/series/series-1/">`,+ `<meta property="og:url" content="https://example.org/series/series-1/">`, `<meta property="og:title" content="series-1">`, `<meta property="og:type" content="website">`, )@@ -468,8 +468,8 @@ keywords: [k1,k2] <meta itemprop="datePublished" content="2024-04-24T08:00:00-07:00"> <meta itemprop="dateModified" content="2024-04-24T11:00:00-07:00"> <meta itemprop="wordCount" content="5">- <meta itemprop="image" content="/a.jpg">- <meta itemprop="image" content="/b.jpg">+ <meta itemprop="image" content="https://example.org/a.jpg">+ <meta itemprop="image" content="https://example.org/b.jpg"> <meta itemprop="keywords" content="t1,t2"> `, )@@ -588,7 +588,7 @@ title: '' b.AssertFileContent("public/s1/p1/index.html", ` <meta name="twitter:card" content="summary_large_image">- <meta name="twitter:image" content="/a.jpg">+ <meta name="twitter:image" content="https://example.org/a.jpg"> <meta name="twitter:title" content="p1"> <meta name="twitter:description" content="a b and c can’t."> <meta name="twitter:site" content="@foo">tpl/tplimpl/tplimpl_integration_test.goindex 647500207..04bd581c6 100644@@ -196,21 +196,21 @@ title: p2 files_b := strings.ReplaceAll(files, "disable = true", "disable = false") b = hugolib.Test(t, files_b) b.AssertFileContentExact("public/sitemap.xml",- "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p1/</loc>\n </url><url>\n <loc>/p2/</loc>\n </url>\n</urlset>\n",+ "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>https://example.org/p1/</loc>\n </url><url>\n <loc>https://example.org/p2/</loc>\n </url>\n</urlset>\n", ) // Test C: Exclude all pages via project config, but include p1 via front matter. files_c := strings.ReplaceAll(files, "p1_disable: foo", "disable: false") b = hugolib.Test(t, files_c) b.AssertFileContentExact("public/sitemap.xml",- "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p1/</loc>\n </url>\n</urlset>\n",+ "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>https://example.org/p1/</loc>\n </url>\n</urlset>\n", ) // Test D: Include all pages via project config, but exclude p1 via front matter. files_d := strings.ReplaceAll(files_b, "p1_disable: foo", "disable: true") b = hugolib.Test(t, files_d) b.AssertFileContentExact("public/sitemap.xml",- "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p2/</loc>\n </url>\n</urlset>\n",+ "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>https://example.org/p2/</loc>\n </url>\n</urlset>\n", ) }
config/allconfig/allconfig.goindex a84545edb..0cb1f3a6b 100644@@ -357,6 +357,10 @@ func (c *Config) CompileConfig(logger loggers.Logger) error { ignoredLogIDs[err] = true } + if c.BaseURL == "" {+ c.BaseURL = "https://example.org/"+ }+ baseURL, err := urls.NewBaseURLFromString(c.BaseURL) if err != nil { return err@@ -594,7 +598,7 @@ func (c *ConfigCompiled) SetServerInfo(baseURL, baseURLLiveReload urls.BaseURL, // RootConfig holds all the top-level configuration options in Hugo type RootConfig struct { // The base URL of the site.- // Note that the default value is empty, but Hugo requires a valid URL (e.g. "https://example.com/") to work properly.+ // It defaults to https://example.org/ // <docsmeta>{"identifiers": ["URL"] }</docsmeta> BaseURL string hugolib/alias_test.goindex e9bfe8e6c..e7072689e 100644@@ -36,8 +36,8 @@ func TestAlias(t *testing.T) { {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com"}}, {"/index.html", "http://example.com/some/path", "/", map[string]any{"baseURL": "http://example.com/some/path"}}, {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com", "canonifyURLs": true}},- {"/index.html", "../..", "/", map[string]any{"relativeURLs": true}},- {".html", "", ".html", map[string]any{"uglyURLs": true}},+ {"/index.html", "../..", "/", map[string]any{"relativeURLs": true, "baseURL": "/"}},+ {".html", "", ".html", map[string]any{"uglyURLs": true, "baseURL": "/"}}, } for _, test := range tests {@@ -273,22 +273,26 @@ aliases: [/p2-alias] b := Test(t, f) // output format: html- b.AssertFileContent("public/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/foo/s1-alias/index.html", `<title>https://example.org/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s1/">`, )- b.AssertFileContent("public/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/foo/s1/p1-alias/index.html", `<title>https://example.org/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s1/p1/">`, )- b.AssertFileContent("public/s2-alias/index.html",+ b.AssertFileContent(+ "public/s2-alias/index.html", `<title>https://example.org/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s2/">`, )- b.AssertFileContent("public/p2-alias/index.html",+ b.AssertFileContent(+ "public/p2-alias/index.html", `<title>https://example.org/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s2/p2/">`,@@ -347,44 +351,52 @@ aliases: [/p2-alias] b = Test(t, f) // output format: html- b.AssertFileContent("public/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/foo/s1-alias/index.html", `<title>https://example.org/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s1/">`, )- b.AssertFileContent("public/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/foo/s1/p1-alias/index.html", `<title>https://example.org/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s1/p1/">`, )- b.AssertFileContent("public/s2-alias/index.html",+ b.AssertFileContent(+ "public/s2-alias/index.html", `<title>https://example.org/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s2/">`, )- b.AssertFileContent("public/p2-alias/index.html",+ b.AssertFileContent(+ "public/p2-alias/index.html", `<title>https://example.org/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/foo/s2/p2/">`, ) // output format: print- b.AssertFileContent("public/print/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/print/foo/s1-alias/index.html", `<title>https://example.org/print/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/print/foo/s1/">`, )- b.AssertFileContent("public/print/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/print/foo/s1/p1-alias/index.html", `<title>https://example.org/print/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/print/foo/s1/p1/">`, )- b.AssertFileContent("public/print/s2-alias/index.html",+ b.AssertFileContent(+ "public/print/s2-alias/index.html", `<title>https://example.org/print/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/print/foo/s2/">`, )- b.AssertFileContent("public/print/p2-alias/index.html",+ b.AssertFileContent(+ "public/print/p2-alias/index.html", `<title>https://example.org/print/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/print/foo/s2/p2/">`,@@ -473,88 +485,104 @@ aliases: [/p2-alias] b := Test(t, files) // language: de, output format: html- b.AssertFileContent("public/guest/v1.0.0/de/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/foo/s1-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/foo/s1/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/foo/s1/p1-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/foo/s1/p1/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/s2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/s2-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/foo/s2/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/p2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/p2-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/foo/s2/p2/">`, ) // language: de, output format: print- b.AssertFileContent("public/guest/v1.0.0/de/print/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/print/foo/s1-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/print/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/print/foo/s1/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/print/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/print/foo/s1/p1-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/print/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/print/foo/s1/p1/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/print/s2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/print/s2-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/print/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/print/foo/s2/">`, )- b.AssertFileContent("public/guest/v1.0.0/de/print/p2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/de/print/p2-alias/index.html", `<title>https://example.org/guest/v1.0.0/de/print/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/de/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/de/print/foo/s2/p2/">`, ) // language: en, output format: html- b.AssertFileContent("public/guest/v1.0.0/en/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/foo/s1-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/foo/s1/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/foo/s1/p1-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/foo/s1/p1/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/s2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/s2-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/foo/s2/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/p2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/p2-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/foo/s2/p2/">`, ) // language: en, output format: print- b.AssertFileContent("public/guest/v1.0.0/en/print/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/print/foo/s1-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/print/foo/s1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/print/foo/s1/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/print/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/print/foo/s1/p1-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/print/foo/s1/p1/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/print/foo/s1/p1/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/print/s2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/print/s2-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/print/foo/s2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/print/foo/s2/">`, )- b.AssertFileContent("public/guest/v1.0.0/en/print/p2-alias/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/print/p2-alias/index.html", `<title>https://example.org/guest/v1.0.0/en/print/foo/s2/p2/</title>`, `<link rel="canonical" href="https://example.org/guest/v1.0.0/en/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://example.org/guest/v1.0.0/en/print/foo/s2/p2/">`,@@ -568,88 +596,104 @@ aliases: [/p2-alias] b = Test(t, files) // language: de, output format: html- b.AssertFileContent("public/de/guest/v1.0.0/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/foo/s1-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/foo/s1/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/foo/s1/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/foo/s1/p1-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/foo/s1/p1/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/foo/s1/p1/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/s2-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/s2-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/foo/s2/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/foo/s2/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/p2-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/p2-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/foo/s2/p2/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/foo/s2/p2/">`, ) // language: de, output format: print- b.AssertFileContent("public/de/guest/v1.0.0/print/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/print/foo/s1-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/print/foo/s1/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/print/foo/s1/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/print/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/print/foo/s1/p1-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/print/foo/s1/p1/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/print/foo/s1/p1/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/print/s2-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/print/s2-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/print/foo/s2/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/print/foo/s2/">`, )- b.AssertFileContent("public/de/guest/v1.0.0/print/p2-alias/index.html",+ b.AssertFileContent(+ "public/de/guest/v1.0.0/print/p2-alias/index.html", `<title>https://de.example.org/guest/v1.0.0/print/foo/s2/p2/</title>`, `<link rel="canonical" href="https://de.example.org/guest/v1.0.0/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://de.example.org/guest/v1.0.0/print/foo/s2/p2/">`, ) // language: en, output format: html- b.AssertFileContent("public/en/guest/v1.0.0/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/foo/s1-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/foo/s1/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/foo/s1/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/foo/s1/p1-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/foo/s1/p1/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/foo/s1/p1/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/s2-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/s2-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/foo/s2/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/foo/s2/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/p2-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/p2-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/foo/s2/p2/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/foo/s2/p2/">`, ) // language: en, output format: print- b.AssertFileContent("public/en/guest/v1.0.0/print/foo/s1-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/print/foo/s1-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/print/foo/s1/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s1/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/print/foo/s1/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/print/foo/s1/p1-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/print/foo/s1/p1-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/print/foo/s1/p1/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s1/p1/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/print/foo/s1/p1/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/print/s2-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/print/s2-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/print/foo/s2/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s2/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/print/foo/s2/">`, )- b.AssertFileContent("public/en/guest/v1.0.0/print/p2-alias/index.html",+ b.AssertFileContent(+ "public/en/guest/v1.0.0/print/p2-alias/index.html", `<title>https://en.example.org/guest/v1.0.0/print/foo/s2/p2/</title>`, `<link rel="canonical" href="https://en.example.org/guest/v1.0.0/foo/s2/p2/">`, `<meta http-equiv="refresh" content="0; url=https://en.example.org/guest/v1.0.0/print/foo/s2/p2/">`,@@ -679,7 +723,8 @@ Home. ` b := Test(t, files) - b.AssertFileContent("public/guest/v1.0.0/en/index.html",+ b.AssertFileContent(+ "public/guest/v1.0.0/en/index.html", "/guest/v1.0.0/en/foo/p2 =>/guest/v1.0.0/en/foo/p1/|", "/guest/v1.0.0/en/p3 =>/guest/v1.0.0/en/foo/p1/|", )@@ -691,6 +736,7 @@ func TestOutputFormatIsHTMLWithMultilangAliases(t *testing.T) { files := ` -- hugo.toml --+baseURL = "/" defaultContentLanguageInSubdir = true disableKinds = ['page', 'section', 'rss', 'sitemap', 'taxonomy', 'term'] @@ -799,6 +845,7 @@ func TestAliasExplicitExtension(t *testing.T) { -- hugo.toml -- disableKinds = ['home','rss','section','sitemap','taxonomy','term'] uglyURLs = UGLYURLS+baseURL = "/" [mediaTypes] [mediaTypes.'text/html']hugolib/page_permalink_test.goindex c2fe8f089..d5ae69375 100644@@ -34,17 +34,17 @@ func TestPermalink(t *testing.T) { expectedAbs string expectedRel string }{- {"x/y/z/boofar.md", "", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},- {"x/y/z/boofar.md", "", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},+ {"x/y/z/boofar.md", "/", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},+ {"x/y/z/boofar.md", "/", "", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"}, // Issue #1174 {"x/y/z/boofar.md", "http://gopher.com/", "", "", false, true, "http://gopher.com/x/y/z/boofar/", "/x/y/z/boofar/"}, {"x/y/z/boofar.md", "http://gopher.com/", "", "", true, true, "http://gopher.com/x/y/z/boofar.html", "/x/y/z/boofar.html"},- {"x/y/z/boofar.md", "", "boofar", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"},+ {"x/y/z/boofar.md", "/", "boofar", "", false, false, "/x/y/z/boofar/", "/x/y/z/boofar/"}, {"x/y/z/boofar.md", "http://barnew/", "", "", false, false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"}, {"x/y/z/boofar.md", "http://barnew/", "boofar", "", false, false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"},- {"x/y/z/boofar.md", "", "", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},- {"x/y/z/boofar.md", "", "", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},- {"x/y/z/boofar.md", "", "boofar", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},+ {"x/y/z/boofar.md", "/", "", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},+ {"x/y/z/boofar.md", "/", "", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},+ {"x/y/z/boofar.md", "/", "boofar", "", true, false, "/x/y/z/boofar.html", "/x/y/z/boofar.html"}, {"x/y/z/boofar.md", "http://barnew/", "", "", true, false, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"}, {"x/y/z/boofar.md", "http://barnew/", "boofar", "", true, false, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"}, {"x/y/z/boofar.md", "http://barnew/boo/", "booslug", "", true, false, "http://barnew/boo/x/y/z/booslug.html", "/boo/x/y/z/booslug.html"},@@ -56,9 +56,9 @@ func TestPermalink(t *testing.T) { {"x/y/z/boo-makeindex.md", "http://barnew/boo", "", "", true, true, "http://barnew/boo/x/y/z/boo-makeindex.html", "/x/y/z/boo-makeindex.html"}, // test URL overrides- {"x/y/z/boofar.md", "", "", "/z/y/q/", false, false, "/z/y/q/", "/z/y/q/"},+ {"x/y/z/boofar.md", "/", "", "/z/y/q/", false, false, "/z/y/q/", "/z/y/q/"}, // test URL override with expands- {"x/y/z/boofar.md", "", "test", "/z/:slug/", false, false, "/z/test/", "/z/test/"},+ {"x/y/z/boofar.md", "/", "test", "/z/:slug/", false, false, "/z/test/", "/z/test/"}, } for i, test := range tests {hugolib/site_url_test.goindex 253969a34..b96dd3de2 100644@@ -14,6 +14,7 @@ package hugolib import (+ "strings" "testing" ) @@ -33,3 +34,25 @@ SectionsEntries: {{ .SectionsEntries }} b.AssertFileContent("public/withfile/index.html", "SectionsEntries: [withfile]") b.AssertFileContent("public/withoutfile/index.html", "SectionsEntries: [withoutfile]") }++// See #14625.+func TestDefaultBaseURL(t *testing.T) {+ filesTemplate := `+-- hugo.toml --+CONFIG+-- content/_index.md --+-- layouts/list.html --+BaseURL: {{ .Site.BaseURL }}+`+ files := strings.ReplaceAll(filesTemplate, "CONFIG", `baseURL = "https://example.com/"`)+ b := Test(t, files)+ b.AssertFileContent("public/index.html", "BaseURL: https://example.com/")++ files = strings.ReplaceAll(filesTemplate, "CONFIG", "")+ b = Test(t, files)+ b.AssertFileContent("public/index.html", "BaseURL: https://example.org/")++ files = strings.ReplaceAll(filesTemplate, "CONFIG", `baseURL = "/"`)+ b = Test(t, files)+ b.AssertFileContent("public/index.html", "BaseURL: /")+}tpl/tplimpl/embedded_templates_integration_test.goindex 5790216cc..4fa17d71d 100644@@ -47,7 +47,8 @@ disqus_url = 'https://example.com/my-page/' b := hugolib.Test(t, files) - b.AssertFileContent("public/index.html",+ b.AssertFileContent(+ "public/index.html", `s.src = '//' + "foo" + '.disqus.com/embed.js';`, `this.page.identifier = 'my-identifier';`, `this.page.title = 'My Title';`,@@ -88,7 +89,8 @@ title: Home // Default respectDoNotTrack value f := strings.ReplaceAll(files, "DNT", "") b := hugolib.Test(t, f)- b.AssertFileContent("public/index.html",+ b.AssertFileContent(+ "public/index.html", `<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`, `if ( true )`, )@@ -96,7 +98,8 @@ title: Home // respectDoNotTrack = true f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = true") b = hugolib.Test(t, f)- b.AssertFileContent("public/index.html",+ b.AssertFileContent(+ "public/index.html", `<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`, `if ( true )`, )@@ -104,7 +107,8 @@ title: Home // respectDoNotTrack = false f = strings.ReplaceAll(files, "DNT", "respectDoNotTrack = false") b = hugolib.Test(t, f)- b.AssertFileContent("public/index.html",+ b.AssertFileContent(+ "public/index.html", `<script async src="https://www.googletagmanager.com/gtag/js?id=G-0123456789"></script>`, `if ( false )`, )@@ -133,6 +137,7 @@ func TestOpengraphTemplate(t *testing.T) { files := ` -- hugo.toml --+baseURL = "/" title = 'My Site' capitalizeListTitles = false disableKinds = ['section','rss','sitemap','taxonomy']@@ -210,7 +215,8 @@ title: p0 b := hugolib.Test(t, files) - b.AssertFileContent("public/s1/p1/index.html", `+ b.AssertFileContent(+ "public/s1/p1/index.html", ` <meta property="og:url" content="/s1/p1/"> <meta property="og:site_name" content="My Site"> <meta property="og:title" content="p1">@@ -237,38 +243,45 @@ title: p0 ) // Description from content excerpt- b.AssertFileContent("public/s1/p2/index.html",+ b.AssertFileContent(+ "public/s1/p2/index.html", `<meta property="og:description" content="d e and f can’t.">`, ) // Description from front matter summary- b.AssertFileContent("public/s1/p3/index.html",+ b.AssertFileContent(+ "public/s1/p3/index.html", `<meta property="og:description" content="g h and i can’t.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p4/index.html",+ b.AssertFileContent(+ "public/s1/p4/index.html", `<meta property="og:description" content="j k and **l** can't.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p5/index.html",+ b.AssertFileContent(+ "public/s1/p5/index.html", `<meta property="og:description" content="m n and **o** can't.">`, ) // og:locale from page front matter- b.AssertFileContent("public/s1/p6/index.html",+ b.AssertFileContent(+ "public/s1/p6/index.html", `<meta property="og:locale" content="fr_FR">`, ) // No article:section for root-level page- b.AssertFileContent("public/p0/index.html",+ b.AssertFileContent(+ "public/p0/index.html", `<meta property="og:type" content="article">`, `! article:section`, ) // Term page- b.AssertFileContent("public/series/series-1/index.html",+ b.AssertFileContent(+ "public/series/series-1/index.html", `<meta property="og:url" content="/series/series-1/">`, `<meta property="og:title" content="series-1">`, `<meta property="og:type" content="website">`,@@ -280,13 +293,15 @@ title: p0 // facebook_app_id takes precedence over facebook_admin f := strings.ReplaceAll(files, "facebook_admin = 'foo'", "facebook_app_id = 'bar'") b = hugolib.Test(t, f)- b.AssertFileContent("public/s1/p1/index.html",+ b.AssertFileContent(+ "public/s1/p1/index.html", `<meta property="fb:app_id" content="bar">`, `! fb:admins`, ) // Issue 14433- b.AssertFileContent("public/index.html",+ b.AssertFileContent(+ "public/index.html", `<meta property="og:title" content="Home">`, `<meta property="og:locale" content="en_US">`, `<meta property="og:type" content="website">`,@@ -365,7 +380,8 @@ title: p10 // Default format, last page: active First and Prev, disabled Next and Last f := strings.ReplaceAll(files, "PARTIAL", `{{ partial "pagination.html" . }}`) b := hugolib.Test(t, f)- b.AssertFileContent("public/page/10/index.html",+ b.AssertFileContent(+ "public/page/10/index.html", `<a href="/" aria-label="First" class="page-link" role="button">`, `<a href="/page/9/" aria-label="Previous" class="page-link" role="button">`, `aria-disabled="true" aria-label="Next"`,@@ -375,7 +391,8 @@ title: p10 // Terse format, last page: First and Prev shown, Next and Last hidden f = strings.ReplaceAll(files, "PARTIAL", `{{ partial "pagination.html" (dict "page" . "format" "terse") }}`) b = hugolib.Test(t, f)- b.AssertFileContent("public/page/10/index.html",+ b.AssertFileContent(+ "public/page/10/index.html", `<a href="/" aria-label="First" class="page-link" role="button">`, `<a href="/page/9/" aria-label="Previous" class="page-link" role="button">`, `! aria-label="Next"`,@@ -412,6 +429,7 @@ func TestSchemaTemplate(t *testing.T) { files := ` -- hugo.toml --+baseURL = "/" capitalizeListTitles = false disableKinds = ['rss','sitemap'] [markup.goldmark.renderer]@@ -462,7 +480,8 @@ keywords: [k1,k2] b := hugolib.Test(t, files) - b.AssertFileContent("public/s1/p1/index.html", `+ b.AssertFileContent(+ "public/s1/p1/index.html", ` <meta itemprop="name" content="p1"> <meta itemprop="description" content="a b and c can’t."> <meta itemprop="datePublished" content="2024-04-24T08:00:00-07:00">@@ -475,27 +494,32 @@ keywords: [k1,k2] ) // Description from content excerpt- b.AssertFileContent("public/s1/p2/index.html",+ b.AssertFileContent(+ "public/s1/p2/index.html", `<meta itemprop="description" content="d e and f can’t.">`, ) // Description from front matter summary- b.AssertFileContent("public/s1/p3/index.html",+ b.AssertFileContent(+ "public/s1/p3/index.html", `<meta itemprop="description" content="g h and i can’t.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p4/index.html",+ b.AssertFileContent(+ "public/s1/p4/index.html", `<meta itemprop="description" content="j k and **l** can't.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p5/index.html",+ b.AssertFileContent(+ "public/s1/p5/index.html", `<meta itemprop="description" content="m n and **o** can't.">`, ) // Front matter keywords- b.AssertFileContent("public/s1/p6/index.html",+ b.AssertFileContent(+ "public/s1/p6/index.html", `<meta itemprop="keywords" content="k1,k2">`, ) @@ -586,9 +610,10 @@ title: '' b := hugolib.Test(t, files) - b.AssertFileContent("public/s1/p1/index.html", `+ b.AssertFileContent(+ "public/s1/p1/index.html", ` <meta name="twitter:card" content="summary_large_image">- <meta name="twitter:image" content="/a.jpg">+ <meta name="twitter:image" content="https://example.org/a.jpg"> <meta name="twitter:title" content="p1"> <meta name="twitter:description" content="a b and c can’t."> <meta name="twitter:site" content="@foo">@@ -596,23 +621,27 @@ title: '' ) // Description from content excerpt- b.AssertFileContent("public/s1/p2/index.html",+ b.AssertFileContent(+ "public/s1/p2/index.html", `<meta name="twitter:card" content="summary">`, `<meta name="twitter:description" content="d e and f can’t.">`, ) // Description from front matter summary- b.AssertFileContent("public/s1/p3/index.html",+ b.AssertFileContent(+ "public/s1/p3/index.html", `<meta name="twitter:description" content="g h and i can’t.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p4/index.html",+ b.AssertFileContent(+ "public/s1/p4/index.html", `<meta name="twitter:description" content="j k and **l** can't.">`, ) // The markdown is intentionally not rendered to HTML.- b.AssertFileContent("public/s1/p5/index.html",+ b.AssertFileContent(+ "public/s1/p5/index.html", `<meta name="twitter:description" content="m n and **o** can't.">`, ) tpl/tplimpl/tplimpl_integration_test.goindex 647500207..b1f03a50a 100644@@ -168,6 +168,7 @@ func TestSitemap(t *testing.T) { files := ` -- hugo.toml --+baseURL = "/" disableKinds = ['home','rss','section','taxonomy','term'] [sitemap] disable = true@@ -188,28 +189,32 @@ title: p2 // Test A: Exclude all pages via project config. b := hugolib.Test(t, files)- b.AssertFileContentExact("public/sitemap.xml",+ b.AssertFileContentExact(+ "public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n \n</urlset>\n", ) // Test B: Include all pages via project config. files_b := strings.ReplaceAll(files, "disable = true", "disable = false") b = hugolib.Test(t, files_b)- b.AssertFileContentExact("public/sitemap.xml",+ b.AssertFileContentExact(+ "public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p1/</loc>\n </url><url>\n <loc>/p2/</loc>\n </url>\n</urlset>\n", ) // Test C: Exclude all pages via project config, but include p1 via front matter. files_c := strings.ReplaceAll(files, "p1_disable: foo", "disable: false") b = hugolib.Test(t, files_c)- b.AssertFileContentExact("public/sitemap.xml",+ b.AssertFileContentExact(+ "public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p1/</loc>\n </url>\n</urlset>\n", ) // Test D: Include all pages via project config, but exclude p1 via front matter. files_d := strings.ReplaceAll(files_b, "p1_disable: foo", "disable: true") b = hugolib.Test(t, files_d)- b.AssertFileContentExact("public/sitemap.xml",+ b.AssertFileContentExact(+ "public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p2/</loc>\n </url>\n</urlset>\n", ) }