-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathindex.11tydata.js
47 lines (39 loc) · 1.01 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
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'];
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));
} 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, date);
}
}
}
// Sort drafts in descending order
return Object.entries(all).sort((a, b) => b[0].localeCompare(a[0]));
}
const specs = [
'requirements'
];
export default async function() {
return {
specs: Object.fromEntries(await Promise.all(specs.map(async spec => {
return [spec, await getDrafts(spec)];
})))
};
}