Node.js based forum software built for the modern web
feat: populate and send link tag/header respectively for activitypub-enabled content
Julian Lam4e0d7dd3648c
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.jsindex 1ef9756784..9aec78ee91 100644--- a/src/controllers/accounts/profile.js+++ b/src/controllers/accounts/profile.js@@ -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}`,+ }];+ }}diff --git a/src/controllers/category.js b/src/controllers/category.jsindex 9bf532cadb..fb2556dd78 100644--- a/src/controllers/category.js+++ b/src/controllers/category.js@@ -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}`,+ });+ }}diff --git a/src/controllers/posts.js b/src/controllers/posts.jsindex 24e8bdfbb7..3b3d5b3b82 100644--- a/src/controllers/posts.js+++ b/src/controllers/posts.js@@ -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);};diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex af4543cbe4..3a6fadd446 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -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) {