Skip to content

Commit 0d31589

Browse files
docs(contributing): add guide for documentation and asset URLs
Add a new guide explaining how to correctly generate documentation, developer hub, and asset URLs using helper functions. Includes usage examples, translation file integration, and best practices for avoiding hardcoded URLs.
1 parent fd1563b commit 0d31589

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

docs/contributing/urls.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
kind: '👋 Contributing'
3+
title: 'Documentation and asset URLs'
4+
---
5+
6+
# Documentation and asset URLs
7+
8+
When working on components, you'll often need to link to documentation, developer hub pages, or static assets. This guide explains how to handle these URLs correctly.
9+
10+
## Documentation URLs
11+
12+
Use `getDocUrl()` to generate URLs for documentation pages on the Clever Cloud developer hub.
13+
14+
### Import the helper
15+
16+
```js
17+
import { getDocUrl } from '../../lib/dev-hub-url.js';
18+
```
19+
20+
<cc-notice intent="info" message="The path to `dev-hub-url.js` is relative to your component's file."></cc-notice>
21+
22+
### Use the helper
23+
24+
```js
25+
const url = getDocUrl('/billing/unified-invoices');
26+
// => 'https://www.clever.cloud/developers/doc/billing/unified-invoices'
27+
28+
// Empty argument defaults to doc root
29+
const url = getDocUrl();
30+
// => 'https://www.clever.cloud/developers/doc'
31+
```
32+
33+
**_🧐 OBSERVATIONS:_**
34+
35+
* Always use a leading slash: `getDocUrl('/path/to/doc')`.
36+
* You can use the helper directly in templates, as a constant, or in translation files.
37+
* The helper preserves query parameters and URL fragments.
38+
39+
### Usage in translation files
40+
41+
You can use `getDocUrl()` in translation files to generate documentation links:
42+
43+
```js
44+
import { getDocUrl } from '../lib/dev-hub-url.js';
45+
46+
export const translations = {
47+
'my-component.doc-link': () => sanitize`
48+
Read more in the <a href="${getDocUrl('/path/to/doc')}">documentation</a>.
49+
`,
50+
};
51+
```
52+
53+
## Developer hub URLs
54+
55+
Use `getDevHubUrl()` to generate URLs for general developer hub pages (not under `/doc/`).
56+
57+
### Import the helper
58+
59+
```js
60+
import { getDevHubUrl } from '../../lib/dev-hub-url.js';
61+
```
62+
63+
### Use the helper
64+
65+
```js
66+
const url = getDevHubUrl('/api/v4');
67+
// => 'https://www.clever.cloud/developers/api/v4'
68+
69+
// Supports fragments and query params
70+
const url = getDevHubUrl('/api/howto/#oauth1');
71+
// => 'https://www.clever.cloud/developers/api/howto/#oauth1'
72+
```
73+
74+
## Asset URLs
75+
76+
Use `getAssetUrl()` to generate URLs for static assets that are not part of the components project.
77+
78+
### Import the helper
79+
80+
```js
81+
import { getAssetUrl } from '../../lib/assets-url.js';
82+
```
83+
84+
### Use the helper
85+
86+
```js
87+
const url = getAssetUrl('/logos/java-jar.svg');
88+
// => 'https://assets.clever-cloud.com/logos/java-jar.svg'
89+
90+
// Preserves query parameters and fragments
91+
const url = getAssetUrl('/images/logo.png?v=2');
92+
// => 'https://assets.clever-cloud.com/images/logo.png?v=2'
93+
```
94+
95+
### Helper functions for common assets
96+
97+
The `remote-assets.js` file provides convenient wrapper functions for frequently used assets:
98+
99+
```js
100+
import { getFlagUrl, getInfraProviderLogoUrl } from '../../lib/remote-assets.js';
101+
102+
// Country flags
103+
const flag = getFlagUrl('fr');
104+
// => 'https://assets.clever-cloud.com/flags/fr.svg'
105+
106+
// Infrastructure provider logos
107+
const logo = getInfraProviderLogoUrl('ovh');
108+
// => 'https://assets.clever-cloud.com/infra/ovh.svg'
109+
```
110+
111+
## Best practices
112+
113+
### Always use the helpers
114+
115+
**DON'T DO THIS:**
116+
117+
```js
118+
// ❌ Hardcoded URLs
119+
const url = 'https://www.clever.cloud/developers/doc/addons/postgresql';
120+
const asset = 'https://assets.clever-cloud.com/logos/java-jar.svg';
121+
```
122+
123+
**DO THIS:**
124+
125+
```js
126+
// ✅ Use the helpers
127+
const url = getDocUrl('/addons/postgresql');
128+
const asset = getAssetUrl('/logos/java-jar.svg');
129+
```
130+

0 commit comments

Comments
 (0)