Skip to content

Commit 9da445e

Browse files
kylemclarenclaude
andauthored
Fix markdown export to display inline in browser (#15)
- Keep .md extension (reverted from .txt) - Add nginx config to serve .md files as text/plain with inline disposition - Fix root URL handling: / now links to /index.md - Generate index.md for the homepage instead of .md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent 4a1c89d commit 9da445e

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ RUN printf 'server {\n\
3232
location / {\n\
3333
try_files $uri $uri/ $uri.html =404;\n\
3434
}\n\
35+
location ~* \\.md$ {\n\
36+
types { text/plain md; }\n\
37+
add_header Content-Disposition "inline";\n\
38+
}\n\
3539
location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {\n\
3640
expires 1y;\n\
3741
add_header Cache-Control "public, immutable";\n\

src/components/react/CopyPageButton.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ export function CopyPageButton({
8080
};
8181

8282
const handleViewMarkdown = () => {
83-
const url = pageUrl.endsWith('/') ? pageUrl.slice(0, -1) : pageUrl;
84-
window.open(`${url}.md`, '_blank');
83+
const url = new URL(pageUrl);
84+
const path = url.pathname.replace(/\/$/, '');
85+
// Root path links to /index.md, otherwise append .md
86+
const mdPath = path === '' ? '/index.md' : `${path}.md`;
87+
window.open(`${url.origin}${mdPath}`, '_blank');
8588
};
8689

8790
return (

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const prerender = true;
66
export const getStaticPaths: GetStaticPaths = async () => {
77
const docs = await getCollection('docs');
88
return docs.map((doc) => ({
9-
params: { slug: doc.id === 'index' ? undefined : doc.id },
9+
params: { slug: doc.id },
1010
props: { doc },
1111
}));
1212
};

0 commit comments

Comments
 (0)