|
| 1 | +import EleventyFetch from '@11ty/eleventy-fetch'; |
| 2 | + |
| 3 | +const apiBaseUrl = 'https://api.w3.org'; |
| 4 | + |
| 5 | +// TODO: support more editors via configuration or commandline argument |
| 6 | +// Manu Sporny's W3C ID |
| 7 | +const editorId = 'hhvask30a7co0gs0gcsgosgkowws0k4'; |
| 8 | + |
| 9 | +const specs = await EleventyFetch( |
| 10 | + // eslint-disable-next-line max-len |
| 11 | + `${apiBaseUrl}/users/${editorId}/specifications?embed=true`, |
| 12 | + { |
| 13 | + duration: '1d', |
| 14 | + type: 'json' |
| 15 | + }); |
| 16 | +const {specifications} = specs._embedded; |
| 17 | + |
| 18 | +let csv = `"${['Title', 'First Date', 'Latest Date', 'Latest Status', |
| 19 | + 'Series Version', 'Short Link', 'Editors'].join('","')}"\n`; |
| 20 | +const rows = await Promise.all(specifications.map(async spec => { |
| 21 | + // gather editor info |
| 22 | + const rv = await EleventyFetch( |
| 23 | + `${spec._links['latest-version'].href}/editors?embed=true`, |
| 24 | + { |
| 25 | + duration: '1d', |
| 26 | + type: 'json' |
| 27 | + }); |
| 28 | + const editors = rv?._embedded?.editors || []; |
| 29 | + const row = []; |
| 30 | + row.push( |
| 31 | + spec.title, |
| 32 | + spec._links['first-version'].href.split('/').at(-1) |
| 33 | + .replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'), |
| 34 | + spec._links['latest-version'].href.split('/').at(-1) |
| 35 | + .replace(/([0-9]{4})([0-9]{2})([0-9]{2})/, '$1-$2-$3'), |
| 36 | + spec._links['latest-version'].title, |
| 37 | + spec['series-version'], |
| 38 | + spec.shortlink, |
| 39 | + editors.map(editor => editor.name).join(', ') |
| 40 | + ); |
| 41 | + return `"${row.join('","')}"`; |
| 42 | +})); |
| 43 | +csv += rows.join('\n'); |
| 44 | +console.log(csv); |
0 commit comments