-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdocusaurus.config.js
More file actions
369 lines (339 loc) · 12.5 KB
/
Copy pathdocusaurus.config.js
File metadata and controls
369 lines (339 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion
//const lightCodeTheme = require('prism-react-renderer/themes/github');
//const darkCodeTheme = require('prism-react-renderer/themes/dracula');
const lightCodeTheme = require('prism-react-renderer').themes.github;
const darkCodeTheme = require('prism-react-renderer').themes.dracula;
const remoteDocs = require('./remote-docs.json');
const { readFileSync } = require('fs');
const { resolve } = require('path');
const remarkStripHiddenLinks = require('./src/remark/remark-strip-hidden-links');
const copyright = `
<div style="font-size: 0.75rem;">
Copyright © ${new Date().getFullYear()} Adobe. All rights reserved.
| <a style="text-decoration: underline;" href="https://www.adobe.com/privacy.html" target="_blank" rel="noopener noreferrer">Privacy</a>
| <a style="text-decoration: underline;" href="https://www.adobe.com/legal/terms.html" target="_blank" rel="noopener noreferrer">Terms of use</a>
| <a style="text-decoration: underline;" href="https://www.adobe.com/privacy/us-rights.html" target="_blank" rel="noopener noreferrer">Do not sell or share my personal information</a>
</div>
`;
// Map of external repositories to their GitHub repository names, paths, and organizations
// Used to create 'Edit this page' links
const externalRepos = {
'sdk-repos/c2pa-cpp': { repo: 'c2pa-cpp', path: '', org: 'contentauth' },
'sdk-repos/c2pa-swift': { repo: 'c2pa-swift', path: '', org: 'contentauth' },
'sdk-repos/c2pa-android': {
repo: 'c2pa-android',
path: '',
org: 'contentauth',
},
'sdk-repos/c2pa-android-example': {
repo: 'c2pa-android-example',
path: '',
org: 'contentauth',
},
'sdk-repos/c2pa-ios-example': {
repo: 'c2pa-ios-example',
path: '',
org: 'contentauth',
},
'sdk-repos/c2pa-js': { repo: 'c2pa-js', path: '', org: 'contentauth' },
'sdk-repos/c2pa-python': {
repo: 'c2pa-python',
path: '',
org: 'contentauth',
},
'sdk-repos/c2pa-python-example': {
repo: 'c2pa-python-example',
path: '',
org: 'contentauth',
},
'sdk-repos/c2patool': { repo: 'c2patool', path: '', org: 'contentauth' },
'sdk-repos/c2pa-rs': { repo: 'c2pa-rs', path: '', org: 'contentauth' },
'sdk-repos/trustmark': { repo: 'trustmark', path: '', org: 'adobe' },
};
// Exact edit URLs for docs that are mirrored from remote-docs.json sources.
// This handles cases where local doc names differ from source repo paths.
/** @type {Record<string, string>} */
const remoteDocEditUrls = {};
for (const source of remoteDocs.sources) {
if (typeof source.dest !== 'string' || !source.dest.startsWith('docs/')) {
continue;
}
if (typeof source.repo !== 'string' || typeof source.path !== 'string') {
continue;
}
const docPath = source.dest.replace(/^docs\//, '').toLowerCase();
let branch = 'main';
if ('branch' in source && typeof source.branch === 'string') {
branch = source.branch;
}
remoteDocEditUrls[
docPath
] = `https://github.com/${source.repo}/edit/${branch}/${source.path}`;
}
const contentauthGithubBaseUrl = 'https://github.com/contentauth/';
const frontMatterRegex = /^---\r?\n([\s\S]*?)\r?\n---/;
const customEditPathRegex = /^\s*custom_edit_path:\s*(.+?)\s*$/m;
/** @type {Map<string, string | null>} */
const customEditUrlCache = new Map();
/**
* Reads a doc's frontmatter and returns its custom contentauth edit URL, if any.
* @param {string | undefined} versionDocsDirPath
* @param {string} docPath
* @returns {string | null}
*/
function getFrontMatterCustomEditUrl(versionDocsDirPath, docPath) {
if (!versionDocsDirPath) {
return null;
}
const cacheKey = `${versionDocsDirPath}:${docPath}`;
if (customEditUrlCache.has(cacheKey)) {
return customEditUrlCache.get(cacheKey) ?? null;
}
let customEditUrl = null;
try {
const markdown = readFileSync(resolve(versionDocsDirPath, docPath), 'utf8');
const frontMatterMatch = markdown.match(frontMatterRegex);
if (frontMatterMatch) {
const customEditPathMatch =
frontMatterMatch[1].match(customEditPathRegex);
if (customEditPathMatch) {
const customEditPath = customEditPathMatch[1]
.trim()
.replace(/^['"]|['"]$/g, '')
.replace(/^\/+/, '');
if (customEditPath) {
customEditUrl = `${contentauthGithubBaseUrl}${customEditPath}`;
}
}
}
} catch {
// Ignore missing/non-readable files and continue with default edit URL logic.
}
customEditUrlCache.set(cacheKey, customEditUrl);
return customEditUrl;
}
/** @returns {Promise<import('@docusaurus/types').Config>} */
async function createConfig() {
const { default: remarkGithubAdmonitionsToDirectives } = await import(
'remark-github-admonitions-to-directives'
);
return {
title: 'Open-source tools for content authenticity and provenance',
tagline: 'Open-source tools for content authenticity and provenance',
url: 'https://contentauth.netlify.com',
baseUrl: '/',
staticDirectories: ['static'],
onBrokenLinks: 'warn',
onBrokenAnchors: 'warn',
markdown: {
mermaid: true,
hooks: {
onBrokenMarkdownLinks: 'warn',
},
},
favicon: '/favicon.png',
organizationName: 'contentauth',
projectName: 'opensource.contentauth.org',
clientModules: [require.resolve('./src/assets/scripts/ui.js')],
scripts: [
// TODO: Re-enable analytics once we solve flicker problem
// '/scripts/analytics.js',
// 'https://www.adobe.com/marketingtech/main.min.js',
{
src: 'https://cookie-cdn.cookiepro.com/scripttemplates/otSDKStub.js',
'data-domain-script': '20e82cdb-918a-4036-93c6-c356dc13a801',
},
'/scripts/cookie-pro.js',
],
stylesheets: [
// Acumin Pro
'https://use.typekit.net/wgs7uns.css',
// Adobe Clean
'https://use.typekit.net/dnb4eqs.css',
],
presets: [
[
'classic',
/** @type {import('@docusaurus/preset-classic').Options} */
({
docs: {
beforeDefaultRemarkPlugins: [
remarkGithubAdmonitionsToDirectives,
remarkStripHiddenLinks,
],
sidebarPath: require.resolve('./sidebars.js'),
editUrl: ({ docPath, versionDocsDirPath }) => {
const normalizedDocPath = docPath.toLowerCase();
// Don't show edit link for dynamically generated API docs
if (docPath.startsWith('js-sdk/api/')) {
return null;
}
// Special case for supported-formats.md files
if (docPath.endsWith('supported-formats.md')) {
return 'https://github.com/contentauth/c2pa-rs/edit/main/docs/supported-formats.md';
}
// Allow docs to point at a contentauth README/source via frontmatter.
const customEditUrl = getFrontMatterCustomEditUrl(
versionDocsDirPath,
docPath,
);
if (customEditUrl) {
return customEditUrl;
}
// Use explicit source mappings from remote-docs.json when available.
const remoteDocEditUrl = remoteDocEditUrls[normalizedDocPath];
if (remoteDocEditUrl) {
return remoteDocEditUrl;
}
// Check if the doc is from an external repository
const externalRepo = Object.keys(externalRepos).find((repo) =>
normalizedDocPath.startsWith(`${repo}/`),
);
if (externalRepo) {
// Get the GitHub repository info for this external repo
const repoInfo = externalRepos[externalRepo];
// Remove the repo prefix from the path to get the relative path in the repo
let repoPath = normalizedDocPath.replace(
`${externalRepo}/`,
'',
);
// Convert readme.md to README.md in the path
repoPath = repoPath.replace(/readme\.md$/i, 'README.md');
return `https://github.com/${repoInfo.org}/${repoInfo.repo}/edit/main/${repoInfo.path}${repoPath}`;
}
// Add edit link for main docs
let mainPath = docPath;
// Convert readme.md to README.md in the path
mainPath = mainPath.replace(/readme\.md$/i, 'README.md');
return `https://github.com/contentauth/opensource.contentauth.org/edit/main/docs/${mainPath}`;
},
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
}),
],
],
// See here for configuration options:
// https://docusaurus.io/docs/api/themes/configuration
themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
metadata: [
// { property: 'twitter:card', content: 'summary_large_image' },
{ property: 'og:card', content: 'summary_large_image' },
{
property: 'og:description',
content:
'Integrate secure provenance signals into your site, app, or service using open-source tools developed by the Content Authenticity Initiative.',
},
{
property: 'og:title',
content:
'Open-source tools for content authenticity and provenance',
},
],
// Relative to your site's 'static' directory.
// Cannot be SVGs. Can be external URLs too.
colorMode: {
defaultMode: 'light',
disableSwitch: false,
respectPrefersColorScheme: true,
},
docs: {
sidebar: {
hideable: true,
autoCollapseCategories: true,
},
},
navbar: {
logo: {
alt: 'Content Authenticity Initiative',
src: 'img/logo-cai.svg',
width: 180,
height: 54,
href: 'https://contentauthenticity.org',
},
items: [
{
type: 'custom-editThisPage',
position: 'right',
className: 'header-logo header-edit-link',
},
{
href: 'https://discord.gg/CAI',
position: 'right',
className: 'header-logo header-discord-link',
},
{
href: 'https://github.com/contentauth',
position: 'right',
className: 'header-logo header-github-link',
},
{
href: 'http://learn.contentauthenticity.org/',
position: 'right',
className: 'header-logo header-learn-link',
},
],
},
footer: {
style: 'light',
/*
logo: {
src: '#', // stop warning.
alt: 'Content Authenticity Initiative',
href: 'https://contentauthenticity.org',
},
*/
copyright,
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
algolia: {
// The application ID provided by Algolia
appId: 'XOI00ZGSIB',
// Public API key: it is safe to commit it
apiKey: '5b5b38fb40adb6dfa25b6bccb03815a5',
indexName: 'contentauthenticity',
// Optional: see doc section below
contextualSearch: true,
},
}),
plugins: [
require.resolve('./src/plugins/docs404Sidebar'),
[
'@docusaurus/plugin-client-redirects',
{
createRedirects(existingPath) {
const prefix = '/docs/sdk-repos/';
if (existingPath.startsWith(prefix)) {
const redirects = [`/docs/${existingPath.slice(prefix.length)}`];
const c2paRsPrefix = '/docs/sdk-repos/c2pa-rs/';
if (existingPath.startsWith(c2paRsPrefix)) {
redirects.push(
`/docs/rust-sdk/${existingPath.slice(c2paRsPrefix.length)}`,
);
}
return redirects;
}
return undefined;
},
},
],
[
'@signalwire/docusaurus-plugin-llms-txt',
{
siteDescription:
'Integrate secure provenance signals into your site, app, or service using open-source tools developed by the Content Authenticity Initiative.',
depth: 2,
},
],
],
themes: ['docusaurus-json-schema-plugin', '@docusaurus/theme-mermaid'],
};
}
module.exports = createConfig();