Skip to content

Commit

Permalink
Custom sitemap item value
Browse files Browse the repository at this point in the history
  • Loading branch information
ihavecoke committed Jun 13, 2024
1 parent b3092f8 commit 416e7f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
17 changes: 15 additions & 2 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const i18n = require("./i18n/config");


const isDev = process.env.NODE_ENV !== "production";
const proxy = process.env.PROXY || 'release';
const proxy = process.env.PROXY || "release";
const ossEnv = isDev ? "/" : proxy;
const targetPortalPath = proxy === "canary" ? "https://m.longbridge.xyz" : "https://m.lbkrs.com";
const localAPIProxyPath = "/dev-proxy";
Expand All @@ -29,7 +29,7 @@ const config: Config = {
baseUrlIssueBanner: false,
onBrokenLinks: "ignore",
onBrokenMarkdownLinks: "ignore",
ssrTemplate:genSSRTemplate(ossEnv),
ssrTemplate: genSSRTemplate(ossEnv),
trailingSlash: false, // https://docusaurus.io/docs/api/docusaurus-config#trailingSlash
favicon: "https://pub.lbkrs.com/static/offline/202211/qohHsXzN9qtQ23ox/longport_favicon.png",
customFields: {
Expand Down Expand Up @@ -107,7 +107,20 @@ const config: Config = {
},
theme: {
customCss: "./src/css/custom.scss"
},
sitemap: {
createSitemapItems: async (params) => {
const { defaultCreateSitemapItems, ...rest } = params;
const items = await defaultCreateSitemapItems(rest);
return await items.map((item) => {
return item.url = item.url
.replace("zh-CN/zh-CN", "zh-CN")
.replace("en/en", "en")
.replace("zh-HK/zh-HK", "zh-HK")
});
}
}

} satisfies Preset.Options
]
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "docusaurus start --port 4040",
"dev": "yarn start",
"build": "yarn clear && docusaurus build --out-dir ./dist",
"dev:build": "docusaurus build --out-dir ./dist",
"postbuild": "sh ./setup-dist-dir.sh",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
Expand Down
13 changes: 5 additions & 8 deletions setup-dist-dir.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# step 1 create basic dirs
# mv all dist to temp dir for backup
mv ./dist/zh-CN /tmp/ && mv ./dist/zh-HK /tmp/ && mv ./dist/en /tmp/
mv ./dist/learn.html ./dist/en/
mv ./dist/sitemap.xml ./dist/en/
mv ./dist/404.html ./dist/en/
mv ./dist/.nojekyll ./dist/en/

# cp all dist file to dist/en
mkdir -p ./dist/en
mv ./dist/* ./dist/en/
mv /tmp/zh-CN ./dist/ && mv /tmp/zh-HK ./dist/ && mv /tmp/en/* ./dist/en/

# step 3 remove duplicated files
# step 2 remove duplicated files
cp -rf ./dist/zh-CN/zh-CN/* ./dist/zh-CN/ && rm -rf ./dist/zh-CN/zh-CN
cp -rf ./dist/zh-HK/zh-HK/* ./dist/zh-HK/ && rm -rf ./dist/zh-HK/zh-HK

0 comments on commit 416e7f8

Please sign in to comment.