Skip to content

Commit ce373d3

Browse files
authored
fixes title generation issues re: Service Worker and partials (GoogleChrome#2309)
* don't escape title * use path title as fallback title, don't show undefined * web.dev default title * fix typo
1 parent 0c45429 commit ce373d3

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/lib/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ workboxRouting.registerRoute(
225225
const meta = partial.offline ? `<meta name="offline" value="true" />` : "";
226226
const output = layoutTemplate.replace(
227227
"%_CONTENT_REPLACE_%",
228-
meta + `<title>${escape(partial.title)}</title>` + partial.raw,
228+
meta + `<title>${partial.title || ""}</title>` + partial.raw,
229229
);
230230
const headers = new Headers();
231231
headers.append("Content-Type", "text/html");

src/site/_includes/components/Meta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ module.exports = (locale, page, collections, renderData = {}) => {
109109

110110
// prettier-ignore
111111
return html`
112-
<title>${pageData.title || pageData.path.title}</title>
112+
<title>${pageData.title || pageData.path.title || "web.dev"}</title>
113113
<meta name="description" content="${pageData.description || pageData.path.description}" />
114114
115115
${renderGoogleMeta()}

src/site/_includes/layout.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<main>
151151
{% include 'partials/banner.njk' %}
152152
<div id="content">
153-
{% Partial page, lang, title, offline %}{{ content | safe }}{% endPartial %}
153+
{% Partial page, path, lang, title, offline %}{{ content | safe }}{% endPartial %}
154154
</div>
155155
</main>
156156
{% include 'partials/footer.njk' %}

src/site/_utils/build-partial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const writePartial = async (to, raw) => {
3434
module.exports = function buildPartial() {
3535
const work = [];
3636

37-
return function(content, page, lang, title, offline) {
37+
return function(content, page, pathData, lang, title, offline) {
3838
if (!page.outputPath.endsWith("/index.html")) {
3939
return content; // unexpected output format
4040
}
@@ -46,7 +46,7 @@ module.exports = function buildPartial() {
4646
const partial = {
4747
raw: content,
4848
lang,
49-
title,
49+
title: title || (pathData && pathData.title) || "web.dev",
5050
offline: offline || undefined,
5151
};
5252

0 commit comments

Comments
 (0)