Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: site seo settings #106

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/hooks/use-seo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect, useCallback, useMemo } from "react";

interface SeoProps {
title?: string;
description?: string;
image?: string;
url?: string;
type?: string;
}

export function useSeo(props: SeoProps | string) {
const { title } = typeof props === 'string' ? { title: props } : props;
const siteName = 'Mog Console';
const siteDescription = 'The Powerfull Console for Mog System';

const seo = useMemo(() => {
return {
title: `${title} - ${siteName}` || siteName,
description: siteDescription,
};
}, [title, siteName, siteDescription]);

const updateTitle = useCallback(() => {
document.title = seo.title;
}, [seo]);

useEffect(() => {
updateTitle();
}, [updateTitle]);
}
2 changes: 2 additions & 0 deletions src/pages/Categories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import type { BasicPage } from "@type/basic";
import { apiClient } from "@utils/request";
import { Input, Textarea } from "@pages/Write/Input";
import styles from "./index.module.css";
import { useSeo } from "@hooks/use-seo";

export const CategoriesPage: BasicPage = () => {
useSeo("分类 & 标签")
const [loading, setLoading] = useState(true);
const serverSnapshot = useSnapshot(server);
const navigate = useNavigate();
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Comments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Modal, ModalBody } from "@components/universal/Modal";
import { Input, Textarea } from "@pages/Write/Input";
import { Selects } from "@components/universal/Select";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/use-seo";

const tabsList = [{
name: "待审核",
Expand All @@ -33,6 +34,7 @@ const tabsList = [{
}]

export const CommentsPage: BasicPage = () => {
useSeo("评论 · 列表")
const status = getQueryVariable("status")
const page = Number(getQueryVariable("page")) || 1
const navigate = useNavigate()
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Friends/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import postStyles from "@pages/Posts/Index/index.module.css";
import { Input, Textarea } from "@pages/Write/Input";
import styles from "./index.module.css";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/use-seo";

const FriendsStatus = ["Approved", "Pending", "Spam", "Trash"];
const FriendsFormFront = [
Expand Down Expand Up @@ -76,6 +77,7 @@ const FriendsFormBack = [
];

export const FriendsPage: BasicPage = () => {
useSeo("朋友 · 列表")
const [loading, setLoading] = useState(true);
const [inSideLoading, setInSideLoading] = useState(true);
const [select, setSelect] = useState<string[]>([]);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { apiClient } from "@utils/request";
import { Loading } from "@components/universal/Loading";
import { GridContainer, Widget, TableContainer, TableItem } from "./universal";
import { useNavigate } from "react-router-dom";
import { useSeo } from "@hooks/use-seo";

export const Home: BasicPage = () => {
useSeo("仪表盘")
const [loading, setLoading] = useState(true);
const navigate = useNavigate();

Expand Down
2 changes: 2 additions & 0 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { Twindow } from "@components/universal/Twindow";
import { app } from "@states/app";
import { setCookie } from "@utils/cookie";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/use-seo";

export const Login: BasicPage = () => {
useSeo("登录")
const [loading, setLoading] = useState(false);
const formRef = useRef<HTMLFormElement>(null);
const navigate = useNavigate();
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Pages/Index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
TableItemValue,
} from "@pages/Home/universal";
import styles from "../../Posts/Index/index.module.css";
import { useSeo } from "@hooks/use-seo";

export const PagesIndex: BasicPage = () => {
useSeo("页面 · 列表")
const [loading, setLoading] = useState(true);
const [select, setSelect] = useState<string[]>([]); // 选择的页面
const navigate = useNavigate();
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Posts/Friends/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
} from "@pages/Home/universal";
import styles from "../Index/index.module.css";
import pageStyles from "./index.module.css";
import { useSeo } from "@hooks/use-seo";

export const FriendsPosts: BasicPage = () => {
useSeo("好友动态")
const [loading, setLoading] = useState(true);
const [data, setData] = useState<{
data: any[];
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Posts/Index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
TableItemValue,
} from "@pages/Home/universal";
import styles from "./index.module.css";
import { useSeo } from "@hooks/use-seo";

export const PostsIndex: BasicPage = () => {
useSeo("文章 · 列表");
const [loading, setLoading] = useState(true);
const [select, setSelect] = useState<string[]>([]); // 选择的文章
const navigate = useNavigate();
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Register/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { Twindow } from "@components/universal/Twindow";
import { app } from "@states/app";
import { setCookie } from "@utils/cookie";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/use-seo";

// nickname, description, email, avatar, password, username

export const RegisterPage: BasicPage = () => {
useSeo("注册")
const navigate = useNavigate();
app.showSidebar = false;
const [loading, setLoading] = useState(false);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { useNavigate } from "react-router-dom";
import { Tags } from "@components/universal/Tags";
import { Toggle } from "@components/universal/Toggle";
import { jump } from "@utils/path";
import { useSeo } from "@hooks/use-seo";

const tabsAPI = ["/user/master/info", "/configs"]

export const SettingsPage: BasicPage = () => {
useSeo("设置")
const [loading, setLoading] = useState(true);
const [data, setData] = useState<any>({});
const tab = getQueryVariable("tab")
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { BasicPage } from "@type/basic";
import { API } from "@utils/request";
import { TableItem, TableItemValue } from "@pages/Home/universal";
import styles from "./index.module.css";
import { useSeo } from "@hooks/use-seo";

interface IStatus {
status: "Operational" | "Down";
Expand All @@ -24,6 +25,7 @@ const Status: React.FC<IStatus> = (props) => {
};

export const StatusPage: BasicPage = () => {
useSeo("服务 · 状态")
const services = [
{
name: "核心网关层",
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Themes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import { useNavigate } from "react-router-dom";
import { Modal } from "@components/universal/Modal";
import { ThemeComponent } from "@components/widgets/ThemeComponent";
import { Space } from "@components/universal/Space";
import { useSeo } from "@hooks/use-seo";

const LIST = "https://ghproxy.com/https://raw.githubusercontent.com/mogland/awesome-mog/main/production-awesome-list/themes.json";

export const ThemesPage: BasicPage = () => {
useSeo("主题")
const _tab = Number(getQueryVariable("tab") || 0)
const [tab, setTab] = useState<number>(_tab);
const [loading, setLoading] = useState(false);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Write/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getQueryVariable } from "@utils/url";
import { Fields } from "./fields";
import styles from "./index.module.css";
import { Input, Textarea } from "./Input";
import { useSeo } from "@hooks/use-seo";

export const EditorPage: BasicPage = () => {
const [loading, setLoading] = useState(true);
Expand All @@ -31,6 +32,8 @@ export const EditorPage: BasicPage = () => {
const id = getQueryVariable("id");
const serverSnapshot = useSnapshot(server);

useSeo(`${data?.title ? data.title : "新建"}${type === "page" ? "页面" : "文章"}`);

useEffect(() => {
if (!id) {
setData({});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@utils/*": ["src/utils/*"],
"@type/*": ["src/types/*"],
"@states/*": ["src/states/*"],
"@hooks/*": ["src/hooks/*"],
}
},
"include": ["src"],
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
"@utils": path.resolve(__dirname, "src/utils"),
"@type": path.resolve(__dirname, "src/types"),
"@states": path.resolve(__dirname, "src/states"),
"@hooks": path.resolve(__dirname, "src/hooks"),
},
},
});