Skip to content

Commit bcb5786

Browse files
committed
fixing meta tags
1 parent 68a6b6b commit bcb5786

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

prerender-urls.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ const { generateFileList } = require('./src/crawler');
22
const { join } = require('path');
33
const fs = require('fs');
44

5-
const [blogs, images] = generateFileList(join(__dirname, 'content')).nodes;
5+
const [blogs] = generateFileList(join(__dirname, 'content')).nodes;
66
module.exports = () => {
77
const pages = [
8-
{ url: '/' },
8+
{
9+
url: '/',
10+
seo: {
11+
cover: '/assets/profile.jpg'
12+
}
13+
},
914
{ url: '/contact/' },
1015
{ url: '/contact/success' }
1116
];
@@ -21,6 +26,7 @@ module.exports = () => {
2126
const data = fs.readFileSync(join('content', 'blog', blog.id), 'utf-8').replace(/---(.*\n)*---/, '');
2227
return {
2328
url: `/blog/${blog.id}`,
29+
seo: blog.details,
2430
data: {
2531
details: blog.details,
2632
content: data

src/template.html

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,23 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title><%= htmlWebpackPlugin.options.title %></title>
5+
<title><% preact.title %></title>
66
<meta name="viewport" content="width=device-width,initial-scale=1">
77
<meta name="mobile-web-app-capable" content="yes">
88
<meta name="apple-mobile-web-app-capable" content="yes">
9-
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>manifest.json">
10-
<% if (htmlWebpackPlugin.options.manifest.theme_color) { %>
11-
<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>">
9+
<meta property="og:title" content="<%= htmlWebpackPlugin.options.title %>" />
10+
<% if(htmlWebpackPlugin.options.seo && 'cover' in htmlWebpackPlugin.options.seo) {%>
11+
<meta property="og:image" content="<%= htmlWebpackPlugin.options.seo.cover %>" />
12+
<meta name="twitter:image:src" content="<%= htmlWebpackPlugin.options.seo.cover %>">
1213
<% } %>
13-
<% const loadManifest = htmlWebpackPlugin.options.createLoadManifest(compilation.assets, webpack.namedChunkGroups);%>
14-
<% const filesRegexp = htmlWebpackPlugin.options.inlineCss ? /\.(chunk\.\w{5}\.css|js)$/ : /\.(css|js)$/;%>
15-
<% for (const file in loadManifest[htmlWebpackPlugin.options.url]) { %>
16-
<% if (htmlWebpackPlugin.options.preload && file && file.match(filesRegexp)) { %>
17-
<% /* crossorigin for main bundle as that is loaded from `<script type=module` tag, other lazy loaded bundles are from webpack so its not needed */ %>
18-
<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>" <%= file.match(/bundle\.\w{5}\.esm\.js$/)?'crossorigin="anonymous"':'' %>>
19-
<% } %>
14+
<% if(htmlWebpackPlugin.options.seo && 'subtitle' in htmlWebpackPlugin.options.seo) {%>
15+
<meta property="og:description" content="<%= htmlWebpackPlugin.options.seo.subtitle %>" />
16+
<meta property="twitter:description" content="<%= htmlWebpackPlugin.options.seo.subtitle %>" />
17+
<meta property="description" content="<%= htmlWebpackPlugin.options.seo.subtitle %>" />
2018
<% } %>
19+
<% preact.headEnd %>
2120
</head>
2221
<body>
23-
<%= htmlWebpackPlugin.options.ssr() %>
24-
<script type="__PREACT_CLI_DATA__">
25-
<%= JSON.stringify(htmlWebpackPlugin.options.CLI_DATA) %>
26-
</script>
27-
<% if (webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/)).length > 0) { %>
28-
<% /* Fix for safari < 11 nomodule bug. TODO: Do the following only for safari. */ %>
29-
<script nomodule>!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();</script>
30-
<script crossorigin="anonymous" src="<%= htmlWebpackPlugin.files.publicPath %><%= webpack.assets.filter(entry => entry.name.match(/bundle(\.\w{5})?.esm.js$/))[0].name %>" type="module"></script>
31-
<%
32-
/*Fetch and Promise polyfills are not needed for browsers that support type=module
33-
Please re-evaluate below line if adding more polyfills.*/
34-
%>
35-
<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
36-
<script nomodule defer src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
37-
<% } else { %>
38-
<script <%= htmlWebpackPlugin.options.scriptLoading %> src="<%= htmlWebpackPlugin.files.chunks['bundle'].entry %>"></script>
39-
<script nomodule src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"></script>
40-
<% } %>
22+
<% preact.bodyEnd %>
4123
</body>
4224
</html>

0 commit comments

Comments
 (0)