diff --git a/app/assets/javascripts/discourse/app/components/about-page.gjs b/app/assets/javascripts/discourse/app/components/about-page.gjs index 9406dd14188..5d929aaa44c 100644 --- a/app/assets/javascripts/discourse/app/components/about-page.gjs +++ b/app/assets/javascripts/discourse/app/components/about-page.gjs @@ -9,6 +9,16 @@ import i18n from "discourse-common/helpers/i18n"; import escape from "discourse-common/lib/escape"; import I18n from "discourse-i18n"; +const pluginActivitiesFuncs = []; + +export function addAboutPageActivity(name, func) { + pluginActivitiesFuncs.push({ name, func }); +} + +export function clearAboutPageActivities() { + pluginActivitiesFuncs.clear(); +} + export default class AboutPage extends Component { get moderatorsCount() { return this.args.model.moderators.length; @@ -57,7 +67,7 @@ export default class AboutPage extends Component { } get siteActivities() { - return [ + const list = [ { icon: "scroll", class: "topics", @@ -104,6 +114,8 @@ export default class AboutPage extends Component { period: I18n.t("about.activities.periods.all_time"), }, ]; + + return list.concat(this.siteActivitiesFromPlugins()); } get contactInfo() { @@ -139,6 +151,33 @@ export default class AboutPage extends Component { } } + siteActivitiesFromPlugins() { + const stats = this.args.model.stats; + const statKeys = Object.keys(stats); + + const configs = []; + for (const { name, func } of pluginActivitiesFuncs) { + let present = false; + const periods = {}; + for (const stat of statKeys) { + const prefix = `${name}_`; + if (stat.startsWith(prefix)) { + present = true; + const period = stat.replace(prefix, ""); + periods[period] = stats[stat]; + } + } + if (!present) { + continue; + } + const config = func(periods); + if (config) { + configs.push(config); + } + } + return configs; + } +