Skip to content

Commit 22ecddb

Browse files
authored
Add environment variable for skipping early-stage entries (#316)
* Add environment variable for skipping needsAdditionalResearch entries * Also skip placeholder/exploratory entries * Set default status for requirements; limit values on groups/guidelines * Update README to reflect status field changes
1 parent 6fb4235 commit 22ecddb

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Each group is defined in a JSON file, with its child guidelines located in a
9393
subdirectory with the same name.
9494

9595
- Supports [common fields](#common-fields): `children`, `status`
96+
- `status` for groups is optional, limited to `developing`, `refining`, `mature`
9697
- No additional unique fields
9798

9899
#### Guidelines
@@ -102,13 +103,15 @@ listed under. Each guideline is defined in a Markdown file, with its child
102103
requirements/assertions located in a subdirectory with the same name.
103104

104105
- Supports [common fields](#common-fields): `children`, `howto`, `status`, `title`
106+
- `status` for guidelines is optional, limited to `developing`, `refining`, `mature`
105107
- No additional unique fields
106108

107109
#### Requirements and Assertions
108110

109111
Represents each fifth-level heading specifying an individual requirement or assertion.
110112

111113
- Supports [common fields](#common-fields): `howto`, `status`, `title`
114+
- `status` for requirements and assertions defaults to `exploratory` if not specified
112115
- `needsAdditionalResearch` - Optional boolean, indicating whether to
113116
display a "needs additional research" editor's note
114117
- `type` - Optional string: `foundational`, `supplemental`, or `assertion`
@@ -308,8 +311,13 @@ create a Markdown file under `terms`, then populate its content and any applicab
308311
309312
### `WCAG_DIFFABLE`
310313
311-
Filters build output to reduce noise when diffing output between changes.
314+
When set, filters build output to reduce noise when diffing output between changes.
312315
This is for maintenance purposes only, to catch regressions;
313316
built code is not expected to run properly when this is active!
314317
315318
**Default:** Unset (set to any non-empty value to enable)
319+
320+
### `WCAG_SKIP_WIP`
321+
322+
When set, excludes requirements/assertions that have `needsAdditionalResearch` set to `true`,
323+
or that have `status` set to `placeholder` or `exploratory`.

src/content.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import uniq from "lodash-es/uniq";
55
/** howto can be set to true to indicate the informative and normative slugs are identical */
66
const howtoSchema = z.boolean().or(z.string().regex(/^[\w-]+$/));
77
const statusSchema = z.enum(["placeholder", "exploratory", "developing", "refining", "mature"]);
8+
const parentStatusSchema = statusSchema.exclude(["placeholder", "exploratory"]);
89

910
/** Contains fields common between guidelines and requirements */
1011
const commonChildSchema = z.object({
1112
howto: howtoSchema.optional(),
12-
status: statusSchema.optional(),
1313
title: z.string().optional(),
1414
});
1515

@@ -43,7 +43,7 @@ export const collections = {
4343
loader: glob({ pattern: "*.json", base: "./guidelines/groups", ignore: "index.json" }),
4444
schema: z.object({
4545
children: childrenSchema,
46-
status: statusSchema.optional(),
46+
status: parentStatusSchema.optional(),
4747
title: z.string().optional(),
4848
}),
4949
}),
@@ -55,12 +55,14 @@ export const collections = {
5555
// Moreover, we can't override generateId for requirements to only use slug,
5656
// due to duplicates across separate guidelines, e.g. "style-guide"
5757
children: childrenSchema,
58+
status: parentStatusSchema.optional(),
5859
}),
5960
}),
6061
requirements: defineCollection({
6162
loader: glob({ pattern: "*/*/*.md", base: "./guidelines/groups" }),
6263
schema: commonChildSchema.extend({
6364
needsAdditionalResearch: z.boolean().optional(),
65+
status: statusSchema.default("exploratory"),
6466
type: z
6567
.enum([
6668
"foundational",

src/lib/guidelines.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
import { getCollection, getEntry, type CollectionEntry, type CollectionKey } from "astro:content";
22
import capitalize from "lodash-es/capitalize";
33

4+
/**
5+
* Returns a filtered list of requirement/assertion slugs under the given group and guideline,
6+
* excluding any marked as needing additional research if WCAG_SKIP_WIP is set.
7+
*/
8+
async function getFilteredRequirements(groupId: string, guidelineSlug: string) {
9+
const guideline = await getEntry("guidelines", `${groupId}/${guidelineSlug}`);
10+
if (!guideline) throw new Error(`Unresolvable guideline ID: ${guidelineSlug}`);
11+
12+
const filteredRequirements: string[] = [];
13+
for (const requirementSlug of guideline.data.children) {
14+
const requirement = await getEntry(
15+
"requirements",
16+
`${groupId}/${guidelineSlug}/${requirementSlug}`
17+
);
18+
if (!requirement) throw new Error(`Unresolvable requirement ID: ${requirementSlug}`);
19+
if (
20+
import.meta.env.WCAG_SKIP_WIP &&
21+
(requirement.data.needsAdditionalResearch ||
22+
requirement.data.status === "placeholder" ||
23+
requirement.data.status === "exploratory")
24+
)
25+
continue;
26+
filteredRequirements.push(requirementSlug);
27+
}
28+
return filteredRequirements;
29+
}
30+
431
let groupIds = (await getCollection("groupOrder")).map(({ id }) => id);
532
let groups: Record<string, CollectionEntry<"groups">> = {};
633
let guidelines: Record<string, CollectionEntry<"guidelines">> = {};
@@ -17,6 +44,7 @@ export async function buildGuidelinesHierarchy() {
1744
for (const guidelineSlug of group.data.children) {
1845
const guideline = await getEntry("guidelines", `${groupId}/${guidelineSlug}`);
1946
if (!guideline) throw new Error(`Unresolvable guideline ID: ${guidelineSlug}`);
47+
guideline.data.children = await getFilteredRequirements(groupId, guidelineSlug);
2048
guidelines[guideline.id] = guideline;
2149

2250
for (const requirementSlug of guideline.data.children) {

0 commit comments

Comments
 (0)