mirror of
https://github.com/tauri-apps/tauri-docs.git
synced 2026-01-31 00:35:16 +01:00
remove patch, bump all, add starlight-sidebar-topics
This commit is contained in:
512
astro.config.mjs
512
astro.config.mjs
@@ -4,10 +4,9 @@ import { rehypeHeadingIds } from '@astrojs/markdown-remark';
|
||||
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
||||
import locales from './locales.json';
|
||||
import starlightLinksValidator from 'starlight-links-validator';
|
||||
import starlightSidebarTopics from 'starlight-sidebar-topics';
|
||||
import starlightBlog from 'starlight-blog';
|
||||
import serviceWorker from 'astrojs-service-worker';
|
||||
import astroD2 from 'astro-d2';
|
||||
import starlightUtils from '@lorenzo_lewis/starlight-utils';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import lunaria from '@lunariajs/starlight';
|
||||
@@ -74,12 +73,245 @@ export default defineConfig({
|
||||
integrations: [
|
||||
starlight({
|
||||
plugins: [
|
||||
starlightUtils({
|
||||
multiSidebar: {
|
||||
switcherStyle: 'horizontalList',
|
||||
},
|
||||
}),
|
||||
starlightBlog({ authors, navigation: 'none' }),
|
||||
// starlightUtils({
|
||||
// multiSidebar: {
|
||||
// switcherStyle: 'horizontalList',
|
||||
// },
|
||||
// }),
|
||||
starlightBlog({ authors }),
|
||||
starlightSidebarTopics(
|
||||
[
|
||||
{
|
||||
label: {
|
||||
en: 'Guides',
|
||||
'zh-CN': '指引',
|
||||
es: 'Guías',
|
||||
},
|
||||
id: 'guides',
|
||||
link: '/start/',
|
||||
icon: 'open-book',
|
||||
items: [
|
||||
{
|
||||
label: 'Quick Start',
|
||||
translations: {
|
||||
'zh-CN': '快速开始',
|
||||
es: 'Guía rápida',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
'start',
|
||||
'start/prerequisites',
|
||||
'start/create-project',
|
||||
// {
|
||||
// label: 'What is Tauri?',
|
||||
// // translations: {
|
||||
// // 'zh-CN': '什么是 Tauri?',
|
||||
// // es: '¿Qué es Tauri?',
|
||||
// // },
|
||||
// link: '/start/',
|
||||
// },
|
||||
// {
|
||||
// label: 'Prerequisites',
|
||||
// // translations: {
|
||||
// // 'zh-CN': '前置条件',
|
||||
// // es: 'Requisitos previos',
|
||||
// // },
|
||||
// link: '/start/prerequisites/',
|
||||
// },
|
||||
// {
|
||||
// label: 'Create a Project',
|
||||
// // translations: {
|
||||
// // 'zh-CN': '创建项目',
|
||||
// // es: 'Crea un proyecto',
|
||||
// // },
|
||||
// link: '/start/create-project/',
|
||||
// },
|
||||
{
|
||||
label: 'Frontend Configuration',
|
||||
translations: {
|
||||
'zh-CN': '前端配置',
|
||||
es: 'Configuración del frontend',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'start/frontend' },
|
||||
},
|
||||
{
|
||||
label: 'Upgrade & Migrate',
|
||||
translations: {
|
||||
'zh-CN': '升级和迁移',
|
||||
es: 'Actualizar y migrar',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'start/migrate' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Core Concepts',
|
||||
translations: {
|
||||
'zh-CN': '核心概念',
|
||||
es: 'Conceptos básicos',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'concept' },
|
||||
},
|
||||
{
|
||||
label: 'Security',
|
||||
translations: {
|
||||
'zh-CN': '安全',
|
||||
es: 'Seguridad',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'security' },
|
||||
},
|
||||
{
|
||||
label: 'Develop',
|
||||
translations: {
|
||||
'zh-CN': '开发',
|
||||
es: 'Desarrollo',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
'develop',
|
||||
'develop/configuration-files',
|
||||
'develop/calling-rust',
|
||||
'develop/calling-frontend',
|
||||
'develop/resources',
|
||||
'develop/sidecar',
|
||||
'develop/state-management',
|
||||
'develop/updating-dependencies',
|
||||
{
|
||||
label: 'Debug',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Debug' },
|
||||
},
|
||||
{
|
||||
label: 'Plugins',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Plugins' },
|
||||
},
|
||||
{
|
||||
label: 'Tests',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Tests' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Distribute',
|
||||
translations: {
|
||||
'zh-CN': '分发',
|
||||
es: 'Distribuir',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'distribute' },
|
||||
},
|
||||
{
|
||||
label: 'Learn',
|
||||
translations: {
|
||||
'zh-CN': '学习',
|
||||
es: 'Aprende',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'learn' },
|
||||
},
|
||||
{
|
||||
label: 'Plugins',
|
||||
translations: {
|
||||
'zh-CN': '插件',
|
||||
es: 'Plugins',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'plugin' },
|
||||
},
|
||||
{
|
||||
label: 'About',
|
||||
translations: {
|
||||
'zh-CN': '关于',
|
||||
es: 'Acerca de',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'about' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: { en: 'References', 'zh-CN': '参考', es: 'Referencias' },
|
||||
id: 'references',
|
||||
link: '/references',
|
||||
icon: 'information',
|
||||
items: [
|
||||
{
|
||||
label: 'Security',
|
||||
translations: {
|
||||
'zh-CN': '安全',
|
||||
es: 'Seguridad',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'reference/acl' },
|
||||
},
|
||||
{
|
||||
label: 'Command Line Interface',
|
||||
translations: {
|
||||
'zh-CN': '命令行接口(CLI)',
|
||||
es: 'Interfaz de línea de comandos',
|
||||
},
|
||||
link: '/reference/cli/',
|
||||
},
|
||||
{
|
||||
label: 'Configuration',
|
||||
translations: {
|
||||
'zh-CN': '配置',
|
||||
es: 'Configuración',
|
||||
},
|
||||
link: '/reference/config/',
|
||||
},
|
||||
{
|
||||
label: 'Environment Variables',
|
||||
translations: {
|
||||
'zh-CN': '环境变量',
|
||||
es: 'Variables de entorno',
|
||||
},
|
||||
link: '/reference/environment-variables/',
|
||||
},
|
||||
{
|
||||
label: 'Webview Versions',
|
||||
translations: {
|
||||
'zh-CN': 'Webview 版本',
|
||||
es: 'Versiones de Webview',
|
||||
},
|
||||
link: '/reference/webview-versions/',
|
||||
},
|
||||
{
|
||||
label: 'Releases',
|
||||
translations: {
|
||||
'zh-CN': '发行版',
|
||||
es: 'Lanzamientos',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'release' },
|
||||
},
|
||||
{
|
||||
label: 'JavaScript',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'reference/javascript' },
|
||||
},
|
||||
{
|
||||
label: 'Rust (docs.rs)',
|
||||
link: 'https://docs.rs/tauri/~2/',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Blog',
|
||||
link: '/blog/',
|
||||
icon: 'information',
|
||||
},
|
||||
],
|
||||
{
|
||||
exclude: ['/blog', '/blog/**/*'],
|
||||
}
|
||||
),
|
||||
starlightLinksValidator({
|
||||
errorOnFallbackPages: false,
|
||||
errorOnRelativeLinks: false,
|
||||
@@ -105,8 +337,6 @@ export default defineConfig({
|
||||
Header: './src/components/overrides/Header.astro',
|
||||
Footer: 'src/components/overrides/Footer.astro',
|
||||
ThemeSelect: 'src/components/overrides/ThemeSelect.astro',
|
||||
PageFrame: 'src/components/overrides/PageFrame.astro',
|
||||
TableOfContents: 'src/components/overrides/TableOfContents.astro',
|
||||
},
|
||||
head: [
|
||||
{
|
||||
@@ -145,245 +375,6 @@ export default defineConfig({
|
||||
expressiveCode: {
|
||||
styleOverrides: { borderRadius: '0.5rem' },
|
||||
},
|
||||
sidebar: [
|
||||
{
|
||||
label: 'Guides',
|
||||
translations: {
|
||||
'zh-CN': '指引',
|
||||
es: 'Guías',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
{
|
||||
label: 'Quick Start',
|
||||
translations: {
|
||||
'zh-CN': '快速开始',
|
||||
es: 'Guía rápida',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
{
|
||||
label: 'What is Tauri?',
|
||||
translations: {
|
||||
'zh-CN': '什么是 Tauri?',
|
||||
es: '¿Qué es Tauri?',
|
||||
},
|
||||
link: '/start/',
|
||||
},
|
||||
{
|
||||
label: 'Prerequisites',
|
||||
translations: {
|
||||
'zh-CN': '前置条件',
|
||||
es: 'Requisitos previos',
|
||||
},
|
||||
link: '/start/prerequisites/',
|
||||
},
|
||||
{
|
||||
label: 'Create a Project',
|
||||
translations: {
|
||||
'zh-CN': '创建项目',
|
||||
es: 'Crea un proyecto',
|
||||
},
|
||||
link: '/start/create-project/',
|
||||
},
|
||||
{
|
||||
label: 'Frontend Configuration',
|
||||
translations: {
|
||||
'zh-CN': '前端配置',
|
||||
es: 'Configuración del frontend',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'start/frontend' },
|
||||
},
|
||||
{
|
||||
label: 'Upgrade & Migrate',
|
||||
translations: {
|
||||
'zh-CN': '升级和迁移',
|
||||
es: 'Actualizar y migrar',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'start/migrate' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Core Concepts',
|
||||
translations: {
|
||||
'zh-CN': '核心概念',
|
||||
es: 'Conceptos básicos',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'concept' },
|
||||
},
|
||||
{
|
||||
label: 'Security',
|
||||
translations: {
|
||||
'zh-CN': '安全',
|
||||
es: 'Seguridad',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'security' },
|
||||
},
|
||||
{
|
||||
label: 'Develop',
|
||||
translations: {
|
||||
'zh-CN': '开发',
|
||||
es: 'Desarrollo',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
'develop',
|
||||
'develop/configuration-files',
|
||||
'develop/calling-rust',
|
||||
'develop/calling-frontend',
|
||||
'develop/resources',
|
||||
'develop/sidecar',
|
||||
'develop/state-management',
|
||||
'develop/updating-dependencies',
|
||||
{
|
||||
label: 'Debug',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Debug' },
|
||||
},
|
||||
{
|
||||
label: 'Plugins',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Plugins' },
|
||||
},
|
||||
{
|
||||
label: 'Tests',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'develop/Tests' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Distribute',
|
||||
translations: {
|
||||
'zh-CN': '分发',
|
||||
es: 'Distribuir',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'distribute' },
|
||||
},
|
||||
{
|
||||
label: 'Learn',
|
||||
translations: {
|
||||
'zh-CN': '学习',
|
||||
es: 'Aprende',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'learn' },
|
||||
},
|
||||
{
|
||||
label: 'Plugins',
|
||||
translations: {
|
||||
'zh-CN': '插件',
|
||||
es: 'Plugins',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'plugin' },
|
||||
},
|
||||
{
|
||||
label: 'About',
|
||||
translations: {
|
||||
'zh-CN': '关于',
|
||||
es: 'Acerca de',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'about' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'References',
|
||||
translations: {
|
||||
'zh-CN': '参考',
|
||||
es: 'Referencias',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
{
|
||||
label: 'Security',
|
||||
translations: {
|
||||
'zh-CN': '安全',
|
||||
es: 'Seguridad',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'reference/acl' },
|
||||
},
|
||||
{
|
||||
label: 'Command Line Interface',
|
||||
translations: {
|
||||
'zh-CN': '命令行接口(CLI)',
|
||||
es: 'Interfaz de línea de comandos',
|
||||
},
|
||||
link: '/reference/cli/',
|
||||
},
|
||||
{
|
||||
label: 'Configuration',
|
||||
translations: {
|
||||
'zh-CN': '配置',
|
||||
es: 'Configuración',
|
||||
},
|
||||
link: '/reference/config/',
|
||||
},
|
||||
{
|
||||
label: 'Environment Variables',
|
||||
translations: {
|
||||
'zh-CN': '环境变量',
|
||||
es: 'Variables de entorno',
|
||||
},
|
||||
link: '/reference/environment-variables/',
|
||||
},
|
||||
{
|
||||
label: 'Webview Versions',
|
||||
translations: {
|
||||
'zh-CN': 'Webview 版本',
|
||||
es: 'Versiones de Webview',
|
||||
},
|
||||
link: '/reference/webview-versions/',
|
||||
},
|
||||
{
|
||||
label: 'Releases',
|
||||
translations: {
|
||||
'zh-CN': '发行版',
|
||||
es: 'Lanzamientos',
|
||||
},
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'release' },
|
||||
},
|
||||
{
|
||||
label: 'JavaScript',
|
||||
collapsed: true,
|
||||
autogenerate: { directory: 'reference/javascript' },
|
||||
},
|
||||
{
|
||||
label: 'Rust (docs.rs)',
|
||||
link: 'https://docs.rs/tauri/~2/',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Blog',
|
||||
translations: {
|
||||
'zh-CN': '博客',
|
||||
es: 'Blog',
|
||||
},
|
||||
collapsed: true,
|
||||
items: [
|
||||
{
|
||||
label: 'All posts',
|
||||
link: '/blog/',
|
||||
},
|
||||
{
|
||||
label: 'Recent posts',
|
||||
collapsed: false,
|
||||
autogenerate: { directory: 'blog', sort: 'date', order: 'descending' },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
locales,
|
||||
lastUpdated: true,
|
||||
}),
|
||||
@@ -393,28 +384,6 @@ export default defineConfig({
|
||||
default: '105',
|
||||
},
|
||||
}),
|
||||
serviceWorker({
|
||||
workbox: {
|
||||
cleanupOutdatedCaches: true,
|
||||
clientsClaim: true,
|
||||
inlineWorkboxRuntime: true,
|
||||
skipWaiting: true,
|
||||
globIgnores: ['**_redirects**', '**_headers**'],
|
||||
globPatterns: ['**/*.js', '**/*.css'],
|
||||
runtimeCaching: [
|
||||
{
|
||||
urlPattern: new RegExp('.*'),
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'tauri-runtime',
|
||||
expiration: {
|
||||
maxAgeSeconds: 30 * 60, // 30 minutes
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
],
|
||||
markdown: {
|
||||
shikiConfig: {
|
||||
@@ -513,7 +482,6 @@ export default defineConfig({
|
||||
server: {
|
||||
headers: readHeaders(),
|
||||
},
|
||||
//
|
||||
});
|
||||
|
||||
// Generates a redirect for each locale.
|
||||
|
||||
20
package.json
20
package.json
@@ -23,16 +23,14 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/markdown-remark": "^6.3.2",
|
||||
"@astrojs/rss": "^4.0.11",
|
||||
"@astrojs/starlight": "0.34.3",
|
||||
"@lorenzo_lewis/starlight-utils": "^0.3.2",
|
||||
"@astrojs/rss": "^4.0.12",
|
||||
"@astrojs/starlight": "0.34.4",
|
||||
"@lunariajs/core": "^0.1.1",
|
||||
"@lunariajs/starlight": "^0.1.1",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"astro": "^5.8.1",
|
||||
"astro-d2": "^0.6.0",
|
||||
"astro": "^5.11.0",
|
||||
"astro-d2": "^0.8.0",
|
||||
"astro-feelback": "^0.3.4",
|
||||
"astrojs-service-worker": "^2.0.0",
|
||||
"jsdom": "^26.1.0",
|
||||
"prettier": "^3.2.5",
|
||||
"prettier-plugin-astro": "^0.14.1",
|
||||
@@ -40,16 +38,12 @@
|
||||
"sass": "^1.89.0",
|
||||
"sharp": "^0.33.5",
|
||||
"shiki": "^3.0.0",
|
||||
"starlight-blog": "^0.23.2",
|
||||
"starlight-links-validator": "^0.14.3"
|
||||
"starlight-blog": "^0.24.0",
|
||||
"starlight-sidebar-topics": "^0.6.0",
|
||||
"starlight-links-validator": "^0.17.0"
|
||||
},
|
||||
"packageManager": "pnpm@10.11.0",
|
||||
"engines": {
|
||||
"pnpm": "^10.0.0"
|
||||
},
|
||||
"pnpm": {
|
||||
"patchedDependencies": {
|
||||
"@astrojs/starlight@0.34.2": "patches/@astrojs__starlight@0.34.2.patch"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
## Updating patch
|
||||
|
||||
Have Starlight version updated on package.json
|
||||
Temporarily remove the patch entry from package.json
|
||||
|
||||
Run `pnpm i`
|
||||
|
||||
place the patch entry back on package.json with the key renamed to $newVersion (keep the older version on the value)
|
||||
|
||||
run `pnpm patch @astrojs/starlight@$newVersion`, it will provide a path, copy it as $path
|
||||
|
||||
run `pnpm patch-commit $path`
|
||||
|
||||
`pnpm dev` and check if blog sidebar still on right order: most recent up top
|
||||
|
||||
check live preview
|
||||
|
||||
merge
|
||||
|
||||
---
|
||||
|
||||
## Manually applying patch in case updating doesn't work
|
||||
|
||||
### 1. `schemas/sidebar.ts`
|
||||
|
||||
Add `sort` and `order` fields to `AutoSidebarGroupSchema`:
|
||||
|
||||
```ts
|
||||
const AutoSidebarGroupSchema = SidebarGroupSchema.extend({
|
||||
autogenerate: z.object({
|
||||
// ...existing fields
|
||||
|
||||
// fields to add
|
||||
sort: z.enum(['date']).optional(),
|
||||
order: z.enum(['ascending', 'descending']).optional(),
|
||||
}),
|
||||
}).strict();
|
||||
```
|
||||
|
||||
### 2. `utils/navigation.ts`
|
||||
|
||||
Extract sort and order from `item.autogenerate`.
|
||||
|
||||
```ts find this object
|
||||
const { collapsed: subgroupCollapsed, directory } = item.autogenerate;
|
||||
```
|
||||
|
||||
```ts add 'sort', 'order'
|
||||
const {
|
||||
collapsed: subgroupCollapsed,
|
||||
directory,
|
||||
sort,
|
||||
order,
|
||||
} = item.autogenerate;
|
||||
```
|
||||
|
||||
Add sortHandler:
|
||||
|
||||
```ts
|
||||
const sortHandler = (kind: 'date', order: 'ascending' | 'descending') => {
|
||||
if (kind === 'date') {
|
||||
return order === 'ascending'
|
||||
? (docA: Route, docB: Route) =>
|
||||
docA.entry.data.date! > docB.entry.data.date! ? 1 : -1
|
||||
: (docA: Route, docB: Route) =>
|
||||
docA.entry.data.date! < docB.entry.data.date! ? 1 : -1;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Sort dirDocs before calling treeify().
|
||||
|
||||
```ts change
|
||||
const tree = treeify(dirDocs, localeDir, ...) ;
|
||||
```
|
||||
|
||||
```ts into this
|
||||
const sorted = !sort ? dirDocs : dirDocs.sort(sortHandler(sort, order)).map((doc, i) => { doc.entry.data.sidebar.order = i; return doc; });
|
||||
|
||||
const tree = treeify(sorted, localeDir, ...);
|
||||
```
|
||||
@@ -1,51 +0,0 @@
|
||||
diff --git a/schemas/sidebar.ts b/schemas/sidebar.ts
|
||||
index 2c4cc1d588f27b0106a82135ca3772cba86c5309..59a46a986a3fac739043c71f8a97801fa50e3e64 100644
|
||||
--- a/schemas/sidebar.ts
|
||||
+++ b/schemas/sidebar.ts
|
||||
@@ -49,6 +49,8 @@ const AutoSidebarGroupSchema = SidebarGroupSchema.extend({
|
||||
// TODO: not supported by Docusaurus but would be good to have
|
||||
/** How many directories deep to include from this directory in the sidebar. Default: `Infinity`. */
|
||||
// depth: z.number().optional(),
|
||||
+ sort: z.enum(['date']).optional(),
|
||||
+ order: z.enum(['ascending','descending']).optional()
|
||||
}),
|
||||
}).strict();
|
||||
export type AutoSidebarGroup = z.infer<typeof AutoSidebarGroupSchema>;
|
||||
diff --git a/utils/navigation.ts b/utils/navigation.ts
|
||||
index 2870d619e16bc8c0983fc22aed0ab936293ff8fa..6e2c245f0b63c3bda40f0def18ba1d1684a0de6a 100644
|
||||
--- a/utils/navigation.ts
|
||||
+++ b/utils/navigation.ts
|
||||
@@ -96,7 +96,7 @@ function groupFromAutogenerateConfig(
|
||||
routes: Route[],
|
||||
currentPathname: string
|
||||
): SidebarGroup {
|
||||
- const { collapsed: subgroupCollapsed, directory } = item.autogenerate;
|
||||
+ const { collapsed: subgroupCollapsed, directory, sort, order } = item.autogenerate;
|
||||
const localeDir = locale ? locale + '/' + directory : directory;
|
||||
const dirDocs = routes.filter((doc) => {
|
||||
const filePathFromContentDir = getRoutePathRelativeToCollectionRoot(doc, locale);
|
||||
@@ -107,7 +107,9 @@ function groupFromAutogenerateConfig(
|
||||
filePathFromContentDir.startsWith(localeDir + '/')
|
||||
);
|
||||
});
|
||||
- const tree = treeify(dirDocs, locale, localeDir);
|
||||
+ const sorted = !sort ? dirDocs : dirDocs.sort(sortHandler(sort, order)).map((doc, i) => { doc.entry.data.sidebar.order = i; return doc; });
|
||||
+
|
||||
+ const tree = treeify(sorted, locale, localeDir);
|
||||
const label = pickLang(item.translations, localeToLang(locale)) || item.label;
|
||||
return {
|
||||
type: 'group',
|
||||
@@ -118,6 +120,13 @@ function groupFromAutogenerateConfig(
|
||||
};
|
||||
}
|
||||
|
||||
+const sortHandler = (kind: 'date', order?: 'ascending' | 'descending') => {
|
||||
+ if (kind === 'date') {
|
||||
+ if (order === 'ascending') return (docA: Route, docB: Route) => docA.entry.data.date! > docB.entry.data.date! ? 1 : -1
|
||||
+ return (docA: Route, docB: Route) => docA.entry.data.date! < docB.entry.data.date! ? 1 : -1
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
/** Check if a string starts with one of `http://` or `https://`. */
|
||||
const isAbsolute = (link: string) => /^https?:\/\//.test(link);
|
||||
|
||||
3220
pnpm-lock.yaml
generated
3220
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user