Skip to content

Commit 0c7ad50

Browse files
committed
(#1311) Upgrade Astro via choco-theme 2.7.0
This updates choco-theme packages to 2.7.0. Included in this release is an upgrade to the version of Astro to 6.x. With the upgrade to Astro, many files needed to be updated due to breaking changes in the way v6 works. No apparent changes should be visible to the end user, and adding the process of adding new content remains the same.
1 parent f0fb977 commit 0c7ad50

16 files changed

Lines changed: 824 additions & 1040 deletions

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// https://github.com/withastro/astro/blob/main/.devcontainer/with-mdx/devcontainer.json
33
{
44
"name": "Node.js & TypeScript",
5-
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",
5+
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-22-bullseye",
66
"forwardPorts": [5086],
77
"portsAttributes": {
88
"5086": {

.github/workflows/playwright.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
- name: Checkout repository using git
1313
uses: actions/checkout@v4
1414
- name: Setup Node.js
15-
uses: actions/setup-node@v4
15+
uses: actions/setup-node@v6
1616
with:
17-
node-version: '20'
17+
node-version-file: 'package.json'
1818
- name: Build site
1919
run: yarn build
2020
- name: Run Playwright tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ There are multiple options to build the site:
3434

3535
### Build the Site On Your Computer
3636

37-
Ensure that you have Node v20+ installed by running `node -v`. There is a `.\setup.ps1` file in the root of this repository that uses Chocolatey to install or upgrade Node to the correct version.
37+
Ensure that you have Node >= 22.12.0 installed by running `node -v`. There is a `.\setup.ps1` file in the root of this repository that uses Chocolatey to install or upgrade Node to the correct version.
3838

3939
After confirming the required Node version, run the following command from a terminal:
4040

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
"homepage": "https://github.com/chocolatey/docs#readme",
1414
"type": "module",
1515
"version": "0.0.1",
16+
"engines": {
17+
"node": ">=22.12.0"
18+
},
1619
"scripts": {
1720
"astro": "npx astro",
21+
"audit": "yarn npm audit --all --recursive --no-deprecations",
1822
"browsers": "npx playwright install --with-deps",
1923
"build": "yarn dependencies && yarn telemetry && yarn choco-theme && yarn browsers && npx astro build",
2024
"build-copy-theme": "npx tsx node_modules/@chocolatey-software/build-tools/build/copy-theme.ts docs",
@@ -32,11 +36,11 @@
3236
},
3337
"devDependencies": {
3438
"@chocolatey-software/assets": "2.0.0",
35-
"@chocolatey-software/astro": "2.6.0",
39+
"@chocolatey-software/astro": "chocolatey/choco-theme#head=choco-theme/2.7.0&workspace=@chocolatey-software/astro",
3640
"@chocolatey-software/build-tools": "2.6.0",
3741
"@chocolatey-software/playwright": "2.6.0"
3842
},
3943
"dependencies": {
40-
"@chocolatey-software/docs": "2.6.0"
44+
"@chocolatey-software/docs": "chocolatey/choco-theme#head=choco-theme/2.7.0&workspace=@chocolatey-software/docs"
4145
}
4246
}

src/components/Breadcrumbs.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const buildPartsList = async () => {
1616
const href = `${paths.slice(0, i + 1).join('/')}`;
1717
1818
if (href !== 'en-us') {
19-
const blogPost = await getEntry('docs', href);
19+
const post = await getEntry('docs', href);
2020
21-
if (blogPost) {
21+
if (post) {
2222
parts.push({
23-
text: blogPost.data.title,
24-
href: blogPost.slug
23+
text: post.data.title,
24+
href: post.id
2525
});
2626
}
2727
}

src/components/Children.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const findObjectBySlug = async (obj: ContentTree, slug: string): Promise<Content
2525
}
2626
2727
// Check if the current object has the specified slug
28-
if (slug === obj.slug || slug === obj.slug.slice(0, -1)) {
28+
if (slug === obj.id || slug === obj.id.slice(0, -1)) {
2929
return obj;
3030
}
3131

src/components/Xref.astro

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
// Scripts and types
3-
import { z } from 'zod';
4-
import { xref, xrefLinkAnchorSchema, xrefLinkValueSchema } from '@scripts/xref.ts';
5-
import type { XrefLinkAnchor, XrefLinkValue} from '@scripts/xref.ts';
3+
import { z } from 'astro/zod';
4+
import { getCollection } from 'astro:content';
65
76
const { title, value, anchor, classes, icon } = Astro.props;
87
const canonicalURL = new URL(Astro.url, Astro.site);
@@ -23,13 +22,27 @@ if (value.includes('#')) {
2322
throw new Error(`Xref link value cannot contain an anchor: ${value} on ${canonicalURL.toString()}`);
2423
}
2524
25+
const posts = await getCollection('docs', ({ data }) => {
26+
return data.highlight === undefined;
27+
});
28+
29+
const post = posts.find(post => post.data.xref === value);
30+
31+
if (!post) {
32+
throw new Error(`No post found for xref value: ${value} on ${canonicalURL.toString()}`);
33+
}
34+
35+
const xrefLinkValueSchema = z.string();
36+
const xrefLinkAnchorSchema = z.string().optional();
2637
const xrefLinkTitleSchema = z.string();
2738
const xrefLinkClassesSchema = z.string().optional();
2839
const xrefLinkIconSchema = z.string().optional();
2940
3041
type XrefLinkTitle = z.infer<typeof xrefLinkTitleSchema>;
3142
type XrefLinkClasses = z.infer<typeof xrefLinkClassesSchema>;
3243
type XrefLinkIcon = z.infer<typeof xrefLinkIconSchema>;
44+
type XrefLinkValue = z.infer<typeof xrefLinkValueSchema>;
45+
type XrefLinkAnchor = z.infer<typeof xrefLinkAnchorSchema>;
3346
3447
interface Props {
3548
title: XrefLinkTitle
@@ -46,7 +59,7 @@ xrefLinkAnchorSchema.parse(anchor);
4659
xrefLinkClassesSchema.parse(classes);
4760
xrefLinkIconSchema.parse(icon);
4861
49-
const link = await xref(value, anchor);
62+
const link = `/${post.id}${anchor ? `#${anchor}` : ''}`;
5063
const allClasses = classes ? classes : '';
5164
const iconTitle = `${title}<i class="fas ${icon} ms-1"></i>`;
5265
---

src/components/sidebar/SidebarListItem.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ const activeSlug = Astro.url.pathname;
1313
---
1414

1515
<li class={`nav-item nav-item-tertiary-bg`}>
16-
<a class={`nav-link py-c75 ${paddingClass} ${isActivePage(content.slug, activeSlug) ? 'active active-page' : ''}`} href={content.slug}>{content.data.title}</a>
16+
<a class={`nav-link py-c75 ${paddingClass} ${isActivePage(content.id, activeSlug) ? 'active active-page' : ''}`} href={content.id}>{content.data.title}</a>
1717
</li>

src/components/sidebar/SidebarSelf.astro

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const isActiveChild = (doc: ContentTree) => {
7676
}
7777
7878
// Check if the current document's slug matches the activeSlug
79-
if (isActivePage(currentDoc.slug, activeSlug)) {
79+
if (isActivePage(currentDoc.id, activeSlug)) {
8080
return true;
8181
}
8282
@@ -93,14 +93,14 @@ const isActiveChild = (doc: ContentTree) => {
9393
};
9494
---
9595

96-
{content.filter(doc => doc.data.showInSidebar === true).map(doc => (
96+
{content?.filter(doc => doc.data.showInSidebar === true).map(doc => (
9797
doc.children && doc.children.length > 0 ? (
9898
<li class={`nav-item nav-item-tertiary-bg ${isActiveChild(doc) ? 'active' : ''}`}>
99-
<div class={`nav-link nav-link-collapse d-flex align-items-center ${isActiveChild(doc) ? 'active' : ''} ${isActivePage(doc.slug, activeSlug) ? 'active-page' : ''}`}>
100-
<button class={`btn btn-collapse rounded-0 border-0 fw-normal ps-3 py-c75 min-w-auto ${listPaddingClass(doc.data.depth)} ${isActiveChild(doc) ? '' : 'collapsed'}`} type="button" data-bs-toggle="collapse" aria-expanded={`${isActiveChild(doc) ? 'true' : 'false'}`} aria-controls={slugId(`id-${doc.slug}`)} aria-label="collapse or expand navigation" data-bs-target={slugId(`#id-${doc.slug}`)}></button>
101-
<a class="fw-normal py-c75" href={doc.slug}>{doc.data.title}</a>
99+
<div class={`nav-link nav-link-collapse d-flex align-items-center ${isActiveChild(doc) ? 'active' : ''} ${isActivePage(doc.id, activeSlug) ? 'active-page' : ''}`}>
100+
<button class={`btn btn-collapse rounded-0 border-0 fw-normal ps-3 py-c75 min-w-auto ${listPaddingClass(doc.data.depth)} ${isActiveChild(doc) ? '' : 'collapsed'}`} type="button" data-bs-toggle="collapse" aria-expanded={`${isActiveChild(doc) ? 'true' : 'false'}`} aria-controls={slugId(`id-${doc.id}`)} aria-label="collapse or expand navigation" data-bs-target={slugId(`#id-${doc.id}`)}></button>
101+
<a class="fw-normal py-c75" href={doc.id}>{doc.data.title}</a>
102102
</div>
103-
<div class={`collapse ${isActiveChild(doc) ? 'show' : ''}`} id={slugId(`id-${doc.slug}`)}>
103+
<div class={`collapse ${isActiveChild(doc) ? 'show' : ''}`} id={slugId(`id-${doc.id}`)}>
104104
<ul class="navbar-nav">
105105
{Array.isArray(doc.children) && (
106106
<Astro.self content={doc.children} />
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
// 1. Import utilities from `astro:content`
2-
import { z, defineCollection } from 'astro:content';
2+
import { defineCollection } from 'astro:content';
33

4-
// 2. Define your collection(s)
4+
// 2. Import loader(s)
5+
import { glob } from 'astro/loaders';
6+
7+
// 3. Import Zod
8+
import { z } from 'astro/zod';
9+
10+
// 4. Define a `loader` and `schema` for each collection
511
const docsCollection = defineCollection({
6-
type: 'content',
12+
loader: glob({ base: './src/content/docs', pattern: '**/*.{md,mdx}' }),
713
schema: z.object({
814
order: z.number(),
915
xref: z.string(),

0 commit comments

Comments
 (0)