-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Facebook and Twitter data per post feature (#8827)
closes #8334 - adds title, image and description to structured data to be rendered as open graph and twitter data. - if meta title and description for a post exists already, the custom structured data will overwrite those for `og:` and `twitter:` data. `JSON-LD` (Schema.org`) is not affected and will stay the same. - adds tests - adds new og and twitter fields to schema incl. migration
- Loading branch information
Showing
17 changed files
with
705 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var utils = require('../../utils'), | ||
getContextObject = require('./context_object.js'), | ||
_ = require('lodash'); | ||
|
||
function getOgImage(data) { | ||
var context = data.context ? data.context : null, | ||
contextObject = getContextObject(data, context); | ||
|
||
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) { | ||
if (contextObject.og_image) { | ||
return utils.url.urlFor('image', {image: contextObject.og_image}, true); | ||
} else if (contextObject.feature_image) { | ||
return utils.url.urlFor('image', {image: contextObject.feature_image}, true); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
module.exports = getOgImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var utils = require('../../utils'), | ||
getContextObject = require('./context_object.js'), | ||
_ = require('lodash'); | ||
|
||
function getTwitterImage(data) { | ||
var context = data.context ? data.context : null, | ||
contextObject = getContextObject(data, context); | ||
|
||
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) { | ||
if (contextObject.twitter_image) { | ||
return utils.url.urlFor('image', {image: contextObject.twitter_image}, true); | ||
} else if (contextObject.feature_image) { | ||
return utils.url.urlFor('image', {image: contextObject.feature_image}, true); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
module.exports = getTwitterImage; |
100 changes: 100 additions & 0 deletions
100
core/server/data/migrations/versions/1.5/1-og-twitter-post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use strict'; | ||
|
||
const Promise = require('bluebird'), | ||
logging = require('../../../../logging'), | ||
commands = require('../../../schema').commands, | ||
table = 'posts', | ||
column1 = 'og_image', | ||
column2 = 'og_title', | ||
column3 = 'og_description', | ||
column4 = 'twitter_image', | ||
column5 = 'twitter_title', | ||
column6 = 'twitter_description', | ||
message1 = 'Adding column: ' + table + '.' + column1, | ||
message2 = 'Adding column: ' + table + '.' + column2, | ||
message3 = 'Adding column: ' + table + '.' + column3, | ||
message4 = 'Adding column: ' + table + '.' + column4, | ||
message5 = 'Adding column: ' + table + '.' + column5, | ||
message6 = 'Adding column: ' + table + '.' + column6; | ||
|
||
module.exports = function addCodeInjectionPostColumns(options) { | ||
let transacting = options.transacting; | ||
|
||
return transacting.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transacting.schema.hasColumn(table, column1); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message1); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message1); | ||
return commands.addColumn(table, column1, transacting); | ||
}) | ||
.then(function () { | ||
return transacting.schema.hasColumn(table, column2); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message2); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message2); | ||
return commands.addColumn(table, column2, transacting); | ||
}) | ||
.then(function () { | ||
return transacting.schema.hasColumn(table, column3); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message3); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message3); | ||
return commands.addColumn(table, column3, transacting); | ||
}) | ||
.then(function () { | ||
return transacting.schema.hasColumn(table, column4); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message4); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message4); | ||
return commands.addColumn(table, column4, transacting); | ||
}) | ||
.then(function () { | ||
return transacting.schema.hasColumn(table, column5); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message5); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message5); | ||
return commands.addColumn(table, column5, transacting); | ||
}) | ||
.then(function () { | ||
return transacting.schema.hasColumn(table, column6); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logging.warn(message6); | ||
return Promise.resolve(); | ||
} | ||
|
||
logging.info(message6); | ||
return commands.addColumn(table, column6, transacting); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.