mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: closes #11921
This commit is contained in:
@@ -206,13 +206,13 @@ async function addTags(topicData, req, res, currentPage) {
|
|||||||
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
|
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
|
||||||
let description = '';
|
let description = '';
|
||||||
if (postAtIndex && postAtIndex.content) {
|
if (postAtIndex && postAtIndex.content) {
|
||||||
description = utils.stripHTMLTags(utils.decodeHTMLEntities(postAtIndex.content));
|
description = utils.stripHTMLTags(utils.decodeHTMLEntities(postAtIndex.content)).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description.length > 160) {
|
if (description.length > 160) {
|
||||||
description = `${description.slice(0, 157)}...`;
|
description = `${description.slice(0, 157)}...`;
|
||||||
}
|
}
|
||||||
description = description.replace(/\n/g, ' ');
|
description = description.replace(/\n/g, ' ').trim();
|
||||||
|
|
||||||
let mainPost = topicData.posts.find(p => parseInt(p.index, 10) === 0);
|
let mainPost = topicData.posts.find(p => parseInt(p.index, 10) === 0);
|
||||||
if (!mainPost) {
|
if (!mainPost) {
|
||||||
@@ -224,18 +224,10 @@ async function addTags(topicData, req, res, currentPage) {
|
|||||||
name: 'title',
|
name: 'title',
|
||||||
content: topicData.titleRaw,
|
content: topicData.titleRaw,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'description',
|
|
||||||
content: description,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
property: 'og:title',
|
property: 'og:title',
|
||||||
content: topicData.titleRaw,
|
content: topicData.titleRaw,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
property: 'og:description',
|
|
||||||
content: description,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
property: 'og:type',
|
property: 'og:type',
|
||||||
content: 'article',
|
content: 'article',
|
||||||
@@ -254,6 +246,19 @@ async function addTags(topicData, req, res, currentPage) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (description && description.length) {
|
||||||
|
res.locals.metaTags.push(
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
content: description,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:description',
|
||||||
|
content: description,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await addOGImageTags(res, topicData, postAtIndex);
|
await addOGImageTags(res, topicData, postAtIndex);
|
||||||
|
|
||||||
const page = currentPage > 1 ? `?page=${currentPage}` : '';
|
const page = currentPage > 1 ? `?page=${currentPage}` : '';
|
||||||
|
|||||||
Reference in New Issue
Block a user