closes #11218, 🚋

This commit is contained in:
Barış Soner Uşaklı
2023-02-16 11:51:07 -05:00
parent e4446ae14a
commit bc23ae80cc
2 changed files with 22 additions and 0 deletions

View File

@@ -43,6 +43,11 @@
"ban-ip": "Ban IP",
"view-history": "Edit History",
"wrote-ago": "wrote <span class=\"timeago\" title=\"%1\"></span>",
"wrote-on": "wrote on <span class=\"timeago\" title=\"%1\"></span>",
"replied-to-user-ago": "replied to <a component=\"post/parent\" data-topid=\"%1\" href=\"%2\">%3</a> <span class=\"timeago\" title=\"%4\"></span>",
"replied-to-user-on": "replied to <a component=\"post/parent\" data-topid=\"%1\" href=\"%2\">%3</a> on <span class=\"timeago\" title=\"%4\"></span>",
"user-locked-topic-ago": "%1 locked this topic %2",
"user-locked-topic-on": "%1 locked this topic on %2",
"user-unlocked-topic-ago": "%1 unlocked this topic %2",

View File

@@ -3,6 +3,7 @@
module.exports = function (utils, Benchpress, relative_path) {
Benchpress.setGlobal('true', true);
Benchpress.setGlobal('false', false);
const oneDayInMs = 24 * 60 * 60 * 1000;
const helpers = {
displayMenuItem,
@@ -24,6 +25,8 @@ module.exports = function (utils, Benchpress, relative_path) {
userAgentIcons,
buildAvatar,
increment,
generateRepliedTo,
generateWrote,
register,
__escape: identity,
};
@@ -320,6 +323,20 @@ module.exports = function (utils, Benchpress, relative_path) {
return value + parseInt(inc, 10);
}
function generateRepliedTo(post, timeagoCutoff) {
const username = post.parent && post.parent.username ?
post.parent.username : '[[global:guest]]';
const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs));
const langSuffix = isBeforeCutoff ? 'on' : 'ago';
return `[[topic:replied-to-user-${langSuffix}, ${post.pid}, ${relative_path}/post/${post.pid}, ${username}, ${post.timestampISO}]]`;
}
function generateWrote(post, timeagoCutoff) {
const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs));
const langSuffix = isBeforeCutoff ? 'on' : 'ago';
return `[[topic:wrote-${langSuffix}, ${post.timestampISO}]]`;
}
function register() {
Object.keys(helpers).forEach(function (helperName) {
Benchpress.registerHelper(helperName, helpers[helperName]);