Skip to content

Commit 96d0cb1

Browse files
authored
docs: fix buttons for changelog (#9649)
The changelog pages where not working with button view as markdown and copy for LLM. Fix it.
1 parent 36b220a commit 96d0cb1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/layouts/MainLayout.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ export interface Props {
1414
content: CollectionEntry<'docs'>['data'];
1515
headings?: MarkdownHeading[];
1616
breadcrumbTitle?: string;
17+
showMarkdownActions?: boolean;
1718
}
1819
19-
const { content, headings, breadcrumbTitle } = Astro.props;
20+
const { content, headings, breadcrumbTitle, showMarkdownActions = true } = Astro.props;
2021
---
2122

2223
<BaseLayout {...Astro.props}>
2324
<RightSidebar slot="secondary-sidebar" {...{ content, headings }} />
2425
<PageContent {...{ content }}>
2526
{
26-
Astro.url.pathname !== '/' && (
27+
Astro.url.pathname !== '/' && showMarkdownActions && (
2728
<Fragment slot="before-title">
2829
<div class="page-heading-bar">
2930
<div class="page-heading-bar__breadcrumbs">

src/pages/[...slug].md.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1+
import { getCollection } from 'astro:content';
12
import { readFile } from 'node:fs/promises';
23
import path from 'node:path';
34
import type { APIRoute } from 'astro';
45
import { allPages } from '~/content';
56

7+
type MarkdownSourceProps = {
8+
id: string;
9+
collection: 'docs' | 'changelog';
10+
};
11+
612
/**
713
* Provides raw markdown (MDX source) versions of each documentation page at the
814
* same route with `.md` appended, e.g. `/getting-started.md`.
915
* This enables llms.txt consumers to fetch LLM-friendly source content.
1016
*/
1117
export async function getStaticPaths() {
12-
return allPages.map((page) => ({
18+
const docPaths = allPages.map((page) => ({
1319
// For catch-all `[...slug]` we must provide the full id as a string (not array),
1420
// mirroring the pattern used in `[...slug].astro` so that `index` maps to /index.md
1521
params: { slug: page.id },
16-
props: { id: page.id },
22+
props: { id: page.id, collection: 'docs' } satisfies MarkdownSourceProps,
1723
}));
24+
25+
const changelogEntries = await getCollection('changelog');
26+
const changelogPaths = changelogEntries.map((entry) => ({
27+
params: { slug: `changelog/${entry.slug}` },
28+
props: { id: entry.slug, collection: 'changelog' } satisfies MarkdownSourceProps,
29+
}));
30+
31+
return [...docPaths, ...changelogPaths];
1832
}
1933

2034
export const GET: APIRoute = async ({ props }) => {
21-
const { id } = props as { id: string };
22-
const fsPath = path.join(process.cwd(), 'src', 'content', 'docs', id + '.mdx');
35+
const { id, collection } = props as MarkdownSourceProps;
36+
const fsPath = path.join(process.cwd(), 'src', 'content', collection, id + '.mdx');
2337
try {
2438
let source = await readFile(fsPath, 'utf-8');
2539
if (!source.endsWith('\n')) source += '\n';

src/pages/changelog/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const title = 'Changelog';
4242
const description = 'Latest product updates from Mergify.';
4343
---
4444

45-
<MainLayout content={{ title, description, suppressTitle: false }}>
45+
<MainLayout content={{ title, description, suppressTitle: false }} showMarkdownActions={false}>
4646
<div class="changelog-header">
4747
<div class="search-wrap">
4848
<label for="search" class="sr-only">Search changelog</label>

0 commit comments

Comments
 (0)