mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-23 11:49:51 +02:00
fix: default to showing alternate as link to the post object
This commit is contained in:
@@ -137,7 +137,9 @@ topicsController.get = async function getTopic(req, res, next) {
|
|||||||
|
|
||||||
if (meta.config.activitypubEnabled) {
|
if (meta.config.activitypubEnabled) {
|
||||||
// Include link header for richer parsing
|
// Include link header for richer parsing
|
||||||
res.set('Link', `<${nconf.get('url')}/topic/${tid}>; rel="alternate"; type="application/activity+json"`);
|
const pid = await topics.getPidByIndex(tid, postIndex);
|
||||||
|
const href = utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid;
|
||||||
|
res.set('Link', `<${href}>; rel="alternate"; type="application/activity+json"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render('topic', topicData);
|
res.render('topic', topicData);
|
||||||
@@ -293,9 +295,7 @@ async function addTags(topicData, req, res, currentPage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (meta.config.activitypubEnabled) {
|
if (meta.config.activitypubEnabled) {
|
||||||
const pid = topicData.postIndex !== 1 ?
|
const pid = await topics.getPidByIndex(topicData.tid, topicData.postIndex);
|
||||||
(await db.getSortedSetRange(`tid:${topicData.tid}:posts`, topicData.postIndex - 2, topicData.postIndex - 2)).pop() :
|
|
||||||
topicData.mainPid;
|
|
||||||
|
|
||||||
res.locals.linkTags.push({
|
res.locals.linkTags.push({
|
||||||
rel: 'alternate',
|
rel: 'alternate',
|
||||||
|
|||||||
@@ -313,4 +313,11 @@ Topics.search = async function (tid, term) {
|
|||||||
return Array.isArray(result) ? result : result.ids;
|
return Array.isArray(result) ? result : result.ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.getPidByIndex = async function (tid, index) {
|
||||||
|
index -= 2; // zset only stores replies, index is not zero-indexed, so offset by 2.
|
||||||
|
return index > 0 ?
|
||||||
|
(await db.getSortedSetRange(`tid:${tid}:posts`, index - 2, index - 2)).pop() :
|
||||||
|
await Topics.getTopicField(tid, 'mainPid');
|
||||||
|
};
|
||||||
|
|
||||||
require('../promisify')(Topics);
|
require('../promisify')(Topics);
|
||||||
|
|||||||
Reference in New Issue
Block a user