mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
ghost_head improvements (#8983)
no issue - Added debug statements to ghost_head - useful for determining how much render time is spent in ghost head - Make promises more readable - Used join instead of props for less code
This commit is contained in:
parent
c64c56f1dc
commit
cdf6a10490
1 changed files with 81 additions and 79 deletions
|
@ -9,6 +9,7 @@
|
|||
var proxy = require('./proxy'),
|
||||
_ = require('lodash'),
|
||||
Promise = require('bluebird'),
|
||||
debug = require('ghost-ignition').debug('ghost_head'),
|
||||
|
||||
getMetaData = proxy.metaData.get,
|
||||
getAssetUrl = proxy.metaData.getAssetUrl,
|
||||
|
@ -24,7 +25,9 @@ var proxy = require('./proxy'),
|
|||
|
||||
function getClient() {
|
||||
if (labs.isSet('publicAPI') === true) {
|
||||
return api.clients.read({slug: 'ghost-frontend'}).then(function (client) {
|
||||
return api.clients
|
||||
.read({slug: 'ghost-frontend'})
|
||||
.then(function handleClient(client) {
|
||||
client = client.clients[0];
|
||||
|
||||
if (client.status === 'enabled') {
|
||||
|
@ -80,30 +83,26 @@ function getAjaxHelper(clientId, clientSecret) {
|
|||
}
|
||||
|
||||
module.exports = function ghost_head(options) {
|
||||
debug('begin');
|
||||
// if server error page do nothing
|
||||
if (this.statusCode >= 500) {
|
||||
return;
|
||||
}
|
||||
|
||||
var metaData,
|
||||
client,
|
||||
head = [],
|
||||
var head = [],
|
||||
globalCodeinjection = settingsCache.get('ghost_head'),
|
||||
postCodeInjection = options.data.root && options.data.root.post ? options.data.root.post.codeinjection_head : null,
|
||||
context = this.context ? this.context : null,
|
||||
useStructuredData = !config.isPrivacyDisabled('useStructuredData'),
|
||||
safeVersion = this.safeVersion,
|
||||
referrerPolicy = config.get('referrerPolicy') ? config.get('referrerPolicy') : 'no-referrer-when-downgrade',
|
||||
fetch = {
|
||||
metaData: getMetaData(this, options.data.root),
|
||||
client: getClient()
|
||||
},
|
||||
favicon = blogIconUtils.getIconUrl(),
|
||||
iconType = blogIconUtils.getIconType(favicon);
|
||||
|
||||
return Promise.props(fetch).then(function (response) {
|
||||
client = response.client;
|
||||
metaData = response.metaData;
|
||||
debug('preparation complete, begin fetch');
|
||||
return Promise
|
||||
.join(getMetaData(this, options.data.root), getClient(), function handleData(metaData, client) {
|
||||
debug('end fetch');
|
||||
|
||||
if (context) {
|
||||
// head is our main array that holds our meta data
|
||||
|
@ -167,9 +166,12 @@ module.exports = function ghost_head(options) {
|
|||
}
|
||||
}
|
||||
return filters.doFilter('ghost_head', head);
|
||||
}).then(function (head) {
|
||||
})
|
||||
.then(function afterFilters(head) {
|
||||
debug('end');
|
||||
return new SafeString(head.join('\n ').trim());
|
||||
}).catch(function handleError(err) {
|
||||
})
|
||||
.catch(function handleError(err) {
|
||||
logging.error(err);
|
||||
|
||||
// Return what we have so far (currently nothing)
|
||||
|
|
Loading…
Add table
Reference in a new issue