diff --git a/core/frontend/meta/excerpt.js b/core/frontend/meta/excerpt.js
new file mode 100644
index 0000000000..453c3f989b
--- /dev/null
+++ b/core/frontend/meta/excerpt.js
@@ -0,0 +1,21 @@
+const generateExcerpt = require('./generate-excerpt');
+
+function getExcerpt(data) {
+ // NOTE: should use 'post' OR 'page' once https://github.com/TryGhost/Ghost/issues/10042 is resolved
+ if (!data.post) {
+ return;
+ }
+ // There's a specific order for description fields (not !!) in structured data
+ // and schema.org which is used the description fields (see https://github.com/TryGhost/Ghost/issues/8793):
+ // 1. CASE: custom_excerpt is populated via the UI
+ // 2. CASE: no custom_excerpt, but meta_description is poplated via the UI
+ // 3. CASE: fall back to automated excerpt of 50 words if neither custom_excerpt nor meta_description is provided
+ // @TODO: https://github.com/TryGhost/Ghost/issues/10062
+ const customExcerpt = data.post.excerpt || data.post.custom_excerpt;
+ const metaDescription = data.post.meta_description;
+ const fallbackExcerpt = data.post.html ? generateExcerpt(data.post.html, {words: 50}) : '';
+
+ return customExcerpt ? customExcerpt : metaDescription ? metaDescription : fallbackExcerpt;
+}
+
+module.exports = getExcerpt;
diff --git a/core/frontend/meta/index.js b/core/frontend/meta/index.js
index 9f8117b332..f475b682fe 100644
--- a/core/frontend/meta/index.js
+++ b/core/frontend/meta/index.js
@@ -24,7 +24,7 @@ const getOgImage = require('./og_image');
const getTwitterImage = require('./twitter_image');
const getStructuredData = require('./structured_data');
const getSchema = require('./schema');
-const generateExcerpt = require('./generate-excerpt');
+const getExcerpt = require('./excerpt');
function getMetaData(data, root) {
const metaData = {
@@ -37,6 +37,7 @@ function getMetaData(data, root) {
rssUrl: getRssUrl(data, true),
metaTitle: getTitle(data, root),
metaDescription: getDescription(data, root) || null,
+ excerpt: getExcerpt(data),
coverImage: {
url: getCoverImage(data, true)
},
@@ -73,26 +74,6 @@ function getMetaData(data, root) {
}
};
- let customExcerpt;
- let metaDescription;
- let fallbackExcerpt;
-
- // TODO: cleanup these if statements
- // NOTE: should use 'post' OR 'page' once https://github.com/TryGhost/Ghost/issues/10042 is resolved
- if (data.post) {
- // There's a specific order for description fields (not !!) in structured data
- // and schema.org which is used the description fields (see https://github.com/TryGhost/Ghost/issues/8793):
- // 1. CASE: custom_excerpt is populated via the UI
- // 2. CASE: no custom_excerpt, but meta_description is poplated via the UI
- // 3. CASE: fall back to automated excerpt of 50 words if neither custom_excerpt nor meta_description is provided
- // @TODO: https://github.com/TryGhost/Ghost/issues/10062
- customExcerpt = data.post.excerpt || data.post.custom_excerpt;
- metaDescription = data.post.meta_description;
- fallbackExcerpt = data.post.html ? generateExcerpt(data.post.html, {words: 50}) : '';
-
- metaData.excerpt = customExcerpt ? customExcerpt : metaDescription ? metaDescription : fallbackExcerpt;
- }
-
if (data.post && data.post.primary_author && data.post.primary_author.name) {
metaData.authorName = data.post.primary_author.name;
}