|
1 |
| -## Updating patch |
2 |
| - |
3 |
| -Have starlight version updated on package.json |
4 |
| -Temporarily remove the patch entry from package.json |
5 |
| - |
6 |
| -Run `pnpm i` |
7 |
| - |
8 |
| -place the patch entry back on package.json with the key renamed to $newVersion (keep the older version on the value) |
9 |
| - |
10 |
| -run `pnpm patch @astrojs/starlight@$newVersion`, it will provide a path, copy it as $path |
11 |
| - |
12 |
| -run `pnpm patch-commit $path` |
13 |
| - |
14 |
| -`pnpm dev` and check if blog sidebar still on right order: most recent up top |
15 |
| - |
16 |
| -check live preview |
17 |
| - |
18 |
| -merge |
19 |
| - |
20 |
| ---- |
21 |
| - |
22 |
| - |
23 |
| -## Fixing patch |
24 |
| - |
25 |
| -### 1. `schemas/sidebar.ts` |
26 |
| - |
27 |
| -Add `sort` and `order` fields to `AutoSidebarGroupSchema`: |
28 |
| - |
29 |
| -```ts |
30 |
| -const AutoSidebarGroupSchema = SidebarGroupSchema.extend({ |
31 |
| - autogenerate: z.object({ |
32 |
| - // ...existing fields |
33 |
| - |
34 |
| - // fields to add |
35 |
| - sort: z.enum(['date']).optional(), |
36 |
| - order: z.enum(['ascending', 'descending']).optional(), |
37 |
| - }), |
38 |
| -}).strict(); |
39 |
| -``` |
40 |
| - |
41 |
| -### 2. `utils/navigation.ts` |
42 |
| - |
43 |
| -Extract sort and order from `item.autogenerate`. |
44 |
| - |
45 |
| -```ts find this object |
46 |
| -const { collapsed: subgroupCollapsed, directory } = item.autogenerate; |
47 |
| -``` |
48 |
| - |
49 |
| -```ts add 'sort', 'order' |
50 |
| -const { collapsed: subgroupCollapsed, directory, sort, order } = item.autogenerate; |
51 |
| -``` |
52 |
| - |
53 |
| -Add sortHandler: |
54 |
| - |
55 |
| -```ts |
56 |
| -const sortHandler = (kind: 'date', order: 'ascending' | 'descending') => { |
57 |
| - if (kind === 'date') { |
58 |
| - return order === 'ascending' |
59 |
| - ? (docA: Route, docB: Route) => docA.entry.data.date! > docB.entry.data.date! ? 1 : -1 |
60 |
| - : (docA: Route, docB: Route) => docA.entry.data.date! < docB.entry.data.date! ? 1 : -1; |
61 |
| - } |
62 |
| -}; |
63 |
| -``` |
64 |
| - |
65 |
| -Sort dirDocs before calling treeify(). |
66 |
| - |
67 |
| -```ts change |
68 |
| -const tree = treeify(dirDocs, localeDir, ...) ; |
69 |
| -``` |
70 |
| - |
71 |
| -```ts into this |
72 |
| -const sorted = !sort ? dirDocs : dirDocs.sort(sortHandler(sort, order)).map((doc, i) => { doc.entry.data.sidebar.order = i; return doc; }); |
73 |
| - |
74 |
| -const tree = treeify(sorted, localeDir, ...); |
75 |
| -``` |
76 |
| - |
| 1 | +## Updating patch |
| 2 | + |
| 3 | +Have Starlight version updated on package.json |
| 4 | +Temporarily remove the patch entry from package.json |
| 5 | + |
| 6 | +Run `pnpm i` |
| 7 | + |
| 8 | +place the patch entry back on package.json with the key renamed to $newVersion (keep the older version on the value) |
| 9 | + |
| 10 | +run `pnpm patch @astrojs/starlight@$newVersion`, it will provide a path, copy it as $path |
| 11 | + |
| 12 | +run `pnpm patch-commit $path` |
| 13 | + |
| 14 | +`pnpm dev` and check if blog sidebar still on right order: most recent up top |
| 15 | + |
| 16 | +check live preview |
| 17 | + |
| 18 | +merge |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Manually applying patch in case updating doesn't work |
| 23 | + |
| 24 | +### 1. `schemas/sidebar.ts` |
| 25 | + |
| 26 | +Add `sort` and `order` fields to `AutoSidebarGroupSchema`: |
| 27 | + |
| 28 | +```ts |
| 29 | +const AutoSidebarGroupSchema = SidebarGroupSchema.extend({ |
| 30 | + autogenerate: z.object({ |
| 31 | + // ...existing fields |
| 32 | + |
| 33 | + // fields to add |
| 34 | + sort: z.enum(['date']).optional(), |
| 35 | + order: z.enum(['ascending', 'descending']).optional(), |
| 36 | + }), |
| 37 | +}).strict(); |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. `utils/navigation.ts` |
| 41 | + |
| 42 | +Extract sort and order from `item.autogenerate`. |
| 43 | + |
| 44 | +```ts find this object |
| 45 | +const { collapsed: subgroupCollapsed, directory } = item.autogenerate; |
| 46 | +``` |
| 47 | + |
| 48 | +```ts add 'sort', 'order' |
| 49 | +const { |
| 50 | + collapsed: subgroupCollapsed, |
| 51 | + directory, |
| 52 | + sort, |
| 53 | + order, |
| 54 | +} = item.autogenerate; |
| 55 | +``` |
| 56 | + |
| 57 | +Add sortHandler: |
| 58 | + |
| 59 | +```ts |
| 60 | +const sortHandler = (kind: 'date', order: 'ascending' | 'descending') => { |
| 61 | + if (kind === 'date') { |
| 62 | + return order === 'ascending' |
| 63 | + ? (docA: Route, docB: Route) => |
| 64 | + docA.entry.data.date! > docB.entry.data.date! ? 1 : -1 |
| 65 | + : (docA: Route, docB: Route) => |
| 66 | + docA.entry.data.date! < docB.entry.data.date! ? 1 : -1; |
| 67 | + } |
| 68 | +}; |
| 69 | +``` |
| 70 | + |
| 71 | +Sort dirDocs before calling treeify(). |
| 72 | + |
| 73 | +```ts change |
| 74 | +const tree = treeify(dirDocs, localeDir, ...) ; |
| 75 | +``` |
| 76 | + |
| 77 | +```ts into this |
| 78 | +const sorted = !sort ? dirDocs : dirDocs.sort(sortHandler(sort, order)).map((doc, i) => { doc.entry.data.sidebar.order = i; return doc; }); |
| 79 | + |
| 80 | +const tree = treeify(sorted, localeDir, ...); |
| 81 | +``` |
0 commit comments