feat(seo): add robots setting for seo

This commit is contained in:
haitao(lj) 2022-12-06 10:35:06 +08:00
parent ceb8f099bf
commit 1812d59cd9
14 changed files with 112 additions and 18 deletions

View File

@ -955,6 +955,7 @@ ui:
write: Write
tos: Terms of Service
privacy: Privacy
seo: SEO
admin:
admin_header:
title: Admin
@ -1204,6 +1205,11 @@ ui:
reserved_tags:
label: Reserved Tags
text: "Reserved tags can only be added to a post by moderator."
seo:
page_title: SEO
robots:
label: robots.txt
text: This will permanently override any related site settings.
form:
empty: cannot be empty
invalid: is invalid

View File

@ -62,6 +62,7 @@ export const ADMIN_NAV_MENUS = [
{ name: 'smtp' },
{ name: 'legal' },
{ name: 'write' },
{ name: 'seo' },
],
},
];

View File

@ -338,6 +338,10 @@ export interface AdminSettingsWrite {
reserved_tags: string[];
}
export interface AdminSettingsSeo {
robots: string;
}
/**
* @description interface for Activity
*/

View File

@ -21,8 +21,6 @@ import { useAnswerSearch, changeAnswerStatus } from '@/services';
import { escapeRemove } from '@/utils';
import { pathFactory } from '@/router/pathFactory';
import '../index.scss';
const answerFilterItems: Type.AdminContentsFilterBy[] = ['normal', 'deleted'];
const Answers: FC = () => {

View File

@ -16,8 +16,6 @@ import { useFlagSearch } from '@/services';
import { escapeRemove } from '@/utils';
import { pathFactory } from '@/router/pathFactory';
import '../index.scss';
const flagFilterKeys: Type.FlagStatus[] = ['pending', 'completed'];
const flagTypeKeys: Type.FlagType[] = ['all', 'question', 'answer', 'comment'];

View File

@ -9,8 +9,6 @@ import { useGeneralSetting, updateGeneralSetting } from '@/services';
import Pattern from '@/common/pattern';
import { handleFormError } from '@/utils';
import '../index.scss';
const General: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'admin.general',

View File

@ -8,7 +8,6 @@ import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
import { useToast } from '@/hooks';
import { getLegalSetting, putLegalSetting } from '@/services';
import { handleFormError } from '@/utils';
import '../index.scss';
const Legal: FC = () => {
const { t } = useTranslation('translation', {

View File

@ -20,8 +20,6 @@ import * as Type from '@/common/interface';
import { useQuestionSearch, changeQuestionStatus } from '@/services';
import { pathFactory } from '@/router/pathFactory';
import '../index.scss';
const questionFilterItems: Type.AdminContentsFilterBy[] = [
'normal',
'closed',

View File

@ -0,0 +1,86 @@
import { FC, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type * as Type from '@/common/interface';
import { getSeoSetting, putSeoSetting } from '@/services';
import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
import { useToast } from '@/hooks';
import { handleFormError } from '@/utils';
const Index: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'admin.seo',
});
const Toast = useToast();
const schema: JSONSchema = {
title: t('page_title'),
properties: {
robots: {
type: 'string',
title: t('robots.label'),
description: t('robots.text'),
},
},
};
const uiSchema: UISchema = {
robots: {
'ui:widget': 'textarea',
'ui:options': {
rows: 10,
},
},
};
const [formData, setFormData] = useState(initFormData(schema));
const onSubmit = (evt) => {
evt.preventDefault();
evt.stopPropagation();
const reqParams: Type.AdminSettingsSeo = {
robots: formData.robots.value,
};
putSeoSetting(reqParams)
.then(() => {
Toast.onShow({
msg: t('update', { keyPrefix: 'toast' }),
variant: 'success',
});
})
.catch((err) => {
if (err.isError) {
const data = handleFormError(err, formData);
setFormData({ ...data });
}
});
};
useEffect(() => {
getSeoSetting().then((setting) => {
if (setting) {
const formMeta = { ...formData };
formMeta.robots.value = setting.robots;
setFormData(formMeta);
}
});
}, []);
const handleOnChange = (data) => {
setFormData(data);
};
return (
<>
<h3 className="mb-4">{t('page_title')}</h3>
<SchemaForm
schema={schema}
formData={formData}
onSubmit={onSubmit}
uiSchema={uiSchema}
onChange={handleOnChange}
/>
</>
);
};
export default Index;

View File

@ -5,8 +5,7 @@ import type * as Type from '@/common/interface';
import { useToast } from '@/hooks';
import { useSmtpSetting, updateSmtpSetting } from '@/services';
import pattern from '@/common/pattern';
import { SchemaForm, JSONSchema, UISchema } from '@/components';
import { initFormData } from '../../../components/SchemaForm/index';
import { SchemaForm, JSONSchema, UISchema, initFormData } from '@/components';
import { handleFormError } from '@/utils';
const Smtp: FC = () => {

View File

@ -18,8 +18,6 @@ import { useChangeModal, useChangeUserRoleModal, useToast } from '@/hooks';
import { useQueryUsers } from '@/services';
import { loggedUserInfoStore } from '@/stores';
import '../index.scss';
const UserFilterKeys: Type.UserFilterBy[] = [
'all',
'staff',

View File

@ -10,14 +10,11 @@ import {
} from '@/services';
import { handleFormError } from '@/utils';
import '../index.scss';
const Legal: FC = () => {
const Index: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'admin.write',
});
const Toast = useToast();
// const updateSiteInfo = siteInfoStore((state) => state.update);
const schema: JSONSchema = {
title: t('page_title'),
@ -125,4 +122,4 @@ const Legal: FC = () => {
);
};
export default Legal;
export default Index;

View File

@ -276,6 +276,10 @@ const routes: RouteNode[] = [
path: 'write',
page: 'pages/Admin/Write',
},
{
path: 'seo',
page: 'pages/Admin/Seo',
},
],
},
// for review

View File

@ -101,3 +101,11 @@ export const getLegalSetting = () => {
export const putLegalSetting = (params: Type.AdminSettingsLegal) => {
return request.put('/answer/admin/api/siteinfo/legal', params);
};
export const getSeoSetting = () => {
return request.get<Type.AdminSettingsSeo>('/answer/admin/api/siteinfo/seo');
};
export const putSeoSetting = (params: Type.AdminSettingsSeo) => {
return request.put('/answer/admin/api/siteinfo/seo', params);
};