diff --git a/content/.vitepress/config.ts b/content/.vitepress/config.ts index 2aa7713..a784ed1 100644 --- a/content/.vitepress/config.ts +++ b/content/.vitepress/config.ts @@ -1,12 +1,33 @@ import { footnote } from '@mdit/plugin-footnote'; import VueJsx from '@vitejs/plugin-vue-jsx'; +import { fileURLToPath } from 'node:url'; import Unocss from 'unocss/vite'; import { defineConfig } from 'vitepress'; +import { generateSidebar, VitePressSidebarOptions } from 'vitepress-sidebar'; import imgPlugin from './plugins/imgPlugin'; -import getPostList from './theme/utils/getPostList'; + +const rootLocale = 'en'; +const commonSidebarConfigs: Partial = { + useTitleFromFrontmatter: true, + useFolderTitleFromIndexFile: true, + useFolderLinkFromIndexFile: true, + useTitleFromFileHeading: true, + collapsed: true, +}; + +const supportedLocales = [rootLocale, 'zh-Hans', 'ja'] as const; + +const sidebarConfigs = supportedLocales.map((lang) => { + return { + ...commonSidebarConfigs, + ...(rootLocale === lang ? {} : { basePath: `/${lang}/` }), // If using `rewrites` option + documentRootPath: `content/${lang}`, + resolvePath: rootLocale === lang ? '/' : `/${lang}/`, + }; +}); // https://vitepress.dev/reference/site-config -export default defineConfig({ +const vitePressConfig = defineConfig({ title: 'One Among Us', description: 'A community for East-Asian and East-Asian Canadian transgender and gender diverse people. An Ontario registered not-for-profit corporation.', @@ -15,6 +36,7 @@ export default defineConfig({ root: { label: 'English', lang: 'en', + themeConfig: {}, }, 'zh-Hans': { label: '简体中文', @@ -26,9 +48,6 @@ export default defineConfig({ { text: '通知公告', link: '/zh-Hans/posts' }, { text: '联系·支持', link: '/zh-Hans/contact' }, ], - sidebar: { - '/zh-Hans/posts': getPostList('zh-Hans'), - }, footer: { message: '若无特殊说明,本站内容以 知识共享 署名 4.0 协议授权', @@ -45,9 +64,6 @@ export default defineConfig({ // { text: 'アーカイブ', link: '/ja/posts' }, { text: '連絡先', link: '/ja/contact' }, ], - sidebar: { - '/ja/posts': getPostList('ja'), - }, footer: { message: '注があるものを除いて、このサイトの内容物は クリエイティブ・コモンズ 表示 4.0 ライセンスの下に提供されています。', @@ -67,9 +83,7 @@ export default defineConfig({ ], logo: '/assets/favicon-new.png', - sidebar: { - '/posts': getPostList(), - }, + sidebar: generateSidebar(sidebarConfigs), footer: { message: @@ -110,17 +124,25 @@ export default defineConfig({ ], }, rewrites: { - 'posts/index.md': 'posts.md', - 'people/index.md': 'people.md', - 'zh-Hans/posts/index.md': 'zh-Hans/posts.md', - 'ja/posts/index.md': 'ja/posts.md', - 'ja/links/index.md': 'ja/links.md', - 'zh-Hans/events/index.md': 'zh-Hans/events.md', + 'en/:rest*': ':rest*', }, + vite: { plugins: [VueJsx(), Unocss()], server: { host: '0.0.0.0' }, css: { preprocessorOptions: { sass: { api: 'modern' } } }, + resolve: { + alias: [ + { + find: '@', + replacement: fileURLToPath(new URL('../', import.meta.url)), + }, + { + find: /^.*\/VPHome\.vue$/, + replacement: fileURLToPath(new URL('./theme/OurHome.vue', import.meta.url)), + }, + ], + }, }, markdown: { config: (md) => { @@ -129,3 +151,7 @@ export default defineConfig({ }, }, }); + +// http://localhost:5173/content/zh-Hans/posts/statement-linux-foundation +// http://localhost:5173/zh-Hans/posts/statement-linux-foundation +export default vitePressConfig; diff --git a/content/.vitepress/theme/index.tsx b/content/.vitepress/theme/index.tsx index 482a3b5..f93d185 100644 --- a/content/.vitepress/theme/index.tsx +++ b/content/.vitepress/theme/index.tsx @@ -1,13 +1,7 @@ // https://vitepress.dev/guide/custom-theme import 'uno.css'; -import Theme from 'vitepress/theme'; -import OurHome from './OurHome.vue'; +import DefaultTheme from 'vitepress/theme'; import './style.css'; // import './scss/main.scss'; -export default { - ...Theme, - enhanceApp({ app, router, siteData }) { - app.component('ourhome', OurHome); - }, -}; +export default DefaultTheme; diff --git a/content/.vitepress/theme/utils/getPostList.data.ts b/content/.vitepress/theme/utils/getPostList.data.ts index df2b0b0..cde26be 100644 --- a/content/.vitepress/theme/utils/getPostList.data.ts +++ b/content/.vitepress/theme/utils/getPostList.data.ts @@ -1,3 +1,8 @@ +import PostData from '@/.vitepress/types/PostData'; import { createContentLoader } from 'vitepress'; -export default createContentLoader('posts/**/*.md'); +export default createContentLoader('en/posts/**/*.md', { + transform: (data) => data.map((item) => ({ ...item, url: item.url.replace('en/', '') })), +}); + +export declare const data: PostData[]; diff --git a/content/.vitepress/theme/utils/getPostList.ja.data.ts b/content/.vitepress/theme/utils/getPostList.ja.data.ts index abe4d7a..98ad3b2 100644 --- a/content/.vitepress/theme/utils/getPostList.ja.data.ts +++ b/content/.vitepress/theme/utils/getPostList.ja.data.ts @@ -1,3 +1,6 @@ +import PostData from '@/.vitepress/types/PostData'; import { createContentLoader } from 'vitepress'; export default createContentLoader('ja/posts/**/*.md'); + +export declare const data: PostData[]; diff --git a/content/.vitepress/theme/utils/getPostList.ts b/content/.vitepress/theme/utils/getPostList.ts deleted file mode 100644 index c7987a1..0000000 --- a/content/.vitepress/theme/utils/getPostList.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { readdirSync, readFileSync, statSync } from 'node:fs'; -import metadataParser from 'markdown-yaml-metadata-parser'; - -const getPostList = (locale?: string) => - readdirSync(locale ? `./content/${locale}/posts` : './content/posts') - .map((file) => { - const [fileName, ext] = file.split('.'); - if (ext !== 'md') return null; - const fileContent = readFileSync( - locale ? `./content/${locale}/posts/${file}` : `./content/posts/${file}`, - 'utf-8', - ); - const { metadata } = metadataParser(fileContent); - if (!metadata?.title) return null; - let date; - if (metadata?.date) { - date = Number(new Date(metadata.date)); - } else { - date = statSync( - locale ? `./content/${locale}/posts/${file}` : `./content/posts/${file}`, - ).ctimeMs; - } - return { - text: metadata.title as string, - link: locale ? `/${locale}/posts/${fileName}` : `/posts/${fileName}`, - time: date, - }; - }) - .filter((item) => item !== null) - .sort((a, b) => b.time - a.time) - .map(({ text, link }) => ({ text, link })); - -export default getPostList; diff --git a/content/.vitepress/theme/utils/getPostList.zh-Hans.data.ts b/content/.vitepress/theme/utils/getPostList.zh-Hans.data.ts index fa03908..76ba6a5 100644 --- a/content/.vitepress/theme/utils/getPostList.zh-Hans.data.ts +++ b/content/.vitepress/theme/utils/getPostList.zh-Hans.data.ts @@ -1,3 +1,6 @@ +import PostData from '@/.vitepress/types/PostData'; import { createContentLoader } from 'vitepress'; export default createContentLoader('zh-Hans/posts/**/*.md'); + +export declare const data: PostData[]; diff --git a/content/about.md b/content/en/about.md similarity index 98% rename from content/about.md rename to content/en/about.md index c87a45f..b31af8c 100644 --- a/content/about.md +++ b/content/en/about.md @@ -90,13 +90,13 @@ Please keep up with our further updates. ### The Flag: Double-Flowered Cherry Blossom -![The Flag of One Among Us](/posts/flag.oau.png 'The Flag of One Among Us') +![The Flag of One Among Us](./posts/flag.oau.png 'The Flag of One Among Us') ### The Anthem: Star Tour Song **『星めぐりの歌』** 宮沢賢治 作詞/作曲 -![Star Tour Song, from *The Complete Work of Miyazawa Kenji*, Chikuma Shobō](/posts/hoshi-meguri-no-uta.png 'Star Tour Song, from The Complete Work of Miyazawa Kenji, Chikuma Shobo') +![Star Tour Song, from *The Complete Work of Miyazawa Kenji*, Chikuma Shobō](./posts/hoshi-meguri-no-uta.png 'Star Tour Song, from The Complete Work of Miyazawa Kenji, Chikuma Shobo') Can you see the red eyed Scorpion? diff --git a/content/community-resource.md b/content/en/community-resource.md similarity index 100% rename from content/community-resource.md rename to content/en/community-resource.md diff --git a/content/contact.md b/content/en/contact.md similarity index 100% rename from content/contact.md rename to content/en/contact.md diff --git a/content/index.md b/content/en/index.md similarity index 97% rename from content/index.md rename to content/en/index.md index 5ff7e1b..52e316f 100644 --- a/content/index.md +++ b/content/en/index.md @@ -1,6 +1,6 @@ --- # https://vitepress.dev/reference/default-theme-home-page -layout: ourhome +layout: home hero: name: 'One Among Us' text: '' @@ -70,8 +70,8 @@ We are a registered not-for-profit organization in Ontario, Canada. ## Events Calendar diff --git a/content/land-ack.md b/content/en/land-ack.md similarity index 100% rename from content/land-ack.md rename to content/en/land-ack.md diff --git a/content/login.md b/content/en/login.md similarity index 100% rename from content/login.md rename to content/en/login.md diff --git a/content/people/index.md b/content/en/people/index.md similarity index 100% rename from content/people/index.md rename to content/en/people/index.md diff --git a/content/people/index.vue b/content/en/people/index.vue similarity index 100% rename from content/people/index.vue rename to content/en/people/index.vue diff --git a/content/posts/2023-member-gathering.md b/content/en/posts/2023-member-gathering.md similarity index 100% rename from content/posts/2023-member-gathering.md rename to content/en/posts/2023-member-gathering.md diff --git a/content/posts/another-mh-art.jpg b/content/en/posts/another-mh-art.jpg similarity index 100% rename from content/posts/another-mh-art.jpg rename to content/en/posts/another-mh-art.jpg diff --git a/content/posts/board_election_202304.md b/content/en/posts/board_election_202304.md similarity index 100% rename from content/posts/board_election_202304.md rename to content/en/posts/board_election_202304.md diff --git a/content/posts/board_election_202312.md b/content/en/posts/board_election_202312.md similarity index 100% rename from content/posts/board_election_202312.md rename to content/en/posts/board_election_202312.md diff --git a/content/posts/flag.oau.png b/content/en/posts/flag.oau.png similarity index 100% rename from content/posts/flag.oau.png rename to content/en/posts/flag.oau.png diff --git a/content/posts/flag_anthem.md b/content/en/posts/flag_anthem.md similarity index 100% rename from content/posts/flag_anthem.md rename to content/en/posts/flag_anthem.md diff --git a/content/posts/hoshi-meguri-no-uta.png b/content/en/posts/hoshi-meguri-no-uta.png similarity index 100% rename from content/posts/hoshi-meguri-no-uta.png rename to content/en/posts/hoshi-meguri-no-uta.png diff --git a/content/posts/index.md b/content/en/posts/index.md similarity index 86% rename from content/posts/index.md rename to content/en/posts/index.md index 96fbeec..8b8ede4 100644 --- a/content/posts/index.md +++ b/content/en/posts/index.md @@ -1,5 +1,6 @@ --- layout: page +title: Archives --- diff --git a/content/posts/index.vue b/content/en/posts/index.vue similarity index 80% rename from content/posts/index.vue rename to content/en/posts/index.vue index 5975d2f..c658f8f 100644 --- a/content/posts/index.vue +++ b/content/en/posts/index.vue @@ -17,12 +17,10 @@