Skip to content

Commit 3462bd8

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 3462bd8

14 files changed

Lines changed: 822 additions & 1038 deletions

.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

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(),
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
// Scripts and types
3-
import { getCollection } from 'astro:content';
3+
import { getCollection, render } from 'astro:content';
44
import { generateContentToc } from '@scripts/generate-content-toc.ts';
55
import { generateContentTree } from '@scripts/generate-content-tree.ts';
66
@@ -10,41 +10,39 @@ import Children from '@components/Children.astro';
1010
import LayoutDocs from '@layouts/LayoutDocs.astro';
1111
import TableOfContents from '@components/toc/TableOfContents.astro';
1212
13-
export const getStaticPaths = (async () => {
14-
const pages = await getCollection('docs', ({ data }) => {
13+
export const getStaticPaths = async () => {
14+
const posts = await getCollection('docs', ({ data }) => {
1515
return data.highlight === undefined;
1616
});
1717
18-
const paths = pages.map(page => {
19-
const [lang, ...slug] = page.slug.split('/');
18+
return posts.map(post => {
19+
const parts = post.id?.split('/') ?? [];
20+
const [lang, ...slugParts] = parts;
21+
22+
const slug = slugParts.join('/');
23+
2024
return {
2125
params: {
22-
lang,
23-
slug: slug.join('/') || undefined
26+
id: slug,
27+
lang: lang,
2428
},
25-
props: page,
26-
};
29+
props: { post }
30+
}
2731
});
32+
};
2833
29-
return paths;
30-
});
31-
32-
// const { lang, slug } = Astro.params;
33-
const page = Astro.props;
34-
35-
const isHome = page.data.xref === 'home';
36-
37-
const { Content } = await page.render();
38-
const headings = await page.render().then(data => data.headings);
34+
const { post } = Astro.props;
35+
const isHome = post.data.xref === 'home';
36+
const { Content, headings } = await render(post);
3937
const contentToc = await generateContentToc(headings);
4038
const contentTree = await generateContentTree();
4139
---
4240

43-
<LayoutDocs title={page.data.title} description={page.data.description} ogImage={page.data.ogImage} twitterImage={page.data.twitterImage} contentTree={contentTree}>
41+
<LayoutDocs title={post.data.title} description={post.data.description} ogImage={post.data.ogImage} twitterImage={post.data.twitterImage} contentTree={contentTree}>
4442
<div class="row">
4543
<div id="mainContent" class="anchorjs-container col-xl-10 order-2 order-xl-1">
4644
<div class="d-none d-xl-block">
47-
<h1 class="title">{page.data.title}</h1>
45+
<h1 class="title">{post.data.title}</h1>
4846
<Breadcrumbs isHome={isHome} />
4947
</div>
5048
<Content />

src/scripts/generate-content-toc.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Scripts and types
2-
import type { ContentToc, ContentTocBase } from '@scripts/types';
2+
import type { ContentToc } from '@scripts/types';
3+
import type { MarkdownHeading } from '@astrojs/markdown-remark';
34

4-
export const generateContentToc = async (headings: ContentTocBase[]): Promise<ContentToc[]> => {
5+
export const generateContentToc = async (headings: MarkdownHeading[]): Promise<ContentToc[]> => {
56
const toc: ContentToc[] = [];
67
const parentHeadings = new Map();
78

0 commit comments

Comments
 (0)