fix: post urls to use prefix instead of linking out directly to origin server, exposed encodeURIComponent as a template helper for themes

This commit is contained in:
Julian Lam
2024-03-21 00:41:53 -04:00
parent 6fa43b9ef0
commit 2408ecd8dc
2 changed files with 8 additions and 3 deletions

View File

@@ -27,6 +27,7 @@ module.exports = function (utils, Benchpress, relative_path) {
increment, increment,
generateRepliedTo, generateRepliedTo,
generateWrote, generateWrote,
encodeURIComponent: _encodeURIComponent,
isoTimeToLocaleString, isoTimeToLocaleString,
shouldHideReplyContainer, shouldHideReplyContainer,
humanReadableNumber, humanReadableNumber,
@@ -340,13 +341,17 @@ module.exports = function (utils, Benchpress, relative_path) {
post.parent.displayname : '[[global:guest]]'; post.parent.displayname : '[[global:guest]]';
const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs));
const langSuffix = isBeforeCutoff ? 'on' : 'ago'; const langSuffix = isBeforeCutoff ? 'on' : 'ago';
return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${relative_path}/post/${post.toPid}, ${displayname}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${relative_path}/post/${encodeURIComponent(post.toPid)}, ${displayname}, ${relative_path}/post/${encodeURIComponent(post.pid)}, ${post.timestampISO}]]`;
} }
function generateWrote(post, timeagoCutoff) { function generateWrote(post, timeagoCutoff) {
const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs));
const langSuffix = isBeforeCutoff ? 'on' : 'ago'; const langSuffix = isBeforeCutoff ? 'on' : 'ago';
return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${encodeURIComponent(post.pid)}, ${post.timestampISO}]]`;
}
function _encodeURIComponent(value) {
return encodeURIComponent(value);
} }
function isoTimeToLocaleString(isoTime, locale = 'en-GB') { function isoTimeToLocaleString(isoTime, locale = 'en-GB') {

View File

@@ -154,7 +154,7 @@ inbox.announce = async (req) => {
await topics.events.log(tid, { await topics.events.log(tid, {
type: 'announce', type: 'announce',
uid: actor, uid: actor,
href: `/post/${pid}`, href: `/post/${encodeURIComponent(pid)}`,
pid, pid,
timestamp, timestamp,
}); });