Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed May 15, 2024
1 parent f2aa627 commit 579d594
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { buildEnd } from "./config/buildEnd";
import { sidebar } from "./config/sidebar";
import { nav } from "./config/navbar";
import { markdown } from "./config/markdown";
import { head } from "./config/head";
import { head, transformPageData } from "./config/head";
import { vite } from "./config/vite";

export default defineConfig({
Expand All @@ -20,6 +20,7 @@ export default defineConfig({
},

head,
transformPageData,

themeConfig: {
logo: "/logo.png",
Expand Down
33 changes: 32 additions & 1 deletion .vitepress/config/head.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DefaultTheme, UserConfig } from "vitepress";
import type { DefaultTheme, PageData, UserConfig } from "vitepress";

const ogDescription =
"Zotero 中文社区,Zotero 中文维护小组,Zotero 插件,Zotero 中文 CSL 样式";
Expand Down Expand Up @@ -32,3 +32,34 @@ export const head: UserConfig["head"] = [
gtag('config', 'G-YHYFX0LRZK');`,
],
];

export const transformPageData = (pageData: PageData) => {
console.log(pageData);
pageData.frontmatter.head ??= [];
pageData.frontmatter.head.push([
"meta",
{
name: "citation_title",
content:
pageData.frontmatter.layout === "home"
? `Zotero 中文社区`
: `${pageData.title} | Zotero 中文社区`,
},
]);
pageData.frontmatter.head.push([
"meta",
{
name: "og:type",
content: pageData.frontmatter.layout === "doc" ? `document` : `website`,
},
]);

const canonicalUrl = `https://zotero-chinese.com/${pageData.relativePath}`
.replace(/index\.md$/, "")
.replace(/\.md$/, ".html");

pageData.frontmatter.head.push([
"link",
{ rel: "canonical", href: canonicalUrl },
]);
};

0 comments on commit 579d594

Please sign in to comment.