Merge pull request #2497 from paulkaplan/dynamic-meta-tag-template

Add flag for dynamic meta tags in the template
This commit is contained in:
Paul Kaplan 2018-12-17 15:39:13 -05:00 committed by GitHub
commit e3e12deea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 27 deletions

View file

@ -167,7 +167,8 @@
"pattern": "^/projects(/editor|(/\\d+(/editor|/fullscreen|/embed)?)?)?/?(\\?.*)?$", "pattern": "^/projects(/editor|(/\\d+(/editor|/fullscreen|/embed)?)?)?/?(\\?.*)?$",
"routeAlias": "/projects/?$", "routeAlias": "/projects/?$",
"view": "preview/preview", "view": "preview/preview",
"title": "Scratch Project" "title": "Scratch Project",
"dynamicMetaTags": true
}, },
{ {
"name": "3faq", "name": "3faq",

View file

@ -8,23 +8,25 @@
<meta http-equiv="x-ua-compatible" content="ie=edge"> <meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=<%= htmlWebpackPlugin.options.viewportWidth %>, initial-scale=1"> <meta name="viewport" content="width=<%= htmlWebpackPlugin.options.viewportWidth %>, initial-scale=1">
<title>Scratch - <%= htmlWebpackPlugin.options.title %></title>
<!-- Prevent mobile Safari from making phone numbers --> <!-- Prevent mobile Safari from making phone numbers -->
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<!-- Search & Open Graph--> <% if (!htmlWebpackPlugin.options.dynamicMetaTags) { %>
<meta name="description" content="<%= htmlWebpackPlugin.options.description %>" /> <title>Scratch - <%= htmlWebpackPlugin.options.title %></title>
<meta name="google-site-verification" content="m_3TAXDreGTFyoYnEmU9mcKB4Xtw5mw6yRkuJtXRKxM" />
<meta property="og:url" content="https://scratch.mit.edu/" /> <!-- Search & Open Graph-->
<meta property="og:type" content="website" /> <meta name="description" content="<%= htmlWebpackPlugin.options.description %>" />
<meta property="og:title" content="Scratch - <%= htmlWebpackPlugin.options.title %>" /> <meta name="google-site-verification" content="m_3TAXDreGTFyoYnEmU9mcKB4Xtw5mw6yRkuJtXRKxM" />
<meta property="og:description" content="<%= htmlWebpackPlugin.options.description %>" />
<meta property="og:image" content="<%- htmlWebpackPlugin.options.og_image %>" /> <meta property="og:url" content="https://scratch.mit.edu/" />
<meta property="og:image:type" content="<%- htmlWebpackPlugin.options.og_image_type %>" /> <meta property="og:type" content="website" />
<meta property="og:image:width" content="<%- htmlWebpackPlugin.options.og_image_width %>" /> <meta property="og:title" content="Scratch - <%= htmlWebpackPlugin.options.title %>" />
<meta property="og:image:height" content="<%- htmlWebpackPlugin.options.og_image_height %>" /> <meta property="og:description" content="<%= htmlWebpackPlugin.options.description %>" />
<meta property="og:image" content="<%- htmlWebpackPlugin.options.og_image %>" />
<meta property="og:image:type" content="<%- htmlWebpackPlugin.options.og_image_type %>" />
<meta property="og:image:width" content="<%- htmlWebpackPlugin.options.og_image_width %>" />
<meta property="og:image:height" content="<%- htmlWebpackPlugin.options.og_image_height %>" />
<% } %>
<!-- Favicon & CSS normalize --> <!-- Favicon & CSS normalize -->
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico" />
@ -60,19 +62,21 @@
<script src="/<%= htmlWebpackPlugin.files.chunks[htmlWebpackPlugin.options.route.name].entry %>"></script> <script src="/<%= htmlWebpackPlugin.files.chunks[htmlWebpackPlugin.options.route.name].entry %>"></script>
<!-- Translate title element --> <!-- Translate title element -->
<script> <% if (!htmlWebpackPlugin.options.dynamicMetaTags) { %>
var loc = window._locale || 'en'; <script>
if (typeof window._messages !== 'undefined' && loc !== 'en') { var loc = window._locale || 'en';
if (typeof window._messages[loc] === 'undefined') { if (typeof window._messages !== 'undefined' && loc !== 'en') {
loc = loc.split('-')[0]; if (typeof window._messages[loc] === 'undefined') {
} loc = loc.split('-')[0];
if (typeof window._messages[loc] !== 'undefined') { }
var localizedTitle = window._messages[loc]['general.' + '<%= htmlWebpackPlugin.options.title %>'.toLowerCase()] || ''; if (typeof window._messages[loc] !== 'undefined') {
if (localizedTitle.length > 0) { var localizedTitle = window._messages[loc]['general.' + '<%= htmlWebpackPlugin.options.title %>'.toLowerCase()] || '';
document.title = 'Scratch - ' + localizedTitle; if (localizedTitle.length > 0) {
document.title = 'Scratch - ' + localizedTitle;
}
} }
} }
} </script>
</script> <% } %>
</body> </body>
</html> </html>

View file

@ -132,7 +132,8 @@ module.exports = {
return new HtmlWebpackPlugin(defaults({}, { return new HtmlWebpackPlugin(defaults({}, {
title: route.title, title: route.title,
filename: route.name + '.html', filename: route.name + '.html',
route: route route: route,
dynamicMetaTags: route.dynamicMetaTags
}, templateConfig)); }, templateConfig));
}) })
).concat([ ).concat([