-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathindex.11tydata.js
52 lines (44 loc) · 1.17 KB
/
index.11tydata.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
import { fileURLToPath } from 'url';
import fs from 'node:fs/promises';
import path from 'node:path';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const specStatuses = ['ED', 'FCGS', 'WD', 'CR', 'PR', 'REC'/*, 'CG-FINAL'*/];
async function getDrafts(spec) {
// Find all drafts and store them in [[date, directory], ...] form
const all = {};
for(const status of specStatuses) {
let dates = [];
try {
dates = await fs.readdir(path.join(__dirname, status, spec));
} catch(e) {
if(e.code !== 'ENOENT') {
throw e;
}
}
if(dates.length) {
for(const date of dates) {
if(date[0] === '.') {
continue;
}
all[date] = path.join(status, spec, date);
}
}
}
// Sort drafts in descending order
return Object.entries(all).sort((a, b) => b[0].localeCompare(a[0]));
}
const specs = [
'json-ld',
'json-ld-syntax',
'json-ld-api',
'json-ld-api-best-practices',
'json-ld-framing',
'json-ld-rdf'
];
export default async function() {
return {
specs: Object.fromEntries(await Promise.all(specs.map(async spec => {
return [spec, await getDrafts(spec)];
})))
};
}