Skip to content
Merged
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
3 changes: 2 additions & 1 deletion packages/astro-utils/src/sidebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export async function processSidebar(
function getSlugFromPath(directory: string, path: string) {
const name = parse(path).name.toLocaleLowerCase();
const normalizedName = name === "index" ? "" : name;
return prefix(join(directory, normalizedName))
const joined = join(directory, normalizedName);
return prefix(joined === "." ? "" : joined)
.replaceAll("$", "")
.replaceAll(" ", "-")
.toLowerCase();
Expand Down
69 changes: 64 additions & 5 deletions website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,91 @@ import { processSidebar } from "@typespec/astro-utils/sidebar";
import astroExpressiveCode from "astro-expressive-code";
import rehypeAstroRelativeMarkdownLinks from "astro-rehype-relative-markdown-links";
import { defineConfig } from "astro/config";
import { readdirSync, readFileSync } from "node:fs";
import { resolve } from "pathe";
import rehypeMermaid from "rehype-mermaid";
import remarkHeadingID from "remark-heading-id";
import current from "./src/content/current-sidebar";

/** Scan the release-notes directory and return the slug of the latest release note. */
function getLatestReleaseNoteSlug() {
const dir = resolve(import.meta.dirname, "src/content/docs/release-notes");
const files = readdirSync(dir).filter((f) => /\.mdx?$/.test(f) && !f.startsWith("index"));

let latestSlug = "";
let latestDate = 0;

for (const file of files) {
const content = readFileSync(resolve(dir, file), "utf-8");
const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);
if (!fmMatch) continue;

const dateMatch = fmMatch[1].match(/releaseDate:\s*(\S+)/);
if (!dateMatch) continue;

const date = new Date(dateMatch[1]).getTime();
if (date > latestDate) {
latestDate = date;
const slugMatch = fmMatch[1].match(/slug:\s*(\S+)/);
latestSlug = slugMatch ? slugMatch[1] : `release-notes/${file.replace(/\.mdx?$/, "")}`;
}
}

return latestSlug;
}

const latestReleaseNote = getLatestReleaseNoteSlug();

const base = process.env.TYPESPEC_WEBSITE_BASE_PATH ?? "/";

// https://astro.build/config
export default defineConfig({
base,
site: "https://typespec.io",
trailingSlash: "always",
redirects: {
// Point the old release-notes index to the latest release note.
...(latestReleaseNote ? { "/release-notes/": `/${latestReleaseNote}/` } : {}),
// Redirect old /docs/ date-based paths to version-based (already existed in HEAD, updated targets)
"/docs/release-notes/release-2025-04-02/": "/release-notes/typespec-1-0-0-rc-0/",
"/docs/release-notes/release-2025-04-22/": "/release-notes/typespec-1-0-0-rc-1/",
"/docs/release-notes/release-2025-05-06/": "/release-notes/typespec-1-0-0/",
"/docs/release-notes/release-2025-06-10/": "/release-notes/typespec-1-1-0/",
"/docs/release-notes/release-2025-07-15/": "/release-notes/typespec-1-2-0/",
"/docs/release-notes/release-2025-08-06/": "/release-notes/typespec-1-3-0/",
"/docs/release-notes/release-2025-09-09/": "/release-notes/typespec-1-4-0/",
"/docs/release-notes/release-2025-10-08/": "/release-notes/typespec-1-5-0/",
"/docs/release-notes/release-2025-11-11/": "/release-notes/typespec-1-6-0/",
"/docs/release-notes/release-2025-12-09/": "/release-notes/typespec-1-7-0/",
"/docs/release-notes/release-2026-01-13/": "/release-notes/typespec-1-8-0/",
"/docs/release-notes/release-2026-02-10/": "/release-notes/typespec-1-9-0/",
"/docs/release-notes/release-2026-03-10/": "/release-notes/typespec-1-10-0/",
},
integrations: [
astroExpressiveCode(),
starlight({
title: "TypeSpec",
sidebar: await processSidebar(
resolve(import.meta.dirname, "src/content/docs"),
"docs",
current,
),
sidebar: [
...(await processSidebar(
resolve(import.meta.dirname, "src/content/docs"),
"docs",
current,
)),
{
label: "🚀 Release Notes",
link: latestReleaseNote ? `/${latestReleaseNote}/` : "/release-notes/",
},
{
label: "🚀 Release Notes",
autogenerate: { directory: "release-notes" },
},
],
favicon: "/img/favicon.svg",
customCss: ["./src/css/custom.css"],
components: {
Header: "./src/components/header/header.astro",
PageFrame: "./src/components/starlight-overrides/PageFrame.astro",
Sidebar: "./src/components/starlight-overrides/Sidebar.astro",
},
expressiveCode: false, // defined directly above
head: [
Expand Down
8 changes: 6 additions & 2 deletions website/src/components/release-notification.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---
import { getCollection } from "astro:content";
const releaseNotes = await getCollection("docs", (x) => x.id.startsWith("docs/release-notes"));
releaseNotes.sort((a, b) => a.id.localeCompare(b.id));
const releaseNotes = await getCollection("docs", (x) => x.id.startsWith("release-notes/"));
releaseNotes.sort((a, b) => {
const dateA = a.data.releaseDate?.getTime() ?? 0;
const dateB = b.data.releaseDate?.getTime() ?? 0;
return dateA - dateB;
});
const last = releaseNotes[releaseNotes.length - 1];
const releaseDate = last.data.releaseDate;
if (!releaseDate) {
Expand Down
51 changes: 51 additions & 0 deletions website/src/components/starlight-overrides/Sidebar.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
import MobileMenuFooter from "@astrojs/starlight/components/MobileMenuFooter.astro";
import SidebarPersister from "@astrojs/starlight/components/SidebarPersister.astro";
import SidebarSublist from "@astrojs/starlight/components/SidebarSublist.astro";
import { getCollection } from "astro:content";

const { sidebar } = Astro.locals.starlightRoute;
const pathname = Astro.url.pathname;
const base = import.meta.env.BASE_URL;

type SidebarEntry = (typeof sidebar)[number];

const isReleaseNotes = pathname.startsWith(base + "release-notes");

/** Returns true for sidebar groups that contain release notes entries. */
function isReleaseNotesGroup(entry: SidebarEntry): boolean {
if (entry.type !== "group") return false;
return entry.entries.some((e) => e.type === "link" && e.href.startsWith(base + "release-notes/"));
}

const filtered = sidebar.filter((entry) =>
isReleaseNotes ? isReleaseNotesGroup(entry) : !isReleaseNotesGroup(entry),
);

// Sort release notes entries by releaseDate so newest appear first.
if (isReleaseNotes) {
const releaseNotes = await getCollection("docs", (x) => x.id.startsWith("release-notes/"));
const dateByHref = new Map<string, number>();
for (const note of releaseNotes) {
const href = base + note.id + "/";
dateByHref.set(href, note.data.releaseDate?.getTime() ?? 0);
}
for (const entry of filtered) {
if (entry.type === "group" && isReleaseNotesGroup(entry)) {
entry.entries.sort((a, b) => {
const dateA = a.type === "link" ? (dateByHref.get(a.href) ?? 0) : 0;
const dateB = b.type === "link" ? (dateByHref.get(b.href) ?? 0) : 0;
return dateB - dateA;
});
}
}
}
---

<SidebarPersister>
<SidebarSublist sublist={filtered} />
</SidebarPersister>

<div class="md:sl-hidden">
<MobileMenuFooter />
</div>
7 changes: 0 additions & 7 deletions website/src/content/current-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,6 @@ const sidebar: SidebarItem[] = [
"extending-typespec/writing-scaffolding-template",
],
},
{
label: "🚀 Release Notes",
autogenerate: {
order: "desc",
directory: "release-notes",
},
},
];

export default sidebar;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: July 2022
releaseDate: 2022-07-08
---

This release contains **breaking changes**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: August 2022
releaseDate: 2022-08-10
---

This release contains **breaking changes**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: September 2022
releaseDate: 2022-09-07
---

This release contains **breaking changes**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: October 2022
releaseDate: 2022-10-12
---

This release contains **breaking changes**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: December 2022
releaseDate: 2022-12-07
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: January 2023
releaseDate: 2023-01-12
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: February 2023
releaseDate: 2023-02-07
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: March 2023
releaseDate: 2023-03-13
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: April 2023
releaseDate: 2023-04-11
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: May 2023
releaseDate: 2023-05-10
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: June 2023
releaseDate: 2023-06-06
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: July 2023
releaseDate: 2023-07-11
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: August 2023
releaseDate: 2023-08-08
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: September 2023
releaseDate: 2023-09-12
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: October 2023
releaseDate: 2023-10-11
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: November 2023
releaseDate: 2023-11-07
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: December 2023
releaseDate: 2023-12-06
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: January 2024
releaseDate: 2024-01-23
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: February 2024
releaseDate: 2024-02-06
---

## Release of VSCode and Visual Studio extensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: March 2024
releaseDate: 2024-03-05
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-55
title: 0.55 - April 2024
releaseDate: 2024-04-02
version: "0.55"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-56
title: 0.56 - May 2024
releaseDate: 2024-05-07
version: "0.56"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-57
title: 0.57 - June 2024
releaseDate: 2024-06-10
version: "0.57"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-58
title: 0.58 - July 2024
releaseDate: 2024-07-16
version: "0.58"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-59
title: 0.59 - August 2024
releaseDate: 2024-08-06
version: "0.59"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-60
title: 0.60 - September 2024
releaseDate: 2024-09-10
version: "0.60"
---

## Features
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
slug: release-notes/typespec-0-61
title: 0.61 - October 2024
releaseDate: 2024-10-09
version: "0.61"
---

:::caution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
slug: release-notes/typespec-0-62
title: 0.62 - November 2024
releaseDate: 2024-11-05
version: "0.62"
Expand Down
Loading
Loading