Ghost/core/server/data/meta/index.js
Hannah Wolfe c4d3bd7cd2 Fix errors in JSON-LD output
refs #6534

- don't output publisher for the 'People' type on the author page
- change publisher to a full 'Organisation' for the 'Article' type on posts

Note:
Google's structured data validator also wants image & publisher.logo inside of Article to be full 'ImageObject's.
Currently, it output's an error for them: 'The attribute itemtype has an invalid value.'
However, the spec on Schema.org says a url is valid: https://schema.org/Article,
which is slightly different to Google's spec here: https://developers.google.com/structured-data/rich-snippets/articles#article_markup_properties

Ideally, we would output a full 'ImageObject', however we don't currently have the width & height info required.
Therefore, I think what we have is valid strictly speaking, but we should aim to fix this when we have better image tools.
2016-05-13 15:13:11 +02:00

63 lines
2.3 KiB
JavaScript

var config = require('../../config'),
getUrl = require('./url'),
getCanonicalUrl = require('./canonical_url'),
getPaginatedUrl = require('./paginated_url'),
getAuthorUrl = require('./author_url'),
getRssUrl = require('./rss_url'),
getTitle = require('./title'),
getDescription = require('./description'),
getCoverImage = require('./cover_image'),
getAuthorImage = require('./author_image'),
getAuthorFacebook = require('./author_fb_url'),
getCreatorTwitter = require('./creator_url'),
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: getPaginatedUrl('prev', data, true),
nextUrl: getPaginatedUrl('next', 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),
authorFacebook: getAuthorFacebook(data),
creatorTwitter: getCreatorTwitter(data),
keywords: getKeywords(data),
publishedDate: getPublishedDate(data),
modifiedDate: getModifiedDate(data),
ogType: getOgType(data),
blog: blog
};
metaData.blog.logo = metaData.blog.logo ?
config.urlFor('image', {image: metaData.blog.logo}, true) : config.urlFor({relativeUrl: '/ghost/img/ghosticon.jpg'}, {}, true);
// 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;