diff options
author | Joe Mooring <[email protected]> | 2024-04-25 07:58:28 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-05-14 14:18:49 +0200 |
commit | 92290aa89263dcaa73149a725be9451ab69b8926 (patch) | |
tree | b16f6e780e925f611520a98408ea3ce00ac3a5e3 | |
parent | 6dbbe6dd3a4b84856aa477b07ec69e948a952a6a (diff) | |
download | hugo-92290aa89263dcaa73149a725be9451ab69b8926.tar.gz hugo-92290aa89263dcaa73149a725be9451ab69b8926.zip |
tpl/tplimpl: Plainify title and description in schema.html
Closes #12432
-rw-r--r-- | tpl/tplimpl/embedded/templates/schema.html | 4 | ||||
-rw-r--r-- | tpl/tplimpl/tplimpl_integration_test.go | 82 |
2 files changed, 84 insertions, 2 deletions
diff --git a/tpl/tplimpl/embedded/templates/schema.html b/tpl/tplimpl/embedded/templates/schema.html index c4e89abd6..2b3c5425a 100644 --- a/tpl/tplimpl/embedded/templates/schema.html +++ b/tpl/tplimpl/embedded/templates/schema.html @@ -1,8 +1,8 @@ -{{- with or .Title site.Title }} +{{- with or .Title site.Title | plainify }} <meta itemprop="name" content="{{ . }}"> {{- end }} -{{- with or .Description .Summary site.Params.Description }} +{{- with or .Description .Summary site.Params.description | plainify | htmlUnescape | chomp }} <meta itemprop="description" content="{{ . }}"> {{- end }} diff --git a/tpl/tplimpl/tplimpl_integration_test.go b/tpl/tplimpl/tplimpl_integration_test.go index f9d25eb49..b30965be9 100644 --- a/tpl/tplimpl/tplimpl_integration_test.go +++ b/tpl/tplimpl/tplimpl_integration_test.go @@ -411,3 +411,85 @@ series: [series-1] `<meta property="og:description" content="m n and **o** can't.">`, ) } + +// Issue 12432 +func TestSchema(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +capitalizeListTitles = false +disableKinds = ['rss','sitemap'] +[markup.goldmark.renderer] +unsafe = true +[params] +description = "m <em>n</em> and **o** can't." +[taxonomies] +tag = 'tags' +-- layouts/_default/list.html -- +{{ template "_internal/schema.html" . }} +-- layouts/_default/single.html -- +{{ template "_internal/schema.html" . }} +-- content/s1/p1.md -- +--- +title: p1 +date: 2024-04-24T08:00:00-07:00 +lastmod: 2024-04-24T11:00:00-07:00 +images: [a.jpg,b.jpg] +tags: [t1,t2] +--- +a <em>b</em> and **c** can't. +-- content/s1/p2.md -- +--- +title: p2 +--- +d <em>e</em> and **f** can't. +<!--more--> +-- content/s1/p3.md -- +--- +title: p3 +summary: g <em>h</em> and **i** can't. +--- +-- content/s1/p4.md -- +--- +title: p4 +description: j <em>k</em> and **l** can't. +--- +-- content/s1/p5.md -- +--- +title: p5 +--- +` + + b := hugolib.Test(t, files) + + 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"> + <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="keywords" content="t1,t2"> + `, + ) + + b.AssertFileContent("public/s1/p2/index.html", + `<meta itemprop="description" content="d e and f can’t.">`, + ) + + 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", + `<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", + `<meta itemprop="description" content="m n and **o** can't.">`, + ) +} |