Backtestshugorun-20261013-011256#14625
Make default baseUrl https://example.org/
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches make an unset baseURL resolve to https://example.org/, so both address the issue. B is the better fix.
Correctness: B registers the default in `applyDefaultConfig` through `SetDefaults`. This is the same mechanism Hugo uses for other default settings, so the value shows up consistently, including in `hugo config` output. Because `SetDefaults` only fills keys that are absent, a user who explicitly sets `baseURL = ""` keeps an empty base URL. B's TestAlias update relies on exactly that for the relativeURLs case. A instead patches `CompileConfig` to replace any empty string with example.org. That makes an explicit empty baseURL impossible, which is why A has to rewrite many tests to use `baseURL = "/"`. It is also a post-hoc fix-up inside compilation rather than a real default. B additionally updates `docs/data/docs.yaml` so the documented default matches the new behaviour.
Tests: B adds integration tests covering:
- the default value itself, plus its effect on `absURL` and `.Permalink`;
- an explicit override;
- multihost per-language baseURLs still taking precedence over the default;
- testscripts for `hugo config` output and for `hugo server` replacing the default with localhost.
B also updates the existing expectations to the new absolute URLs, which documents the real behaviour change. A adds a smaller test (default, override, and "/"). Its other test edits mostly pin `baseURL = "/"` to preserve the old output, which hides the effect of the change rather than exercising it.
Scope and craft: A carries a large amount of unrelated reformatting, splitting every `AssertFileContent("path",` call across lines in several test files. That churn obscures the real change. B's diff is focused and follows existing conventions.
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 15m
Wall-clock time in the container
Full test suite
No new failures
2,301 passed · 97 skipped · 2,419 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
187vs 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..0268ce4a6 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/", which allows a basic site to be built without any configuration file. // <docsmeta>{"identifiers": ["URL"] }</docsmeta> BaseURL string config/allconfig/allconfig_integration_test.goindex e6e213b2b..7a4382213 100644@@ -421,3 +421,53 @@ func TestLegacyEmbeddedRenderHookEnablement(t *testing.T) { b, _ = hugolib.TestE(t, f) b.AssertLogContains("ERROR deprecated") }++func TestDefaultBaseURL(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+title = "No baseURL"+disableKinds = ["taxonomy", "term", "sitemap", "rss"]+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|AbsURL: {{ "foo" | absURL }}|Permalink: {{ .Permalink }}|+`++ b := hugolib.Test(t, files)++ b.Assert(b.H.Sites[0].Conf.BaseURL().String(), qt.Equals, "https://example.org/")+ b.AssertFileContent("public/index.html", "BaseURL: https://example.org/|AbsURL: https://example.org/foo|Permalink: https://example.org/|")+}++func TestDefaultBaseURLOverride(t *testing.T) {+ t.Parallel()++ files := `+-- hugo.toml --+baseURL = "https://example.net/docs/"+disableKinds = ["taxonomy", "term", "sitemap", "rss"]+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|+`++ b := hugolib.Test(t, files)+ b.AssertFileContent("public/index.html", "BaseURL: https://example.net/docs/|")++ // Per-language baseURL (multihost) must still win over the default.+ files = `+-- hugo.toml --+disableKinds = ["taxonomy", "term", "sitemap", "rss"]+[languages.en]+baseURL = "https://en.example.net/"+weight = 1+[languages.sv]+baseURL = "https://sv.example.net/"+weight = 2+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|+`++ b = hugolib.Test(t, files)+ b.AssertFileContent("public/en/index.html", "BaseURL: https://en.example.net/|")+ b.AssertFileContent("public/sv/index.html", "BaseURL: https://sv.example.net/|")+}config/allconfig/load.goindex 76eb65703..f8cca3402 100644@@ -178,6 +178,8 @@ func (l configLoader) applyDefaultConfig() error { // These dirs are used early/before we build the config struct. "themesDir": "themes", "configDir": "config",+ // Allows a basic site to be built without any configuration file.+ "baseURL": "https://example.org/", } l.cfg.SetDefaults(defaultSettings)docs/data/docs.yamlindex 709a71d68..9c576c129 100644@@ -1326,7 +1326,7 @@ config: archeTypeDir: archetypes assetDir: assets author: {}- baseURL: ''+ baseURL: https://example.org/ build: buildStats: disableClasses: falsehugolib/alias_test.goindex e9bfe8e6c..fa122cefa 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/config__default_baseurl.txtnew file mode 100644index 000000000..e7ee79a7d@@ -0,0 +1,14 @@+# Test that the baseURL defaults to https://example.org/ when not configured.++hugo config+stdout 'baseurl = .https://example.org/'++hugo+grep 'BaseURL: https://example.org/\|AbsURL: https://example.org/foo' public/index.html++# Test files+-- hugo.toml --+title = "My New Hugo Project"+disableKinds = ["taxonomy", "term", "sitemap", "rss"]+-- layouts/home.html --+BaseURL: {{ site.BaseURL }}|AbsURL: {{ "foo" | absURL }}|testscripts/server/server__default_baseurl.txtnew file mode 100644index 000000000..90e466a91@@ -0,0 +1,17 @@+# Test the hugo server command with no baseURL configured.+# The default baseURL (https://example.org/) should be replaced with localhost.++hugo server --renderToMemory &++waitServer++httpget $HUGOTEST_BASEURL_0 'Title: Hugo Server Test' 'BaseURL: http://localhost:' $HUGOTEST_BASEURL_0++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Test"+disableKinds = ["taxonomy", "term", "sitemap"]+-- layouts/home.html --+Title: {{ .Title }}|BaseURL: {{ site.BaseURL }}|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", ) }