Skip to content

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.

fix(SEO): Make `permalink` support short id

haitaoo3aaf29f8a533
diff --git a/ui/src/pages/Admin/Seo/index.tsx b/ui/src/pages/Admin/Seo/index.tsx
index 66625e8b..b95d8ea7 100644
--- a/ui/src/pages/Admin/Seo/index.tsx
+++ b/ui/src/pages/Admin/Seo/index.tsx
@@ -19,8 +19,13 @@ const Index: FC = () => {
type: 'number',
title: t('permalink.label'),
description: t('permalink.text'),
- enum: [1, 2],
- enumNames: ['/questions/123/post-title', '/questions/123'],
+ enum: [1, 2, 3, 4],
+ enumNames: [
+ '/questions/10020000009999999/post-title',
+ '/questions/10020000009999999',
+ '/questions/2jsXF/post-title',
+ '/questions/2jsXF',
+ ],
default: 1,
},
robots: {
@@ -74,7 +79,7 @@ const Index: FC = () => {
const formMeta = { ...formData };
formMeta.robots.value = setting.robots;
formMeta.permalink.value = setting.permalink;
- if (formMeta.permalink.value !== 1 && formMeta.permalink.value !== 2) {
+ if (!/[1234]/.test(formMeta.permalink.value)) {
formMeta.permalink.value = 1;
}
setFormData(formMeta);
diff --git a/ui/src/router/pathFactory.ts b/ui/src/router/pathFactory.ts
index 7b267bf8..fbf4e0ca 100644
--- a/ui/src/router/pathFactory.ts
+++ b/ui/src/router/pathFactory.ts
@@ -19,7 +19,8 @@ const tagEdit = (tagId: string) => {
};
const questionLanding = (questionId: string, slugTitle: string = '') => {
const { seo } = seoSettingStore.getState();
- if (seo.permalink === 1 && slugTitle) {
+ // @ts-ignore
+ if (/[13]/.test(seo.permalink) && slugTitle) {
return urlcat('/questions/:questionId/:slugPermalink', {
questionId,
slugPermalink: slugTitle,
diff --git a/ui/src/stores/seoSetting.ts b/ui/src/stores/seoSetting.ts
index 800c480a..6c15e9cf 100644
--- a/ui/src/stores/seoSetting.ts
+++ b/ui/src/stores/seoSetting.ts
@@ -15,7 +15,8 @@ const siteInfo = create<IProps>((set) => ({
update: (params) =>
set((state) => {
const o = { ...state.seo, ...params };
- if (o.permalink !== 1 && o.permalink !== 2) {
+ // @ts-ignore
+ if (!/[1234]/.test(o.permalink)) {
o.permalink = 1;
}
return {