-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch-readme.js
265 lines (256 loc) · 7.29 KB
/
fetch-readme.js
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
const fetch = require('node-fetch');
const { resolve } = require('path');
const { writeFile } = require('fs/promises');
const url = require('url');
const GITHUB_HOST = 'https://github.com';
const RAW_GITHUB_HOST = 'https://raw.githubusercontent.com';
const mdLinkRegex =
/\[([\w\s\d\-]+)\]\(((?:\/|https?:\/\/|\.)[\w\d\-./?=#]+)\)/g;
/*
After adding a new file to below array, you must manually create the directory
and add an empty .gitkeep file to it so the build will work. For example:
$ cd opensource.contentauth.org/docs
$ mkdir c2pa_service_example
$ cd c2pa_service_example
$ touch .gitkeep
*/
const readmes = [
// js-sdk examples - View manifest
{
dest: resolve(
__dirname,
'../docs/js-sdk/examples/view-manifest/index.html',
),
repo: 'contentauth/c2pa-js',
path: 'examples/minimal-ts-vite/examples/active-manifest/index.html',
},
{
dest: resolve(__dirname, '../docs/js-sdk/examples/view-manifest/main.ts'),
repo: 'contentauth/c2pa-js',
path: 'examples/minimal-ts-vite/examples/active-manifest/main.ts',
},
// Vite Quickstart
{
dest: resolve(__dirname, '../docs/js-sdk/examples/quickstart/vite-main.ts'),
repo: 'contentauth/c2pa-js',
path: 'examples/minimal-ts-vite/examples/cdn/main.ts',
},
// Rollup Quickstart
{
dest: resolve(
__dirname,
'../docs/js-sdk/examples/quickstart/rollup-main.ts',
),
repo: 'contentauth/c2pa-js',
path: 'examples/minimal-ts-rollup/src/main.ts',
},
// WebPack Quickstart
{
dest: resolve(
__dirname,
'../docs/js-sdk/examples/quickstart/webpack-main.ts',
),
repo: 'contentauth/c2pa-js',
path: 'examples/minimal-ts-webpack/src/index.ts',
},
// c2patool
{
dest: resolve(__dirname, '../docs/c2patool/readme.md'),
repo: 'contentauth/c2pa-rs',
path: 'cli/README.md',
},
{
dest: resolve(__dirname, '../docs/c2patool/docs/manifest.md'),
repo: 'contentauth/c2pa-rs',
path: 'cli/docs/manifest.md',
},
{
dest: resolve(__dirname, '../docs/c2patool/docs/x_509.md'),
repo: 'contentauth/c2pa-rs',
path: 'cli/docs/x_509.md',
},
{
dest: resolve(__dirname, '../docs/c2patool/docs/changelog.md'),
repo: 'contentauth/c2pa-rs',
path: 'cli/CHANGELOG.md',
},
{
dest: resolve(__dirname, '../docs/c2patool/docs/usage.md'),
repo: 'contentauth/c2pa-rs',
path: 'cli/docs/usage.md',
},
{
dest: resolve(__dirname, '../docs/c2patool/docs/supported-formats.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/supported-formats.md',
},
// c2pa-service-example
{
dest: resolve(__dirname, '../docs/c2pa-service-example/readme.md'),
repo: 'contentauth/c2pa-service-example',
path: 'README.md',
},
// Node.js lib
{
dest: resolve(__dirname, '../docs/c2pa-node/readme.md'),
repo: 'contentauth/c2pa-node',
path: 'README.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-node/docs/usage.md'),
repo: 'contentauth/c2pa-node',
path: 'docs/usage.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-node/docs/supported-formats.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/supported-formats.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-node/docs/release-notes.md'),
repo: 'contentauth/c2pa-node',
path: 'docs/release-notes.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-node-example/readme.md'),
repo: 'contentauth/c2pa-node-example',
path: 'README.md',
},
// Python lib
{
dest: resolve(__dirname, '../docs/c2pa-python/readme.md'),
repo: 'contentauth/c2pa-python',
path: 'README.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-python/docs/usage.md'),
repo: 'contentauth/c2pa-python',
path: 'docs/usage.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-python/docs/supported-formats.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/supported-formats.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-python/docs/release-notes.md'),
repo: 'contentauth/c2pa-python',
path: 'docs/release-notes.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-python-example/readme.md'),
repo: 'contentauth/c2pa-python-example',
path: 'README.md',
},
// C lib
{
dest: resolve(__dirname, '../docs/c2pa-c/readme.md'),
repo: 'contentauth/c2pa-c',
path: 'README.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-c/docs/usage.md'),
repo: 'contentauth/c2pa-c',
path: 'docs/usage.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-c/docs/supported-formats.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/supported-formats.md',
},
// Rust lib
{
dest: resolve(__dirname, '../docs/rust-sdk/readme.md'),
repo: 'contentauth/c2pa-rs',
path: 'README.md',
},
{
dest: resolve(__dirname, '../docs/rust-sdk/docs/supported-formats.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/supported-formats.md',
},
{
dest: resolve(__dirname, '../docs/rust-sdk/docs/usage.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/usage.md',
},
{
dest: resolve(__dirname, '../docs/rust-sdk/docs/release-notes.md'),
repo: 'contentauth/c2pa-rs',
path: 'docs/release-notes.md',
},
{
dest: resolve(__dirname, '../docs/c2pa-min/readme.md'),
repo: 'contentauth/c2pa-min',
path: 'README.md',
},
{
dest: resolve(__dirname, '../static/sb-alg-list.json'),
repo: 'c2pa-org/softbinding-algorithm-list',
path: 'softbinding-algorithm-list.json',
},
// TrustMark
{
dest: resolve(__dirname, '../docs/trustmark/README.md'),
repo: 'adobe/trustmark',
path: 'README.md',
},
{
dest: resolve(__dirname, '../docs/trustmark/python/CONFIG.md'),
repo: 'adobe/trustmark',
path: 'python/CONFIG.md',
},
{
dest: resolve(__dirname, '../docs/trustmark/FAQ.md'),
repo: 'adobe/trustmark',
path: 'FAQ.md',
},
{
dest: resolve(__dirname, '../docs/trustmark/c2pa/README.md'),
repo: 'adobe/trustmark',
path: 'c2pa/README.md',
},
{
dest: resolve(__dirname, '../docs/trustmark/js/README.md'),
repo: 'adobe/trustmark',
path: 'js/README.md',
},
{
dest: resolve(__dirname, '../docs/trustmark/rust/README.md'),
repo: 'adobe/trustmark',
path: 'rust/README.md',
},
{
dest: resolve(
__dirname,
'../docs/trustmark/rust/crates/trustmark-cli/README.md',
),
repo: 'adobe/trustmark',
path: 'rust/crates/trustmark-cli/README.md',
},
];
function resolveMarkdownLinks(linkBase, content) {
return content.replaceAll(mdLinkRegex, (match, label, href) => {
let revisedUrl = href;
if (!/^https?:\/\//.test(href)) {
revisedUrl = url.resolve(linkBase, href);
}
return `[${label}](${revisedUrl})`;
});
}
async function download() {
for await (const { repo, path, dest, branch = 'main' } of readmes) {
/*
* Pass {branch} var to pull docs from other than main branch.
*/
const src = `${RAW_GITHUB_HOST}/${repo}/${branch}/${path}`;
const linkBase = `${GITHUB_HOST}/${repo}/blob/${branch}/${path}`;
const res = await fetch(src);
const markdown = await res.text();
//const resolvedMarkdown = resolveMarkdownLinks(linkBase, markdown);
//await writeFile(dest, resolvedMarkdown, { encoding: 'utf-8', flag: 'w+' });
await writeFile(dest, markdown, { encoding: 'utf-8', flag: 'w+' });
console.log('Saved %s to %s', src, dest);
}
}
download();