From 4e844bcaac7e2e42e308c5e9b487d00080209ab3 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Mon, 29 Apr 2019 17:53:29 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20404=20in=20collectio?= =?UTF-8?q?n=20index=20page=20if=20using=20data.slug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #10542 - Fixed error that was causing collection index to not be rendered: relations connected to alliased resource were not fetched --- .../services/routing/helpers/fetch-data.js | 10 +- core/test/unit/data/meta/schema_spec.js | 100 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/core/server/services/routing/helpers/fetch-data.js b/core/server/services/routing/helpers/fetch-data.js index ff824278ddf..d6e08c6b058 100644 --- a/core/server/services/routing/helpers/fetch-data.js +++ b/core/server/services/routing/helpers/fetch-data.js @@ -28,6 +28,13 @@ const defaultQueryOptions = { } }; +const defaultDataQueryOptions = { + post: _.cloneDeep(defaultQueryOptions), + page: _.cloneDeep(defaultQueryOptions), + tag: null, + author: null +}; + const defaultPostQuery = _.cloneDeep(queryDefaults); defaultPostQuery.options = defaultQueryOptions.options; @@ -97,7 +104,8 @@ function fetchData(pathOptions, routerOptions, locals) { // CASE: fetch more data defined by the router e.g. tags, authors - see TaxonomyRouter _.each(routerOptions.data, function (query, name) { - props[name] = processQuery(query, pathOptions.slug, locals); + const dataQueryOptions = _.merge(query, defaultDataQueryOptions[name]); + props[name] = processQuery(dataQueryOptions, pathOptions.slug, locals); }); return Promise.props(props) diff --git a/core/test/unit/data/meta/schema_spec.js b/core/test/unit/data/meta/schema_spec.js index 4cfba455c5a..cb154efcdf8 100644 --- a/core/test/unit/data/meta/schema_spec.js +++ b/core/test/unit/data/meta/schema_spec.js @@ -102,6 +102,106 @@ describe('getSchema', function () { done(); }); + it('should return page schema if context starts with page', function (done) { + var metadata = { + blog: { + title: 'Blog Title', + url: 'http://mysite.com', + logo: { + url: 'http://mysite.com/author/image/url/logo.jpg', + dimensions: { + width: 500, + height: 500 + } + } + }, + authorImage: { + url: 'http://mysite.com/author/image/url/me.jpg', + dimensions: { + width: 500, + height: 500 + } + }, + authorFacebook: 'testuser', + creatorTwitter: '@testuser', + authorUrl: 'http://mysite.com/author/me/', + metaTitle: 'Page Title', + url: 'http://mysite.com/post/my-page-slug/', + publishedDate: '2015-12-25T05:35:01.234Z', + modifiedDate: '2016-01-21T22:13:05.412Z', + coverImage: { + url: 'http://mysite.com/content/image/mypagecoverimage.jpg', + dimensions: { + width: 500, + height: 500 + } + }, + keywords: ['one', 'two'], + metaDescription: 'Post meta description', + excerpt: 'Custom excerpt for description' + }, data = { + context: ['page'], + page: { + primary_author: { + name: 'Page Author', + website: 'http://myblogsite.com/', + bio: 'My author bio.', + facebook: 'testuser', + twitter: '@testuser' + } + } + }, + schema = getSchema(metadata, data); + + should.deepEqual(schema, { + '@context': 'https://schema.org', + '@type': 'Article', + author: { + '@type': 'Person', + image: { + '@type': 'ImageObject', + url: 'http://mysite.com/author/image/url/me.jpg', + width: 500, + height: 500 + }, + name: 'Page Author', + sameAs: [ + 'http://myblogsite.com/', + 'https://www.facebook.com/testuser', + 'https://twitter.com/testuser' + ], + url: 'http://mysite.com/author/me/' + }, + dateModified: '2016-01-21T22:13:05.412Z', + datePublished: '2015-12-25T05:35:01.234Z', + description: 'Custom excerpt for description', + headline: 'Page Title', + image: { + '@type': 'ImageObject', + url: 'http://mysite.com/content/image/mypagecoverimage.jpg', + width: 500, + height: 500 + }, + keywords: 'one, two', + mainEntityOfPage: { + '@type': 'WebPage', + '@id': 'http://mysite.com' + }, + publisher: { + '@type': 'Organization', + name: 'Blog Title', + logo: { + '@type': 'ImageObject', + url: 'http://mysite.com/author/image/url/logo.jpg', + width: 500, + height: 500 + } + }, + url: 'http://mysite.com/post/my-page-slug/' + }); + done(); + }); + it('should return post schema if context starts with amp', function (done) { var metadata = { blog: { From 63fa899607759078e8131d5f1bb50f7443553411 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Tue, 30 Apr 2019 11:26:28 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20meta=20schema=20for?= =?UTF-8?q?=20'page'=20context=20in=20dynamic=20routing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #10082 - When specifying an existing page as an allias for collection, e.g: `data: page.it-is-a-page` it was failing to generate metadata --- core/server/data/meta/schema.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/server/data/meta/schema.js b/core/server/data/meta/schema.js index 9974f645390..9f13f278e0e 100644 --- a/core/server/data/meta/schema.js +++ b/core/server/data/meta/schema.js @@ -38,15 +38,15 @@ function trimSchema(schema) { function trimSameAs(data, context) { var sameAs = []; - if (context === 'post') { - if (data.post.primary_author.website) { - sameAs.push(escapeExpression(data.post.primary_author.website)); + if (context === 'post' || context === 'page') { + if (data[context].primary_author.website) { + sameAs.push(escapeExpression(data[context].primary_author.website)); } - if (data.post.primary_author.facebook) { - sameAs.push(social.urls.facebook(data.post.primary_author.facebook)); + if (data[context].primary_author.facebook) { + sameAs.push(social.urls.facebook(data[context].primary_author.facebook)); } - if (data.post.primary_author.twitter) { - sameAs.push(social.urls.twitter(data.post.primary_author.twitter)); + if (data[context].primary_author.twitter) { + sameAs.push(social.urls.twitter(data[context].primary_author.twitter)); } } else if (context === 'author') { if (data.author.website) { @@ -69,6 +69,8 @@ function getPostSchema(metaData, data) { var description = metaData.excerpt ? escapeExpression(metaData.excerpt) : null, schema; + const context = data.page ? 'page' : 'post'; + schema = { '@context': 'https://schema.org', '@type': 'Article', @@ -79,12 +81,12 @@ function getPostSchema(metaData, data) { }, author: { '@type': 'Person', - name: escapeExpression(data.post.primary_author.name), + name: escapeExpression(data[context].primary_author.name), image: schemaImageObject(metaData.authorImage), url: metaData.authorUrl, - sameAs: trimSameAs(data, 'post'), - description: data.post.primary_author.metaDescription ? - escapeExpression(data.post.primary_author.metaDescription) : + sameAs: trimSameAs(data, context), + description: data[context].primary_author.metaDescription ? + escapeExpression(data[context].primary_author.metaDescription) : null }, headline: escapeExpression(metaData.metaTitle),