mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 16:30:34 +01:00
refactored meta and link tag generation to template (yay frontend processing!)
cache busters now always added in template, instead of throughout code
This commit is contained in:
@@ -153,43 +153,6 @@
|
||||
}
|
||||
return result;
|
||||
},
|
||||
buildMetaTags: function(tagsArr) {
|
||||
var tags = '',
|
||||
tag;
|
||||
for (var x = 0, numTags = tagsArr.length; x < numTags; x++) {
|
||||
if (tags.length > 0) {
|
||||
tags += "\n\t";
|
||||
}
|
||||
tag = '<meta';
|
||||
var y;
|
||||
for (y in tagsArr[x]) {
|
||||
tag += ' ' + y + '="' + tagsArr[x][y] + '"';
|
||||
}
|
||||
tag += ' />';
|
||||
|
||||
tags += tag;
|
||||
}
|
||||
|
||||
return tags;
|
||||
},
|
||||
|
||||
buildLinkTags: function(tagsArr) {
|
||||
var tags = '',
|
||||
tag;
|
||||
for (var x = 0, numTags = tagsArr.length; x < numTags; x++) {
|
||||
if (tags.length > 0) tags += "\n\t";
|
||||
tag = '<link';
|
||||
var y;
|
||||
for (y in tagsArr[x]) {
|
||||
tag += ' ' + y + '="' + tagsArr[x][y] + '"';
|
||||
}
|
||||
tag += ' />';
|
||||
|
||||
tags += tag;
|
||||
}
|
||||
|
||||
return tags;
|
||||
},
|
||||
|
||||
isRelativeUrl: function(url) {
|
||||
var firstChar = url.slice(0, 1);
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>{browserTitle}</title>
|
||||
{meta_tags}
|
||||
<link rel="icon" type="image/x-icon" href="{brand:favicon}" />
|
||||
<!-- BEGIN metaTags -->
|
||||
<meta<!-- IF metaTags.name --> name="{metaTags.name}"<!-- ENDIF metaTags.name --><!-- IF metaTags.property --> property="{metaTags.property}"<!-- ENDIF metaTags.property --><!-- IF metaTags.content --> content="{metaTags.content}"<!-- ENDIF metaTags.content --> />
|
||||
<!-- END metaTags -->
|
||||
<link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="{relative_path}/css/theme.css?{cache-buster}" />
|
||||
<!-- IF bootswatchCSS --><link href="{bootswatchCSS}" rel="stylesheet" media="screen"><!-- ENDIF bootswatchCSS -->
|
||||
{link_tags}
|
||||
<!-- BEGIN linkTags -->
|
||||
<link<!-- IF linkTags.link --> link="{linkTags.link}"<!-- ENDIF linkTags.link --><!-- IF linkTags.rel --> rel="{linkTags.rel}"<!-- ENDIF linkTags.rel --><!-- IF linkTags.href --> href="{linkTags.href}"<!-- ENDIF linkTags.href --> />
|
||||
<!-- END linkTags -->
|
||||
<!-- BEGIN pluginCSS -->
|
||||
<link rel="stylesheet" href="{pluginCSS.path}?{cache-buster}">
|
||||
<!-- END pluginCSS -->
|
||||
|
||||
@@ -287,21 +287,16 @@ var fs = require('fs'),
|
||||
}, function (err, results) {
|
||||
if (results.minFile > results.mtime) {
|
||||
winston.info('No changes to client-side libraries -- skipping minification');
|
||||
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile) + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '')]);
|
||||
callback(null, [path.relative(path.join(__dirname, '../public'), Meta.js.minFile)]);
|
||||
} else {
|
||||
Meta.js.minify(function () {
|
||||
callback(null, [
|
||||
path.relative(path.join(__dirname, '../public'), Meta.js.minFile) + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '')
|
||||
path.relative(path.join(__dirname, '../public'), Meta.js.minFile)
|
||||
]);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (meta.config['cache-buster']) {
|
||||
scripts = scripts.map(function(script) {
|
||||
return script + '?v=' + meta.config['cache-buster'];
|
||||
});
|
||||
}
|
||||
callback(null, scripts);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -94,13 +94,11 @@ module.exports.server = server;
|
||||
}],
|
||||
templateValues = {
|
||||
bootswatchCSS: meta.config['theme:src'],
|
||||
pluginCSS: plugins.cssFiles.map(function(file) { return { path: nconf.get('relative_path') + file.replace(/\\/g, '/') + (meta.config['cache-buster'] ? '?v=' + meta.config['cache-buster'] : '') }; }),
|
||||
pluginCSS: plugins.cssFiles.map(function(file) { return { path: nconf.get('relative_path') + file.replace(/\\/g, '/') }; }),
|
||||
title: meta.config.title || '',
|
||||
description: meta.config.description || '',
|
||||
'brand:logo': meta.config['brand:logo'] || '',
|
||||
'brand:logo:display': meta.config['brand:logo']?'':'hide',
|
||||
'brand:favicon': meta.config['brand:favicon'] || nconf.get('relative_path') + '/favicon.ico',
|
||||
browserTitle: meta.config.browserTitle || 'NodeBB',
|
||||
csrf: options.res.locals.csrf_token,
|
||||
relative_path: nconf.get('relative_path'),
|
||||
clientScripts: clientScripts,
|
||||
@@ -119,13 +117,20 @@ module.exports.server = server;
|
||||
var uid = '0';
|
||||
|
||||
// Meta Tags
|
||||
templateValues.meta_tags = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || []).map(function(tag) {
|
||||
templateValues.metaTags = defaultMetaTags.concat(options.metaTags || []).map(function(tag) {
|
||||
tag.content = tag.content.replace(/[&<>'"]/g, function(tag) {
|
||||
return escapeList[tag] || tag;
|
||||
});
|
||||
return tag;
|
||||
}));
|
||||
templateValues.link_tags = utils.buildLinkTags(defaultLinkTags.concat(options.linkTags || []));
|
||||
});
|
||||
|
||||
// Link Tags
|
||||
templateValues.linkTags = defaultLinkTags.concat(options.linkTags || []);
|
||||
templateValues.linkTags.push({
|
||||
rel: "icon",
|
||||
type: "image/x-icon",
|
||||
href: meta.config['brand:favicon'] || nconf.get('relative_path') + '/favicon.ico'
|
||||
});
|
||||
|
||||
if(options.req.user && options.req.user.uid) {
|
||||
uid = options.req.user.uid;
|
||||
|
||||
Reference in New Issue
Block a user