Skip to content

Commit d5abdc9

Browse files
authored
Merge pull request #206 from contentauth/add-page-edit-link
Add edit page link
2 parents 626d70f + d30a332 commit d5abdc9

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

docusaurus.config.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ const copyright = `
1313
</div>
1414
`;
1515

16+
// Map of external repositories to their GitHub repository names, paths, and organizations
17+
const externalRepos = {
18+
'c2pa-c': { repo: 'c2pa-c', path: '', org: 'contentauth' },
19+
'c2pa-min': { repo: 'c2pa-min', path: '', org: 'contentauth' },
20+
'c2pa-node': { repo: 'c2pa-node', path: '', org: 'contentauth' },
21+
'c2pa-node-example': {
22+
repo: 'c2pa-node-example',
23+
path: '',
24+
org: 'contentauth',
25+
},
26+
'c2pa-python': { repo: 'c2pa-python', path: '', org: 'contentauth' },
27+
'c2pa-python-example': {
28+
repo: 'c2pa-python-example',
29+
path: '',
30+
org: 'contentauth',
31+
},
32+
'c2pa-service-example': {
33+
repo: 'c2pa-service-example',
34+
path: '',
35+
org: 'contentauth',
36+
},
37+
c2patool: { repo: 'c2pa-rs', path: 'cli/', org: 'contentauth' },
38+
'rust-sdk': { repo: 'c2pa-rs', path: '', org: 'contentauth' },
39+
trustmark: { repo: 'trustmark', path: '', org: 'adobe' },
40+
};
41+
1642
/** @type {import('@docusaurus/types').Config} */
1743
const config = {
1844
title: 'Open-source tools for content authenticity and provenance',
@@ -49,6 +75,38 @@ const config = {
4975
({
5076
docs: {
5177
sidebarPath: require.resolve('./sidebars.js'),
78+
editUrl: ({ docPath }) => {
79+
// Don't show edit link for dynamically generated API docs
80+
if (docPath.startsWith('js-sdk/api/')) {
81+
return null;
82+
}
83+
84+
// Special case for supported-formats.md files
85+
if (docPath.endsWith('supported-formats.md')) {
86+
return 'https://github.com/contentauth/c2pa-rs/edit/main/docs/supported-formats.md';
87+
}
88+
89+
// Check if the doc is from an external repository
90+
const externalRepo = Object.keys(externalRepos).find((repo) =>
91+
docPath.startsWith(`${repo}/`),
92+
);
93+
94+
if (externalRepo) {
95+
// Get the GitHub repository info for this external repo
96+
const repoInfo = externalRepos[externalRepo];
97+
// Remove the repo prefix from the path to get the relative path in the repo
98+
let repoPath = docPath.replace(`${externalRepo}/`, '');
99+
// Convert readme.md to README.md in the path
100+
repoPath = repoPath.replace(/readme\.md$/i, 'README.md');
101+
return `https://github.com/${repoInfo.org}/${repoInfo.repo}/edit/main/${repoInfo.path}${repoPath}`;
102+
}
103+
104+
// Add edit link for main docs
105+
let mainPath = docPath;
106+
// Convert readme.md to README.md in the path
107+
mainPath = mainPath.replace(/readme\.md$/i, 'README.md');
108+
return `https://github.com/contentauth/opensource.contentauth.org/edit/main/docs/${mainPath}`;
109+
},
52110
},
53111
theme: {
54112
customCss: require.resolve('./src/css/custom.css'),
@@ -92,7 +150,6 @@ const config = {
92150
content: 'Open-source tools for content authenticity and provenance',
93151
},
94152
],
95-
96153
// Relative to your site's 'static' directory.
97154
// Cannot be SVGs. Can be external URLs too.
98155
colorMode: {

0 commit comments

Comments
 (0)