Skip to content

Commit 1854c23

Browse files
Merge branch 'main' of https://github.com/reactjs/react.dev into sync-1207ee36
2 parents 20df580 + 1207ee3 commit 1854c23

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

next.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ const nextConfig = {
2222
async rewrites() {
2323
return {
2424
beforeFiles: [
25+
// Explicit .md extension also serves markdown
26+
{
27+
source: '/:path*.md',
28+
destination: '/api/md/:path*',
29+
},
2530
// Serve markdown when Accept header prefers text/markdown
2631
// Useful for LLM agents - https://www.skeptrune.com/posts/use-the-accept-header-to-serve-markdown-instead-of-html-to-llms/
2732
{
28-
source: '/:path((?!llms.txt).*)',
33+
source: '/:path((?!llms\\.txt|api/md).*)',
2934
has: [
3035
{
3136
type: 'header',
@@ -35,11 +40,6 @@ const nextConfig = {
3540
],
3641
destination: '/api/md/:path*',
3742
},
38-
// Explicit .md extension also serves markdown
39-
{
40-
source: '/:path*.md',
41-
destination: '/api/md/:path*',
42-
},
4343
],
4444
};
4545
},

src/components/PageHeading.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,20 @@ function CopyAsMarkdownButton() {
4141
return () => clearTimeout(timer);
4242
}, [copied]);
4343

44-
async function handleCopy() {
44+
async function fetchPageBlob() {
4545
const cleanPath = asPath.split(/[?#]/)[0];
46+
const res = await fetch(cleanPath + '.md');
47+
if (!res.ok) throw new Error('Failed to fetch');
48+
const text = await res.text();
49+
return new Blob([text], {type: 'text/plain'});
50+
}
51+
52+
async function handleCopy() {
4653
try {
47-
const res = await fetch(cleanPath + '.md');
48-
if (!res.ok) return;
49-
const text = await res.text();
50-
await navigator.clipboard.writeText(text);
54+
await navigator.clipboard.write([
55+
// Don't wait for the blob, or Safari will refuse clipboard access
56+
new ClipboardItem({'text/plain': fetchPageBlob()}),
57+
]);
5158
setCopied(true);
5259
} catch {
5360
// Silently fail

0 commit comments

Comments
 (0)