A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: Dynamically set the app generator according to the app version number.
haitaoo20bca5a262f2
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.tsindex 76583a8d..1797813f 100644--- a/ui/src/common/interface.ts+++ b/ui/src/common/interface.ts@@ -319,6 +319,7 @@ export interface SiteSettings {custom_css_html: AdminSettingsCustom;theme: AdminSettingsTheme;site_seo: AdminSettingsSeo;+ version: string;}export interface AdminSettingBranding {diff --git a/ui/src/components/PageTags/index.tsx b/ui/src/components/PageTags/index.tsxindex 449bd0ec..ba777f05 100644--- a/ui/src/components/PageTags/index.tsx+++ b/ui/src/components/PageTags/index.tsx@@ -1,7 +1,7 @@-import { FC } from 'react';+import { FC, useEffect } from 'react';import { Helmet } from 'react-helmet-async';-import { brandingStore, pageTagStore } from '@/stores';+import { brandingStore, pageTagStore, siteInfoStore } from '@/stores';const doInsertCustomCSS = !document.querySelector('link[href*="custom.css"]');@@ -10,6 +10,23 @@ const Index: FC = () => {const { pageTitle, keywords, description } = pageTagStore((state) => state.items,);+ const appVersion = siteInfoStore((_) => _.version);+ const setAppGenerator = () => {+ if (!appVersion) {+ return;+ }+ const generatorMetaNode = document.querySelector('meta[name="generator"]');+ if (generatorMetaNode) {+ generatorMetaNode.setAttribute(+ 'content',+ `Answer ${appVersion} - https://github.com/answerdev/answer`,+ );+ }+ };++ useEffect(() => {+ setAppGenerator();+ }, [appVersion]);return (<Helmet><linkdiff --git a/ui/src/stores/siteInfo.ts b/ui/src/stores/siteInfo.tsindex e484f554..26c5321b 100644--- a/ui/src/stores/siteInfo.ts+++ b/ui/src/stores/siteInfo.ts@@ -5,7 +5,9 @@ import { DEFAULT_SITE_NAME } from '@/common/constants';interface SiteInfoType {siteInfo: AdminSettingsGeneral;+ version: string;update: (params: AdminSettingsGeneral) => void;+ updateVersion: (ver: string) => void;}const siteInfo = create<SiteInfoType>((set) => ({@@ -17,6 +19,7 @@ const siteInfo = create<SiteInfoType>((set) => ({contact_email: '',permalink: 1,},+ version: '',update: (params) =>set((_) => {const o = { ..._.siteInfo, ...params };@@ -27,6 +30,11 @@ const siteInfo = create<SiteInfoType>((set) => ({siteInfo: o,};}),+ updateVersion: (ver) => {+ set(() => {+ return { version: ver };+ });+ },}));export default siteInfo;diff --git a/ui/src/utils/guard.ts b/ui/src/utils/guard.tsindex 3ca73e0e..5b592180 100644--- a/ui/src/utils/guard.ts+++ b/ui/src/utils/guard.ts@@ -257,6 +257,7 @@ export const initAppSettingsStore = async () => {const appSettings = await getAppSettings();if (appSettings) {siteInfoStore.getState().update(appSettings.general);+ siteInfoStore.getState().updateVersion(appSettings.version);interfaceStore.getState().update(appSettings.interface);brandingStore.getState().update(appSettings.branding);loginSettingStore.getState().update(appSettings.login);