🐛 Fixed published time and modified time for structured data (#12085)

closes #12059

- Published Time and Modified Time were not populating for 'page' context because it is an extension of 'post' and hence there was no context 'page'. 
- Fixed it by using the common contextObject & `getContextObject` utility. 
- Should also fix some other missing parameters.
This commit is contained in:
Roshan Dash 2020-08-17 20:22:31 +05:30 committed by GitHub
parent 3430c47725
commit c81d11b910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -1,16 +1,17 @@
const urlService = require('../services/url');
const getContextObject = require('./context_object.js');
function getAuthorUrl(data, absolute) {
let context = data.context ? data.context[0] : null;
context = context === 'amp' ? 'post' : context;
const contextObject = getContextObject(data, context);
if (data.author) {
return urlService.getUrlByResourceId(data.author.id, {absolute: absolute, secure: data.author.secure, withSubdirectory: true});
}
if (data[context] && data[context].primary_author) {
return urlService.getUrlByResourceId(data[context].primary_author.id, {absolute: absolute, secure: data[context].secure, withSubdirectory: true});
if (contextObject && contextObject.primary_author) {
return urlService.getUrlByResourceId(contextObject.primary_author.id, {absolute: absolute, secure: contextObject.secure, withSubdirectory: true});
}
return null;

View File

@ -1,13 +1,13 @@
const _ = require('lodash');
const getContextObject = require('./context_object.js');
function getModifiedDate(data) {
let context = data.context ? data.context : null;
let modDate;
context = _.includes(context, 'amp') ? 'post' : context;
const contextObject = getContextObject(data, context);
if (data[context]) {
modDate = data[context].updated_at || null;
if (contextObject) {
modDate = contextObject.updated_at || null;
if (modDate) {
return new Date(modDate).toISOString();
}

View File

@ -1,10 +1,12 @@
const getContextObject = require('./context_object.js');
function getPublishedDate(data) {
let context = data.context ? data.context[0] : null;
context = context === 'amp' ? 'post' : context;
const contextObject = getContextObject(data, context);
if (data[context] && data[context].published_at) {
return new Date(data[context].published_at).toISOString();
if (contextObject && contextObject.published_at) {
return new Date(contextObject.published_at).toISOString();
}
return null;
}