Skip to content

Commit

Permalink
fix: closes #11921
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 22, 2023
1 parent a7843a4 commit e396970
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/controllers/topics.js
Expand Up @@ -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));
let description = '';
if (postAtIndex && postAtIndex.content) {
description = utils.stripHTMLTags(utils.decodeHTMLEntities(postAtIndex.content));
description = utils.stripHTMLTags(utils.decodeHTMLEntities(postAtIndex.content)).trim();
}

if (description.length > 160) {
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);
if (!mainPost) {
Expand All @@ -224,18 +224,10 @@ async function addTags(topicData, req, res, currentPage) {
name: 'title',
content: topicData.titleRaw,
},
{
name: 'description',
content: description,
},
{
property: 'og:title',
content: topicData.titleRaw,
},
{
property: 'og:description',
content: description,
},
{
property: 'og:type',
content: 'article',
Expand All @@ -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);

const page = currentPage > 1 ? `?page=${currentPage}` : '';
Expand Down

0 comments on commit e396970

Please sign in to comment.