fix: fix seo title

This commit is contained in:
fantasticit 2022-04-13 09:06:04 +08:00
parent 3e0d8a4781
commit f1b039a687
6 changed files with 66 additions and 55 deletions

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Helmet } from 'react-helmet';
interface IProps {
@ -9,6 +9,10 @@ interface IProps {
const buildTitle = (title) => `${title} - 云策文档`;
export const Seo: React.FC<IProps> = ({ title, needTitleSuffix = true }) => {
useEffect(() => {
window.document.title = needTitleSuffix ? buildTitle(title) : title;
}, [title, needTitleSuffix]);
return (
<Helmet>
<title>{needTitleSuffix ? buildTitle(title) : title}</title>

View File

@ -13,8 +13,8 @@ interface IProps {
wikiId: string;
}
export const WorkspaceDocs: React.FC<IProps> = ({ wikiId }) => {
const { data: workspace, loading: workspaceLoading, toggleStatus: toggleWorkspaceStatus } = useWikiDetail(wikiId);
export const Documents: React.FC<IProps> = ({ wikiId }) => {
const { data: wiki, loading: wikiLoading, toggleStatus: toggleWorkspaceStatus } = useWikiDetail(wikiId);
const { data: tocs, loading } = useWikiTocs(wikiId);
const documents = flattenTree2Array(tocs).map((d) => {
d.label = d.title;
@ -22,7 +22,7 @@ export const WorkspaceDocs: React.FC<IProps> = ({ wikiId }) => {
return d;
});
const [nextStatus, setNextStatus] = useState('');
const isPublic = useMemo(() => workspace && isPublicWiki(workspace.status), [workspace]);
const isPublic = useMemo(() => wiki && isPublicWiki(wiki.status), [wiki]);
const [publicDocumentIds, setPublicDocumentIds] = useState([]); // 公开的
const privateDocumentIds = useMemo(() => {
return documents.filter((doc) => !publicDocumentIds.includes(doc.id)).map((doc) => doc.id);
@ -69,9 +69,9 @@ export const WorkspaceDocs: React.FC<IProps> = ({ wikiId }) => {
}, []);
useEffect(() => {
if (!workspace) return;
setNextStatus(workspace.status);
}, [workspace]);
if (!wiki) return;
setNextStatus(wiki.status);
}, [wiki]);
useEffect(() => {
if (!documents.length) return;

View File

@ -1,9 +1,10 @@
import React from 'react';
import { Tabs, TabPane } from '@douyinfe/semi-ui';
import { Seo } from 'components/seo';
import { useWikiDetail } from 'data/wiki';
import { Base } from './base';
import { Users } from './users';
import { WorkspaceDocs } from './documents';
import { Documents } from './documents';
import { More } from './more';
interface IProps {
@ -12,23 +13,33 @@ interface IProps {
onNavigate: (arg: string) => void;
}
const TitleMap = {
base: '基础信息',
users: '成员管理',
docs: '隐私管理',
more: '更多',
};
export const WikiSetting: React.FC<IProps> = ({ wikiId, tab, onNavigate }) => {
const { data, loading, error, update } = useWikiDetail(wikiId);
const { data, update } = useWikiDetail(wikiId);
return (
<Tabs lazyRender type="line" activeKey={tab} onChange={onNavigate}>
<TabPane tab="基础信息" itemKey="base">
<Base wiki={data} update={update as any} />
</TabPane>
<TabPane tab="成员管理" itemKey="users">
<Users wikiId={wikiId} />
</TabPane>
<TabPane tab="隐私管理" itemKey="docs">
<WorkspaceDocs wikiId={wikiId} />
</TabPane>
<TabPane tab="更多" itemKey="more">
<More wikiId={wikiId} />
</TabPane>
</Tabs>
<>
<Seo title={TitleMap[tab]} />
<Tabs lazyRender type="line" activeKey={tab} onChange={onNavigate}>
<TabPane tab={TitleMap['base']} itemKey="base">
<Base wiki={data} update={update as any} />
</TabPane>
<TabPane tab={TitleMap['users']} itemKey="users">
<Users wikiId={wikiId} />
</TabPane>
<TabPane tab={TitleMap['docs']} itemKey="docs">
<Documents wikiId={wikiId} />
</TabPane>
<TabPane tab={TitleMap['more']} itemKey="more">
<More wikiId={wikiId} />
</TabPane>
</Tabs>
</>
);
};

View File

@ -4,8 +4,6 @@ import { Avatar, Button, Typography, Skeleton, Tooltip } from '@douyinfe/semi-ui
import { IconPlus } from '@douyinfe/semi-icons';
import { isPublicWiki } from '@think/domains';
import { useWikiDetail, useWikiTocs } from 'data/wiki';
import { useToggle } from 'hooks/use-toggle';
import { Seo } from 'components/seo';
import { findParents } from 'components/wiki/tocs/utils';
import { IconDocument, IconSetting, IconOverview, IconGlobe } from 'components/icons';
import { DataRender } from 'components/data-render';
@ -19,20 +17,19 @@ interface IProps {
documentId?: string;
docAsLink?: string;
getDocLink?: (arg: string) => string;
pageTitle: string;
// pageTitle: string;
}
const { Text } = Typography;
export const WikiTocs: React.FC<IProps> = ({
pageTitle,
// pageTitle,
wikiId,
documentId = null,
docAsLink = '/wiki/[wikiId]/document/[documentId]',
getDocLink = (documentId) => `/wiki/${wikiId}/document/${documentId}`,
}) => {
const { pathname } = useRouter();
const [visible, toggleVisible] = useToggle(false);
const { data: wiki, loading: wikiLoading, error: wikiError } = useWikiDetail(wikiId);
const { data: tocs, loading: tocsLoading, error: tocsError, refresh } = useWikiTocs(wikiId);
const [parentIds, setParentIds] = useState<Array<string>>([]);
@ -74,28 +71,25 @@ export const WikiTocs: React.FC<IProps> = ({
}
error={wikiError}
normalContent={() => (
<>
<Seo title={wiki.name + ' - ' + pageTitle} />
<NavItem
icon={
<Avatar
shape="square"
size="small"
src={wiki.avatar}
style={{
marginRight: 8,
width: 24,
height: 24,
borderRadius: 4,
}}
>
{wiki.name.charAt(0)}
</Avatar>
}
text={<Text strong>{wiki.name}</Text>}
hoverable={false}
/>
</>
<NavItem
icon={
<Avatar
shape="square"
size="small"
src={wiki.avatar}
style={{
marginRight: 8,
width: 24,
height: 24,
borderRadius: 4,
}}
>
{wiki.name.charAt(0)}
</Avatar>
}
text={<Text strong>{wiki.name}</Text>}
hoverable={false}
/>
)}
/>

View File

@ -1,16 +1,17 @@
import { NextPage } from 'next';
import Router, { useRouter } from 'next/router';
import React, { useCallback } from 'react';
import { Typography, List, Tabs, TabPane, Tree } from '@douyinfe/semi-ui';
import { Typography, List, Tabs, TabPane } from '@douyinfe/semi-ui';
import { CreateDocumentIllustration } from 'illustrations/create-document';
import { DoubleColumnLayout } from 'layouts/double-column';
import { Seo } from 'components/seo';
import { DataRender } from 'components/data-render';
import { WikiTocs } from 'components/wiki/tocs';
import { WikiTocsManager } from 'components/wiki/tocs/manager';
import { useWikiDocs } from 'data/wiki';
import { DocumentCardPlaceholder, DocumentCard } from 'components/document/card';
import { Empty } from 'components/empty';
import { DocumentCreator } from 'components/document-creator';
import { useWikiDocs } from 'data/wiki';
interface IProps {
wikiId: string;
@ -79,9 +80,10 @@ const Page: NextPage<IProps> = ({ wikiId }) => {
return (
<DoubleColumnLayout
leftNode={<WikiTocs pageTitle="文档管理" wikiId={wikiId} />}
leftNode={<WikiTocs wikiId={wikiId} />}
rightNode={
<>
<Seo title={tab === 'documents' ? '全部文档' : '目录管理'} />
<Title heading={3} style={{ marginBottom: 24 }}>
</Title>

View File

@ -26,9 +26,9 @@ const Page: NextPage<IProps> = ({ wikiId }) => {
return (
<DoubleColumnLayout
leftNode={<WikiTocs pageTitle="设置" wikiId={wikiId} />}
leftNode={<WikiTocs wikiId={wikiId} />}
rightNode={<WikiSetting wikiId={wikiId} tab={tab} onNavigate={(tab) => navigate(tab)()} />}
></DoubleColumnLayout>
/>
);
};