Skip to content

Commit b3c8c35

Browse files
committed
add interactive component
1 parent 387c3ff commit b3c8c35

File tree

2 files changed

+98
-39
lines changed

2 files changed

+98
-39
lines changed

advanced/subpath/vercel.mdx

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: "Vercel"
33
description: "Host documentation at a subpath using Vercel"
44
---
55

6+
import { VercelJsonGenerator } from "/snippets/vercel-json-generator.mdx";
7+
68
<Steps>
79
<Step title="Move your docs files">
810
Edit your file structure so that all your files are within a folder which is your custom subpath. So if you want to host your docs at `/docs` you would do the following:
@@ -15,46 +17,9 @@ description: "Host documentation at a subpath using Vercel"
1517
```
1618
</Step>
1719
<Step title="Configure your vercel.json">
18-
In your main website add the following rewrites to your `vercel.json`. Make sure to replace `[SUBDOMAIN]` with your subdomain.
20+
In your main website add the following rewrites to your `vercel.json`.
1921

20-
```json
21-
{
22-
"rewrites": [
23-
{
24-
"source": "/api/request",
25-
"destination": "https://[SUBDOMAIN].mintlify.app/api/request"
26-
},
27-
{
28-
"source": "/custom/subdirectory",
29-
"destination": "https://[SUBDOMAIN].mintlify.app"
30-
},
31-
{
32-
"source": "/custom/subdirectory/llms.txt",
33-
"destination": "https://[SUBDOMAIN].mintlify.app/llms.txt"
34-
},
35-
{
36-
"source": "/custom/subdirectory/llms-full.txt",
37-
"destination": "https://[SUBDOMAIN].mintlify.app/llms-full.txt"
38-
},
39-
{
40-
"source": "/custom/subdirectory/sitemap.xml",
41-
"destination": "https://[SUBDOMAIN].mintlify.app/sitemap.xml"
42-
},
43-
{
44-
"source": "/custom/subdirectory/robots.txt",
45-
"destination": "https://[SUBDOMAIN].mintlify.app/robots.txt"
46-
},
47-
{
48-
"source": "/custom/subdirectory/:path*",
49-
"destination": "https://[SUBDOMAIN].mintlify.app/custom/subdirectory/:path*"
50-
},
51-
{
52-
"source": "/mintlify-assets/:path+",
53-
"destination": "https://[SUBDOMAIN].mintlify.app/mintlify-assets/:path+"
54-
}
55-
]
56-
}
57-
```
22+
<VercelJsonGenerator />
5823
</Step>
5924
</Steps>
6025

snippets/vercel-json-generator.mdx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
export const VercelJsonGenerator = () => {
2+
const [subdomain, setSubdomain] = useState('[SUBDOMAIN]')
3+
const [subdirectory, setSubdirectory] = useState('/docs')
4+
5+
const vercelConfig = {
6+
rewrites: [
7+
{
8+
source: "/api/request",
9+
destination: `https://${subdomain}.mintlify.app/api/request`
10+
},
11+
{
12+
source: `/${subdirectory}`,
13+
destination: `https://${subdomain}.mintlify.app`
14+
},
15+
{
16+
source: `/${subdirectory}/llms.txt`,
17+
destination: `https://${subdomain}.mintlify.app/llms.txt`
18+
},
19+
{
20+
source: `/${subdirectory}/llms-full.txt`,
21+
destination: `https://${subdomain}.mintlify.app/llms-full.txt`
22+
},
23+
{
24+
source: `/${subdirectory}/sitemap.xml`,
25+
destination: `https://${subdomain}.mintlify.app/sitemap.xml`
26+
},
27+
{
28+
source: `/${subdirectory}/robots.txt`,
29+
destination: `https://${subdomain}.mintlify.app/robots.txt`
30+
},
31+
{
32+
source: `/${subdirectory}/:path*`,
33+
destination: `https://${subdomain}.mintlify.app/${subdirectory}/:path*`
34+
},
35+
{
36+
source: "/mintlify-assets/:path+",
37+
destination: `https://${subdomain}.mintlify.app/mintlify-assets/:path+`
38+
}
39+
]
40+
}
41+
42+
const copyToClipboard = () => {
43+
navigator.clipboard
44+
.writeText(JSON.stringify(vercelConfig, null, 2))
45+
.then(() => {
46+
console.log('Copied config to clipboard!')
47+
})
48+
.catch((err) => {
49+
console.error("Failed to copy: ", err)
50+
})
51+
}
52+
53+
return (
54+
<div className="p-4 border dark:border-white/10 rounded-2xl not-prose space-y-4">
55+
<div className="space-y-4">
56+
<div>
57+
<label className="block text-sm text-zinc-950/70 dark:text-white/70 mb-1">
58+
Subdomain
59+
</label>
60+
<input
61+
type="text"
62+
value={subdomain}
63+
onChange={(e) => setSubdomain(e.target.value)}
64+
placeholder="your-subdomain"
65+
className="w-full p-1 text-sm rounded border dark:border-white/10 bg-transparent"
66+
/>
67+
</div>
68+
<div>
69+
<label className="block text-sm text-zinc-950/70 dark:text-white/70 mb-1">
70+
Subdirectory
71+
</label>
72+
<input
73+
type="text"
74+
value={subdirectory}
75+
onChange={(e) => setSubdirectory(e.target.value)}
76+
placeholder="docs"
77+
className="w-full p-1 text-sm rounded border dark:border-white/10 bg-transparent"
78+
/>
79+
</div>
80+
</div>
81+
<div className="relative">
82+
<button
83+
onClick={copyToClipboard}
84+
className="absolute top-2 right-2 px-2 py-1 text-sm border dark:border-white/10 rounded hover:bg-zinc-950/5 dark:hover:bg-white/5 transition-colors bg-white"
85+
>
86+
Copy to Clipboard
87+
</button>
88+
<pre className="bg-zinc-950/5 dark:bg-white/5 p-4 rounded-lg overflow-auto text-xs">
89+
<code>{JSON.stringify(vercelConfig, null, 2)}</code>
90+
</pre>
91+
</div>
92+
</div>
93+
)
94+
}

0 commit comments

Comments
 (0)