|
30 | 30 | 'required-sections': false, |
31 | 31 | }, |
32 | 32 | preProcess: [ |
33 | | - function checkAudiences() { |
| 33 | + function checkAudiences(_conf, _doc, utils) { |
34 | 34 | // Ensure every principle has a data-audiences attribute with a |
35 | 35 | // space-separated list of the target audiences of that principle. |
36 | | - let errors = Array.from(document.querySelectorAll('div.practice') |
37 | | - ).flatMap(practice => { |
38 | | - const audiences = practice.dataset.audiences?.split(/\s+/) ?? []; |
39 | | - if (audiences.length === 0) { |
40 | | - return `Missing data-audiences attribute in principle "${practice.textContent}".`; |
41 | | - } |
42 | | - const unknownAudiences = audiences.filter( |
43 | | - audience => !['websites', 'user-agents', 'api-designers'].includes(audience)); |
44 | | - if (unknownAudiences.length > 0) { |
45 | | - return `Unknown audience "${unknownAudiences.join(', ')}" in principle "${practice.textContent}".`; |
46 | | - } |
47 | | - return []; |
48 | | - }); |
49 | | - if (errors.length !== 0) { |
50 | | - throw new Error(errors.join('\n')); |
| 36 | + for (const practice of document.querySelectorAll("div.practice")) { |
| 37 | + const audiences = practice.dataset.audiences?.split(/\s+/) ?? []; |
| 38 | + if (audiences.length === 0) { |
| 39 | + utils.showError( |
| 40 | + `Missing data-audiences attribute in principle.`, |
| 41 | + { |
| 42 | + title: "Missing data-audiences attribute.", |
| 43 | + elements: [practice], |
| 44 | + hint: 'Set it to a space-separated list of "websites", "user-agents", or "api-designers".', |
| 45 | + } |
| 46 | + ); |
| 47 | + continue; |
| 48 | + } |
| 49 | + const unknownAudiences = audiences.filter( |
| 50 | + (audience) => |
| 51 | + !["websites", "user-agents", "api-designers"].includes(audience) |
| 52 | + ); |
| 53 | + if (unknownAudiences.length > 0) { |
| 54 | + const list = new Intl.ListFormat().format(unknownAudiences); |
| 55 | + utils.showError( |
| 56 | + `Unknown audience "${list}" in principle.`, |
| 57 | + { |
| 58 | + title: "Unknown audience in data-audience attribute.", |
| 59 | + elements: [practice], |
| 60 | + hint: `Remove ${list}.`, |
| 61 | + } |
| 62 | + ); |
| 63 | + } |
51 | 64 | } |
52 | 65 | } |
53 | 66 | ], |
|
0 commit comments