Ghost/core/server/data/meta/index.js
Hannah Wolfe dcc8bcc4f1 Strutured data: Slack Unfurls & published_at fix
refs #6534

- fixes a bug where published_at was incorrectly falling back to the created_at date
- updated meta index to get author name
- add written by & filed under labels + data if the values are present (only on posts/pages)
- updated tests
2016-02-22 01:45:00 +01:00

57 lines
1.9 KiB
JavaScript

var config = require('../../config'),
getUrl = require('./url'),
getCanonicalUrl = require('./canonical_url'),
getPreviousUrl = require('./previous_url'),
getNextUrl = require('./next_url'),
getAuthorUrl = require('./author_url'),
getRssUrl = require('./rss_url'),
getTitle = require('./title'),
getDescription = require('./description'),
getCoverImage = require('./cover_image'),
getAuthorImage = require('./author_image'),
getKeywords = require('./keywords'),
getPublishedDate = require('./published_date'),
getModifiedDate = require('./modified_date'),
getOgType = require('./og_type'),
getStructuredData = require('./structured_data'),
getSchema = require('./schema'),
getExcerpt = require('./excerpt');
function getMetaData(data, root) {
var blog = config.theme, metaData;
metaData = {
url: getUrl(data, true),
canonicalUrl: getCanonicalUrl(data),
previousUrl: getPreviousUrl(data, true),
nextUrl: getNextUrl(data, true),
authorUrl: getAuthorUrl(data, true),
rssUrl: getRssUrl(data, true),
metaTitle: getTitle(data, root),
metaDescription: getDescription(data, root),
coverImage: getCoverImage(data, true),
authorImage: getAuthorImage(data, true),
keywords: getKeywords(data),
publishedDate: getPublishedDate(data),
modifiedDate: getModifiedDate(data),
ogType: getOgType(data),
blog: blog
};
// TODO: cleanup these if statements
if (data.post && data.post.html) {
metaData.excerpt = getExcerpt(data.post.html, {words: 50});
}
if (data.post && data.post.author && data.post.author.name) {
metaData.authorName = data.post.author.name;
}
metaData.structuredData = getStructuredData(metaData);
metaData.schema = getSchema(metaData, data);
return metaData;
}
module.exports = getMetaData;