From e717b89ee78718805ce71366a217c5848f4a9d2d Mon Sep 17 00:00:00 2001 From: YunYouJun Date: Sat, 28 Oct 2023 23:28:18 +0800 Subject: [PATCH] docs: add how to add default frontmatter --- demo/yun/pages/test/time_warning.md | 8 + docs/locales/en.yml | 4 + docs/locales/zh-CN.yml | 4 + docs/pages/addons/use.md | 26 ++- docs/pages/guide/config/extend.md | 103 +++++++++ .../guide/{config.md => config/index.md} | 128 ++-------- docs/pages/guide/getting-started.md | 4 +- docs/pages/migration/hexo.md | 4 +- docs/pages/migration/index.md | 2 +- docs/valaxy.config.ts | 27 ++- .../components/PressCategory.vue | 7 +- .../components/PressSidebar.vue | 76 +++++- .../components/PressSidebarItem.vue | 218 ++++++++++++++++++ .../valaxy-theme-press/composables/sidebar.ts | 172 ++++++++++++++ packages/valaxy-theme-press/types/index.d.ts | 47 +++- .../components/YunMdTimeWarning.vue | 9 +- .../components/third/YunWaline.vue | 2 +- .../valaxy-theme-yun/docs/zh-CN/README.md | 2 +- packages/valaxy/client/locales/zh-CN.yml | 2 +- packages/valaxy/node/config/index.ts | 4 + packages/valaxy/node/plugins/pages.ts | 2 +- packages/valaxy/package.json | 1 + packages/valaxy/types/config.ts | 6 + 23 files changed, 731 insertions(+), 127 deletions(-) create mode 100644 demo/yun/pages/test/time_warning.md create mode 100644 docs/pages/guide/config/extend.md rename docs/pages/guide/{config.md => config/index.md} (79%) create mode 100644 packages/valaxy-theme-press/components/PressSidebarItem.vue create mode 100644 packages/valaxy-theme-press/composables/sidebar.ts diff --git a/demo/yun/pages/test/time_warning.md b/demo/yun/pages/test/time_warning.md new file mode 100644 index 00000000..7c493a25 --- /dev/null +++ b/demo/yun/pages/test/time_warning.md @@ -0,0 +1,8 @@ +--- +title: Time Warning Test +date: 2020-10-01 +categories: + - test +--- + +This is a test page for time warning. diff --git a/docs/locales/en.yml b/docs/locales/en.yml index aeca930e..30359ec7 100644 --- a/docs/locales/en.yml +++ b/docs/locales/en.yml @@ -92,3 +92,7 @@ features: tooltip: edit_this_page: Edit this page on GitHub + +toc: + base-config: Base Config + extend-config: Extend Config diff --git a/docs/locales/zh-CN.yml b/docs/locales/zh-CN.yml index fd9c5ea4..d70f96c6 100644 --- a/docs/locales/zh-CN.yml +++ b/docs/locales/zh-CN.yml @@ -92,3 +92,7 @@ features: tooltip: edit_this_page: 在 GitHub 上编辑此页 + +toc: + base-config: 基础配置 + extend-config: 扩展配置 diff --git a/docs/pages/addons/use.md b/docs/pages/addons/use.md index 59f91ecd..1b03ab73 100644 --- a/docs/pages/addons/use.md +++ b/docs/pages/addons/use.md @@ -16,9 +16,9 @@ pnpm add [valaxy-addon-package1] [valaxy-addon-package2] ```ts // valaxy.config.ts -import { defineConfig } from 'valaxy' +import { defineValaxyConfig } from 'valaxy' -export default defineConfig({ +export default defineValaxyConfig({ addons: [ 'valaxy-addon-package1', // pass addon options @@ -26,3 +26,25 @@ export default defineConfig({ ] }) ``` + +### Addon With Options + +譬如开启 Waline 评论: + +```ts +import { defineValaxyConfig } from 'valaxy' +import { addonWaline } from 'valaxy-addon-waline' + +export default defineValaxyConfig({ + // 启用评论 + comment: { + enable: true + }, + // 设置 valaxy-addon-waline 配置项 + addons: [ + addonWaline({ + serverURL: 'https://your-waline-url', + }), + ], +}) +``` diff --git a/docs/pages/guide/config/extend.md b/docs/pages/guide/config/extend.md new file mode 100644 index 00000000..ed3cb916 --- /dev/null +++ b/docs/pages/guide/config/extend.md @@ -0,0 +1,103 @@ +--- +title: Extend Config +title_zh-CN: 扩展配置 +categories: + - config +--- + +> [packages/valaxy/node/type.ts](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy/node/types.ts) + +### Unocss Presets + +```ts +// types +export interface ValaxyExtendConfig { + /** + * Markdown Feature + */ + features: { + /** + * enable katex for global + */ + katex: boolean + } + + vite?: ViteUserConfig + vue?: Parameters[0] + components?: Parameters[0] + unocss?: UnoCSSConfig + /** + * unocss presets + */ + unocssPresets?: { + uno?: Parameters[0] + attributify?: Parameters[0] + icons?: Parameters[0] + typography?: Parameters[0] + } + pages?: Parameters[0] + /** + * for markdown + */ + markdown?: MarkdownOptions + extendMd?: (ctx: { + route: { + meta: { frontmatter: Record; layout?: string } & object + path: string + component: string + } + data: Readonly> + content: string + excerpt?: string + path: string + }) => void + addons?: ValaxyAddons +} +``` + +::: zh-CN +所以,你可以像这样使用: +::: + +::: en +So you can use it like this: +::: + +```ts +// valaxy.config.ts +import { defineValaxyConfig } from 'valaxy' +import type { ThemeConfig } from 'valaxy-theme-yun' +import { addonComponents } from 'valaxy-addon-components' +import Inspect from 'vite-plugin-inspect' + +const safelist = [ + 'i-ri-home-line', +] + +export default defineValaxyConfig({ + // site config see site.config.ts or write in siteConfig + siteConfig: {}, + + theme: 'yun', + themeConfig: { + banner: { + enable: true, + title: '云游君的小站', + }, + }, + + vite: { + // https://github.com/antfu/vite-plugin-inspect + // Visit http://localhost:3333/__inspect/ to see the inspector + plugins: [Inspect()], + }, + + unocss: { + safelist, + }, + + addons: [ + addonComponents() + ], +}) +``` diff --git a/docs/pages/guide/config.md b/docs/pages/guide/config/index.md similarity index 79% rename from docs/pages/guide/config.md rename to docs/pages/guide/config/index.md index 1c5c177a..f735f303 100644 --- a/docs/pages/guide/config.md +++ b/docs/pages/guide/config/index.md @@ -4,7 +4,6 @@ title_zh-CN: 基础配置 categories: - config end: false -top: 10 --- ## 配置说明 {lang="zh-CN"} @@ -14,12 +13,12 @@ top: 10 ::: zh-CN 为了便于配置,Valaxy 将配置分为了三种。 -`valaxy.config.ts` 是配置的主入口。 +`valaxy.config.ts` 是配置的主入口,它包含了一下配置。 - `siteConfig`: 站点**信息**配置,这部分内容面向站点展示且在任何主题也是通用的格式 - `themeConfig`: 主题配置,这部分内容仅在特定主题生效 - `runtimeConfig`: 运行时的配置(由 Valaxy 自动生成),用户无需配置 -- 其他 Valaxy 通用配置内容(如需要在 Node 端处理的配置) +- 其他 Valaxy 通用配置内容(如需要在 Node 端处理的配置 `unocss`/`addons`) 譬如: ::: @@ -188,6 +187,28 @@ export default defineSiteConfig({ ::: +### Default Frontmatter + +为所有文章设置默认的 Frontmatter。 + +譬如: + +> 设置 `time_warning: false`,则所有文章都不会显示阅读时间警告。 + +```ts {8-10} +// site.config.ts +import { defineSiteConfig } from 'valaxy' + +export default defineSiteConfig({ + /** + * 默认 Frontmatter + */ + frontmatter: { + time_warning: false, + } +}) +``` + ### 社交图标 {lang="zh-CN"} ### Social Icons {lang="en"} @@ -400,104 +421,3 @@ export default defineSiteConfig({ ::: en Please refer to [Using Themes](/themes/use) and the theme you are using to configure it. ::: - -## Valaxy 扩展配置 {lang="zh-CN"} - -## Valaxy Extended Configuration {lang="zh-CN"} - -> [packages/valaxy/node/type.ts](https://github.com/YunYouJun/valaxy/blob/main/packages/valaxy/node/types.ts) - -### Unocss Presets - -```ts -// types -export interface ValaxyExtendConfig { - /** - * Markdown Feature - */ - features: { - /** - * enable katex for global - */ - katex: boolean - } - - vite?: ViteUserConfig - vue?: Parameters[0] - components?: Parameters[0] - unocss?: UnoCSSConfig - /** - * unocss presets - */ - unocssPresets?: { - uno?: Parameters[0] - attributify?: Parameters[0] - icons?: Parameters[0] - typography?: Parameters[0] - } - pages?: Parameters[0] - /** - * for markdown - */ - markdown?: MarkdownOptions - extendMd?: (ctx: { - route: { - meta: { frontmatter: Record; layout?: string } & object - path: string - component: string - } - data: Readonly> - content: string - excerpt?: string - path: string - }) => void - addons?: ValaxyAddons -} -``` - -::: zh-CN -所以,你可以像这样使用: -::: - -::: en -So you can use it like this: -::: - -```ts -// valaxy.config.ts -import { defineValaxyConfig } from 'valaxy' -import type { ThemeConfig } from 'valaxy-theme-yun' -import { addonComponents } from 'valaxy-addon-components' -import Inspect from 'vite-plugin-inspect' - -const safelist = [ - 'i-ri-home-line', -] - -export default defineValaxyConfig({ - // site config see site.config.ts or write in siteConfig - siteConfig: {}, - - theme: 'yun', - themeConfig: { - banner: { - enable: true, - title: '云游君的小站', - }, - }, - - vite: { - // https://github.com/antfu/vite-plugin-inspect - // Visit http://localhost:3333/__inspect/ to see the inspector - plugins: [Inspect()], - }, - - unocss: { - safelist, - }, - - addons: [ - addonComponents() - ], -}) -``` diff --git a/docs/pages/guide/getting-started.md b/docs/pages/guide/getting-started.md index cc200de8..83d82e9e 100644 --- a/docs/pages/guide/getting-started.md +++ b/docs/pages/guide/getting-started.md @@ -216,14 +216,14 @@ npm run dev ::: zh-CN 博客创建完毕,查看本地 `http://localhost:4859/`,玩的开心! -- Valaxy 博客通用的配置可参见 [配置](/guide/config) 与 [自定义扩展](/guide/custom/extend)。 +- Valaxy 博客通用的配置可参见 [配置](/guide/config/) 与 [自定义扩展](/guide/custom/extend)。 - Valaxy 主题独有配置请参见对应主题文档。(Valaxy Theme Yun 主题文档编写中……) ::: ::: en See `http://localhost:4859/`, have fun! -- See [Config](/guide/config) and [Custom Extensions](/guide/custom/extend) for the general configuration for Valaxy blogs. +- See [Config](/guide/config/) and [Custom Extensions](/guide/custom/extend) for the general configuration for Valaxy blogs. - For configuring Valaxy themes, please see the documentation for the corresponding themes. (Docs for Valaxy Theme Yun is still work in progress) ::: diff --git a/docs/pages/migration/hexo.md b/docs/pages/migration/hexo.md index 84dca188..6f5a045c 100644 --- a/docs/pages/migration/hexo.md +++ b/docs/pages/migration/hexo.md @@ -44,14 +44,14 @@ The relationship between Hexo blog directory and Valaxy blog directory is shown ### Migrate Configurations {lang="en"} ::: zh-CN -参考 [Valaxy 配置文档](/guide/config) 将 Hexo `_config.yml` 配置文件中的内容,迁移至 `valaxy.config.ts` 文件中。 +参考 [Valaxy 配置文档](/guide/config/) 将 Hexo `_config.yml` 配置文件中的内容,迁移至 `valaxy.config.ts` 文件中。 > 配置示例:[demo/yun/valaxy.config.ts](https://github.com/YunYouJun/valaxy/blob/main/demo/yun/valaxy.config.ts)、[yunyoujun.github.io/valaxy.config.ts](https://github.com/YunYouJun/yunyoujun.github.io/blob/valaxy/valaxy.config.ts) > `valaxy.config.ts` 提供了完备的类型提示,这意味着你在 VSCode 中可以直接鼠标悬浮查看各参数注释。 ::: ::: en -Refer to [Valaxy Config](/guide/config) to migrate configurations from Hexo's `_config.yml` to Valaxy's `valaxy.config.ts`. +Refer to [Valaxy Config](/guide/config/) to migrate configurations from Hexo's `_config.yml` to Valaxy's `valaxy.config.ts`. > Examples of configuration: [demo/yun/valaxy.config.ts](https://github.com/YunYouJun/valaxy/blob/main/demo/yun/valaxy.config.ts), [yunyoujun.github.io/valaxy.config.ts](https://github.com/YunYouJun/yunyoujun.github.io/blob/valaxy/valaxy.config.ts). > `valaxy.config.ts` provides a complete type prompt, which means that you can hover on configuration fields directly to view the comments in VSCode. diff --git a/docs/pages/migration/index.md b/docs/pages/migration/index.md index bcbd2ecd..c491d934 100644 --- a/docs/pages/migration/index.md +++ b/docs/pages/migration/index.md @@ -15,7 +15,7 @@ top: 10 - 将你的文章(Markdown 文件)复制至 Valaxy `pages/posts` 目录下。 - 将你的自定义页面(非文章的 Markdown/HTML 文件)复制至 Valaxy `pages` 目录下。 - 将你的静态资源(图片等)复制至 Valaxy `public` 目录下。 -- 参考 [配置](/guide/config) 配置你的配置文件 `valaxy.config.ts`/`site.config.ts`。 +- 参考 [配置](/guide/config/) 配置你的配置文件 `valaxy.config.ts`/`site.config.ts`。 ## 常见问题 {lang="zh-CN"} diff --git a/docs/valaxy.config.ts b/docs/valaxy.config.ts index aef2bb5b..4762ebf3 100644 --- a/docs/valaxy.config.ts +++ b/docs/valaxy.config.ts @@ -37,7 +37,32 @@ export default defineValaxyConfig({ theme: 'press', themeConfig: { logo: '/favicon.svg', - sidebar: ['getting-started', 'guide', 'config', 'migration', 'built-ins', 'third', 'custom', 'examples', 'theme', 'addon', 'dev'], + sidebar: [ + 'getting-started', + 'guide', + { + text: 'category.config', + collapsed: false, + items: [ + { + text: 'toc.base-config', + link: '/guide/config/', + }, + { + text: 'toc.extend-config', + link: '/guide/config/extend', + }, + ], + }, + 'migration', + 'built-ins', + 'third', + 'custom', + 'examples', + 'theme', + 'addon', + 'dev', + ], socialLinks: [ { icon: 'i-ri-github-line', link: 'https://github.com/YunYouJun/valaxy' }, ], diff --git a/packages/valaxy-theme-press/components/PressCategory.vue b/packages/valaxy-theme-press/components/PressCategory.vue index 0e949ebf..5d5a566d 100644 --- a/packages/valaxy-theme-press/components/PressCategory.vue +++ b/packages/valaxy-theme-press/components/PressCategory.vue @@ -32,7 +32,8 @@ function getTitle(post: Post | any) { v-if="category.total" p="t-2" w="full" border="t t-$pr-c-divider-light" - class="category-list-item inline-flex items-center justify-between" + class="press-sidebar-item category-list-item inline-flex items-center justify-between" + text-14px tabindex="0" > @@ -41,7 +42,9 @@ function getTitle(post: Post | any) {