mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: meta description missing if url doesn't have post index
This commit is contained in:
@@ -166,9 +166,9 @@ async function buildBreadcrumbs(topicData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addTags(topicData, req, res) {
|
async function addTags(topicData, req, res) {
|
||||||
var postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, req.params.post_index - 1), 10));
|
const postIndex = parseInt(req.params.post_index, 10) || 0;
|
||||||
|
const postAtIndex = topicData.posts.find(p => parseInt(p.index, 10) === parseInt(Math.max(0, postIndex - 1), 10));
|
||||||
var 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));
|
||||||
}
|
}
|
||||||
@@ -329,10 +329,10 @@ topicsController.pagination = async function (req, res, callback) {
|
|||||||
return helpers.notAllowed(req, res);
|
return helpers.notAllowed(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
var postCount = topic.postcount;
|
const postCount = topic.postcount;
|
||||||
var pageCount = Math.max(1, Math.ceil(postCount / settings.postsPerPage));
|
const pageCount = Math.max(1, Math.ceil(postCount / settings.postsPerPage));
|
||||||
|
|
||||||
var paginationData = pagination.create(currentPage, pageCount);
|
const paginationData = pagination.create(currentPage, pageCount);
|
||||||
paginationData.rel.forEach(function (rel) {
|
paginationData.rel.forEach(function (rel) {
|
||||||
rel.href = nconf.get('url') + '/topic/' + topic.slug + rel.href;
|
rel.href = nconf.get('url') + '/topic/' + topic.slug + rel.href;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -918,6 +918,16 @@ describe('Topic\'s', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should load topic api data', function (done) {
|
||||||
|
request(nconf.get('url') + '/api/topic/' + topicData.slug, { json: true }, function (err, response, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(response.statusCode, 200);
|
||||||
|
assert.strictEqual(body._header.tags.meta.find(t => t.name === 'description').content, 'topic content');
|
||||||
|
assert.strictEqual(body._header.tags.meta.find(t => t.property === 'og:description').content, 'topic content');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should 404 if post index is invalid', function (done) {
|
it('should 404 if post index is invalid', function (done) {
|
||||||
request(nconf.get('url') + '/topic/' + topicData.slug + '/derp', function (err, response) {
|
request(nconf.get('url') + '/topic/' + topicData.slug + '/derp', function (err, response) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user