mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 15:20:39 +01:00
feat: populate and send link tag/header respectively for activitypub-enabled content
This commit is contained in:
@@ -4,6 +4,7 @@ const nconf = require('nconf');
|
||||
const _ = require('lodash');
|
||||
|
||||
const db = require('../../database');
|
||||
const meta = require('../../meta');
|
||||
const user = require('../../user');
|
||||
const posts = require('../../posts');
|
||||
const categories = require('../../categories');
|
||||
@@ -53,7 +54,12 @@ profileController.get = async function (req, res, next) {
|
||||
userData.profileviews = 1;
|
||||
}
|
||||
|
||||
addMetaTags(res, userData);
|
||||
addTags(res, userData);
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
// Include link header for richer parsing
|
||||
res.set('Link', `<${nconf.get('url')}/uid/${userData.uid}>; rel="alternate"; type="application/activity+json"`);
|
||||
}
|
||||
|
||||
res.render('account/profile', userData);
|
||||
};
|
||||
@@ -124,7 +130,7 @@ async function getPosts(callerUid, userData, setSuffix) {
|
||||
return postData.slice(0, count);
|
||||
}
|
||||
|
||||
function addMetaTags(res, userData) {
|
||||
function addTags(res, userData) {
|
||||
const plainAboutMe = userData.aboutme ? utils.stripHTMLTags(utils.decodeHTMLEntities(userData.aboutme)) : '';
|
||||
res.locals.metaTags = [
|
||||
{
|
||||
@@ -161,4 +167,12 @@ function addMetaTags(res, userData) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
res.locals.linkTags = [{
|
||||
rel: 'alternate',
|
||||
type: 'application/activity+json',
|
||||
href: `${nconf.get('url')}/uid/${userData.uid}`,
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,11 @@ categoryController.get = async function (req, res, next) {
|
||||
|
||||
analytics.increment([`pageviews:byCid:${categoryData.cid}`]);
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
// Include link header for richer parsing
|
||||
res.set('Link', `<${nconf.get('url')}/actegory/${cid}>; rel="alternate"; type="application/activity+json"`);
|
||||
}
|
||||
|
||||
res.render('category', categoryData);
|
||||
};
|
||||
|
||||
@@ -229,4 +234,12 @@ function addTags(categoryData, res, currentPage) {
|
||||
href: categoryData.rssFeedUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
res.locals.linkTags.push({
|
||||
rel: 'alternate',
|
||||
type: 'application/activity+json',
|
||||
href: `${nconf.get('url')}/actegory/${categoryData.cid}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const nconf = require('nconf');
|
||||
const querystring = require('querystring');
|
||||
|
||||
const meta = require('../meta');
|
||||
const posts = require('../posts');
|
||||
const privileges = require('../privileges');
|
||||
const utils = require('../utils');
|
||||
@@ -27,6 +29,11 @@ postsController.redirectToPost = async function (req, res, next) {
|
||||
return helpers.notAllowed(req, res);
|
||||
}
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
// Include link header for richer parsing
|
||||
res.set('Link', `<${nconf.get('url')}/post/${req.params.pid}>; rel="alternate"; type="application/activity+json"`);
|
||||
}
|
||||
|
||||
const qs = querystring.stringify(req.query);
|
||||
helpers.redirect(res, qs ? `${path}?${qs}` : path, true);
|
||||
};
|
||||
|
||||
@@ -133,6 +133,12 @@ topicsController.get = async function getTopic(req, res, next) {
|
||||
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
|
||||
res.locals.linkTags.push(rel);
|
||||
});
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
// Include link header for richer parsing
|
||||
res.set('Link', `<${nconf.get('url')}/topic/${tid}>; rel="alternate"; type="application/activity+json"`);
|
||||
}
|
||||
|
||||
res.render('topic', topicData);
|
||||
};
|
||||
|
||||
@@ -284,6 +290,15 @@ async function addTags(topicData, req, res, currentPage) {
|
||||
href: `${url}/user/${postAtIndex.user.userslug}`,
|
||||
});
|
||||
}
|
||||
|
||||
if (meta.config.activitypubEnabled) {
|
||||
const { pid } = topicData.posts[topicData.postIndex - 1];
|
||||
res.locals.linkTags.push({
|
||||
rel: 'alternate',
|
||||
type: 'application/activity+json',
|
||||
href: utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function addOGImageTags(res, topicData, postAtIndex) {
|
||||
|
||||
Reference in New Issue
Block a user