Skip to content

Commit d514ad1

Browse files
authored
docs: add custom domain guide #143 (#155)
1 parent 3cf2a60 commit d514ad1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/docs/astro.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ export default defineConfig({
161161
},
162162
],
163163
},
164+
{
165+
label: 'Guides',
166+
items: [
167+
{
168+
label: 'Custom Domain',
169+
link: '/guides/custom-domain',
170+
},
171+
],
172+
},
164173
],
165174
}),
166175
svelte(),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: "Adding a Custom Domain"
3+
---
4+
5+
Enhance the delivery of your media assets by integrating svelte-cloudinary with a [private CDN and/or custom domain](https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_custom_delivery_hostnames_cnames).
6+
7+
:::note
8+
**Private CDN** and **Custom Domain** features are available exclusively on [Cloudinary's Advanced plan](https://cloudinary.com/pricing).
9+
:::
10+
11+
## Step-by-Step Configuration
12+
13+
### 1. Install Dependencies
14+
15+
Ensure you have **svelte-cloudinary** installed in your project:
16+
17+
```bash
18+
npm install svelte-cloudinary
19+
```
20+
21+
### 2. Set Up Environment Variables
22+
23+
Create a `.env` file in your project root (if it doesn't exist already) and add the following variables:
24+
25+
```bash
26+
VITE_CLOUDINARY_CLOUD_NAME="your_cloud_name"
27+
VITE_CLOUDINARY_PRIVATE_CDN="true"
28+
VITE_CLOUDINARY_SECURE_DISTRIBUTION="your-custom-domain.com"
29+
```
30+
Replace your_cloud_name with your actual Cloudinary cloud name and your-custom-domain.com with your custom domain. Read more about [configuring svelte-cloudinary here](https://svelte.cloudinary.dev/config).
31+
32+
:::caution
33+
Never commit your `.env` file to version control. Add it to your `.gitignore` file to keep sensitive information secure.
34+
:::
35+
36+
## Example Usage
37+
38+
With the configuration in place, use the `<CldImage />` component to serve images through your private CDN and custom domain:
39+
40+
```svelte
41+
<script>
42+
import { CldImage } from 'svelte-cloudinary';
43+
</script>
44+
45+
<CldImage
46+
src="<Your Public ID>"
47+
alt="Sample Image"
48+
width="800"
49+
height="600"
50+
/>
51+
```
52+
53+
This setup ensures that the image URL follows your custom domain structure:
54+
55+
- **Before:** `https://res.cloudinary.com/your_cloud_name/image/upload/sample.jpg`
56+
- **After:** `https://your-custom-domain.com/image/upload/sample.jpg`
57+
58+
Learn more about setting up CNAME records on the [Cloudinary docs](https://cloudinary.com/documentation/advanced_url_delivery_options#private_cdns_and_custom_delivery_hostnames_cnames).

0 commit comments

Comments
 (0)