-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (28 loc) · 1.36 KB
/
index.js
File metadata and controls
38 lines (28 loc) · 1.36 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
import QRCode from 'qrcode'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url';
import markdownTemplate from './markdownTemplate.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); // get the name of the directory
const pathToVCs = path.join(__dirname, 'certificates')
const indexOfVCs = '' + markdownTemplate
const files = fs.readdirSync(pathToVCs, { withFileTypes: true, recursive: true });
const promises = files.filter(file=>file.isFile && file.name.endsWith('.json')).map(async (file) => {
const pathToVC = path.join(file.parentPath, file.name)
const relativePath = pathToVC.split('certificates').pop()
const rawGithubURL = `https://github.com/digitalcredentials/mit-learn-ob-template/raw/refs/heads/main/certificates${relativePath}`
const localImageFilePath = pathToVC.slice(0, -4) + 'png'
try {
await QRCode.toFile(localImageFilePath, rawGithubURL, {})
} catch (err) {
console.log(`error saving ${pathToVC}: ${err}`)
}
return `### ${relativePath}
[${file.name}](${rawGithubURL})
}png)
`
}
);
const markdownEntries = await Promise.all(promises);
const finalIndexOfVCs = indexOfVCs.concat(markdownEntries.join(''))
fs.writeFileSync(path.join(__dirname, 'certificates/certificates.md'), finalIndexOfVCs)