Skip to content

Commit 46f7c05

Browse files
authored
Fix relative link handling an use standard transforms for community pages (#103)
1 parent a373e04 commit 46f7c05

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

remote-content/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,53 @@ Different repositories may have different link structures or conventions. The `r
387387
- Adjusting image paths
388388
- Handling repository-specific markdown formats
389389

390+
#### Link Transformation Behavior
391+
392+
The system automatically transforms relative links in markdown files to ensure they work correctly in the documentation site:
393+
394+
**Relative Links → GitHub URLs**
395+
- Links without `./` prefix (e.g., `[file.md](file.md)` or `[PR_SIGNOFF.md](PR_SIGNOFF.md)`)
396+
- Links with `./` prefix (e.g., `[file.md](./file.md)`)
397+
- Links with `../` navigation (e.g., `[file.md](../../other/file.md)`)
398+
- All are transformed to absolute GitHub URLs: `https://github.com/org/repo/blob/main/path/file.md`
399+
400+
**Internal Guide Links → Local Docs**
401+
- Specific guide files listed in `INTERNAL_GUIDE_MAPPINGS` (in `repo-transforms.js`)
402+
- These stay within the docs site for better navigation
403+
- Example: `guides/QUICKSTART.md``/docs/guide/Installation/quickstart`
404+
405+
**Images → GitHub Raw URLs**
406+
- All relative image paths are converted to GitHub raw URLs
407+
- Example: `![image](./image.png)``![image](https://github.com/org/repo/raw/main/path/image.png)`
408+
409+
**Using `createStandardTransform()`**
410+
411+
All content sources should use `createStandardTransform()` to get consistent link handling:
412+
413+
```javascript
414+
const contentTransform = createStandardTransform('llm-d');
415+
416+
// Then pass it to createContentWithSource:
417+
createContentWithSource({
418+
// ... other options
419+
contentTransform // Apply standard transformations
420+
})
421+
```
422+
423+
For special cases where you need to override specific links after transformation:
424+
425+
```javascript
426+
const contentTransform = (content, sourcePath) => {
427+
const standardTransform = createStandardTransform('llm-d');
428+
const transformed = standardTransform(content, sourcePath);
429+
430+
// Override specific GitHub links to stay local
431+
return transformed
432+
.replace(/\(https:\/\/github\.com\/llm-d\/llm-d\/blob\/main\/CODE_OF_CONDUCT\.md\)/g, '(code-of-conduct)')
433+
.replace(/\(https:\/\/github\.com\/llm-d\/llm-d\/blob\/main\/SIGS\.md\)/g, '(sigs)');
434+
};
435+
```
436+
390437
## 📁 File Structure
391438

392439
```
@@ -468,14 +515,16 @@ For non-component content:
468515
| Page not appearing | Check source URL is publicly accessible |
469516
| Build errors | Verify all `YOUR-...` placeholders are replaced |
470517
| Wrong sidebar order | Check `sidebarPosition` numbers |
471-
| Links broken | Use `contentTransform` to fix relative links or add to `repo-transforms.js` |
518+
| Links broken | Ensure you're using `createStandardTransform()` - it automatically fixes relative links to GitHub URLs |
519+
| Relative links not working | All relative links (with or without `./`) are automatically converted to GitHub URLs by `createStandardTransform()` |
472520
| Import errors | Ensure file is imported in `remote-content/remote-content.js` with correct path |
473521
| Component not showing | Check `component-configs.js` and ensure repository is public |
474522
| Source banner missing | Verify you're using `createContentWithSource()` from utils.js |
475523
| Banner at wrong location | Source banners now appear at bottom of pages automatically |
476524
| Import path errors | Use `../` to reference utils from subdirectories (e.g., `../utils.js`) |
477525
| File in wrong directory | Move to appropriate subdirectory: `architecture/`, `guide/`, or `community/` |
478526
| Template not working | Ensure you're using the updated template with correct import paths |
527+
| Need local links | Override specific links after `createStandardTransform()` - see "Using `createStandardTransform()`" section above |
479528

480529
## 📝 Content Source Banners
481530

remote-content/remote-sources/community/code-of-conduct.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* and transforms it into docs/community/code-of-conduct.md
66
*/
77

8-
import { createContentWithSource } from '../utils.js';
8+
import { createContentWithSource, createStandardTransform } from '../utils.js';
99
import { findRepoConfig, generateRepoUrls } from '../component-configs.js';
1010

1111
// Get repository configuration from centralized config
1212
const repoConfig = findRepoConfig('llm-d');
1313
const { repoUrl, sourceBaseUrl } = generateRepoUrls(repoConfig);
14+
const contentTransform = createStandardTransform('llm-d');
1415

1516
export default [
1617
'docusaurus-plugin-remote-content',
@@ -37,7 +38,8 @@ export default [
3738
newFilename: 'code-of-conduct.md',
3839
repoUrl,
3940
branch: repoConfig.branch,
40-
content
41+
content,
42+
contentTransform
4143
});
4244
}
4345
return undefined;

remote-content/remote-sources/community/contribute.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
* and transforms it into docs/community/contribute.md
66
*/
77

8-
import { createContentWithSource } from '../utils.js';
8+
import { createContentWithSource, createStandardTransform } from '../utils.js';
99
import { findRepoConfig, generateRepoUrls } from '../component-configs.js';
1010

1111
// Get repository configuration from centralized config
1212
const repoConfig = findRepoConfig('llm-d');
1313
const { repoUrl, sourceBaseUrl } = generateRepoUrls(repoConfig);
1414

15+
// Create content transform that applies standard transformations,
16+
// then overrides specific links that should stay local to the docs site
17+
const contentTransform = (content, sourcePath) => {
18+
const standardTransform = createStandardTransform('llm-d');
19+
const transformed = standardTransform(content, sourcePath);
20+
return transformed
21+
.replace(/\(https:\/\/github\.com\/llm-d\/llm-d\/blob\/main\/CODE_OF_CONDUCT\.md\)/g, '(code-of-conduct)')
22+
.replace(/\(https:\/\/github\.com\/llm-d\/llm-d\/blob\/main\/SIGS\.md\)/g, '(sigs)');
23+
};
24+
1525
export default [
1626
'docusaurus-plugin-remote-content',
1727
{
@@ -38,10 +48,7 @@ export default [
3848
repoUrl,
3949
branch: repoConfig.branch,
4050
content,
41-
// Fix relative links in the content
42-
contentTransform: (content) => content
43-
.replace(/\(CODE_OF_CONDUCT\.md\)/g, '(code-of-conduct)')
44-
.replace(/\(SIGS\.md\)/g, '(sigs)')
51+
contentTransform
4552
});
4653
}
4754
return undefined;

remote-content/remote-sources/community/security.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
* and transforms it into docs/community/security.md
66
*/
77

8-
import { createContentWithSource } from '../utils.js';
8+
import { createContentWithSource, createStandardTransform } from '../utils.js';
99
import { findRepoConfig, generateRepoUrls } from '../component-configs.js';
1010

1111
// Get repository configuration from centralized config
1212
const repoConfig = findRepoConfig('llm-d');
1313
const { repoUrl, sourceBaseUrl } = generateRepoUrls(repoConfig);
14+
const contentTransform = createStandardTransform('llm-d');
1415

1516
export default [
1617
'docusaurus-plugin-remote-content',
@@ -38,8 +39,7 @@ export default [
3839
repoUrl,
3940
branch: repoConfig.branch,
4041
content,
41-
// No additional content transformations needed for SECURITY.md
42-
contentTransform: (content) => content
42+
contentTransform
4343
});
4444
}
4545
return undefined;

0 commit comments

Comments
 (0)