Skip to content

update starlight and astro ecosystem pkgs #3196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export default defineConfig({
'/blog/2023/06/14/tauri-1-4': '/blog/tauri-1-4',
'/blog/2023/06/15/tauri-board-elections-and-governance-updates':
'/blog/tauri-board-elections-and-governance-updates',
'about/intro': 'about/philosophy',
'/about/intro': '/about/philosophy',
// v1 /guides/debugging -> /guides/debug
...i18nRedirect('/v1/guides/debugging/application', '/guides/debug/application'),
...i18nRedirect('/v1/guides/debugging/vs-code', '/guides/debug/vs-code'),
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@
"preview": "astro preview"
},
"dependencies": {
"@astrojs/markdown-remark": "^5.2.0",
"@astrojs/rss": "^4.0.7",
"@astrojs/starlight": "0.29.2",
"@lorenzo_lewis/starlight-utils": "^0.2.0",
"@astrojs/markdown-remark": "^6.2.0",
"@astrojs/rss": "^4.0.11",
"@astrojs/starlight": "0.32.2",
"@lorenzo_lewis/starlight-utils": "^0.3.1",
"@lunariajs/core": "^0.1.1",
"@lunariajs/starlight": "^0.1.1",
"@types/json-schema": "^7.0.15",
"astro": "^4.16.18",
"astro": "^5.4.2",
"astro-d2": "^0.6.0",
"astro-feelback": "^0.3.4",
"astrojs-service-worker": "^2.0.0",
"jsdom": "^26.0.0",
"prettier": "^3.2.5",
"prettier-plugin-astro": "^0.14.0",
"prettier-plugin-astro": "^0.14.1",
"rehype-autolink-headings": "^7.1.0",
"sass": "^1.77.2",
"sharp": "^0.33.2",
"shiki": "^1.1.7",
"starlight-blog": "^0.15.0",
"starlight-links-validator": "^0.13.0"
"starlight-blog": "^0.18.0",
"starlight-links-validator": "^0.14.3"
},
"packageManager": "[email protected]",
"engines": {
"pnpm": "^9.0.0"
},
"pnpm": {
"patchedDependencies": {
"@astrojs/starlight@0.29.2": "patches/@astrojs__starlight@0.29.2.patch"
"@astrojs/starlight@0.32.2": "patches/@astrojs__starlight@0.32.2.patch"
}
}
}
}
76 changes: 76 additions & 0 deletions patches/.updating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## 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

---


## Fixing patch

### 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, ...);
```

51 changes: 51 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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);

Loading
Loading