Skip to content

Commit

Permalink
fix(lint): support pages with multiple browser-compat keys
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jan 3, 2025
1 parent 28b4bbe commit dd817d0
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lint/linter/test-mdn-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,25 @@ const slugByPath = (() => {
continue;
}

const path = item.frontmatter['browser-compat'];
if (typeof path !== 'string') {
// Ignore pages with multiple keys.
continue;
}
const value = item.frontmatter['browser-compat'];
const paths = Array.isArray(value) ? value : [value];

const slug = item.frontmatter.slug;

const slugTail = slug.split('/').at(-1);
const pathTail = path.split('.').at(-1);
for (const path of paths) {
const slugTail = slug.split('/').at(-1);
const pathTail = path.split('.').at(-1);

if (!slugTail.includes(pathTail) && !pathTail?.includes(slugTail)) {
// Ignore unrelated pages/features.
continue;
}
if (!slugTail.includes(pathTail) && !pathTail?.includes(slugTail)) {
// Ignore unrelated pages/features.
continue;
}

if (!slugsByPath.has(path)) {
slugsByPath.set(path, []);
if (!slugsByPath.has(path)) {
slugsByPath.set(path, []);
}
slugsByPath.get(path)?.push(item.frontmatter.slug);
}
slugsByPath.get(path)?.push(item.frontmatter.slug);
}

const slugByPath = new Map<string, string>();
Expand Down

0 comments on commit dd817d0

Please sign in to comment.