Skip to content

Commit 46b7e4f

Browse files
committed
[Chore] Add zero and 1 use partials to style guide page
1 parent b6a1cb0 commit 46b7e4f

File tree

4 files changed

+63
-73
lines changed

4 files changed

+63
-73
lines changed

.github/workflows/partials-audit.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/components/PartialsUsage.astro

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ import { getPartialsUsage } from "~/util/components";
44
import Details from "./Details.astro";
55
import UsageList from "./UsageList.astro";
66
7-
const partials = await getPartialsUsage();
7+
const allPartials = await getPartialsUsage();
8+
9+
const usedPartials = Object.fromEntries(
10+
Object.entries(allPartials).filter(([key, value]) => value.count > 1),
11+
);
12+
13+
const singleUsePartials = Object.fromEntries(
14+
Object.entries(allPartials).filter(([key, value]) => value.count === 1),
15+
);
16+
17+
const zeroUsePartials = Object.fromEntries(
18+
Object.entries(allPartials).filter(([key, value]) => value.count === 0),
19+
);
820
---
921

1022
<Details header="Usage" id="partials-container">
1123
{
12-
[...Object.entries(partials)]
24+
[...Object.entries(usedPartials)]
1325
.sort((a, b) => a[0].localeCompare(b[0]))
1426
.map(([name, usage]) => (
1527
<Details
@@ -22,6 +34,36 @@ const partials = await getPartialsUsage();
2234
}
2335
</Details>
2436

37+
<br />
38+
39+
<Details
40+
header=`1 use partials - ${Object.keys(singleUsePartials).length} files`
41+
id="unused-partials-container"
42+
>
43+
{
44+
[...Object.entries(singleUsePartials)]
45+
.sort((a, b) => a[0].localeCompare(b[0]))
46+
.map(([name, usage]) => (
47+
<p>{`${name} (${usage.count} uses on ${usage.pages.size} pages)`}</p>
48+
))
49+
}
50+
</Details>
51+
52+
<br />
53+
54+
<Details
55+
header=`0 use partials - ${Object.keys(zeroUsePartials).length} files`
56+
id="unused-partials-container"
57+
>
58+
{
59+
[...Object.entries(zeroUsePartials)]
60+
.sort((a, b) => a[0].localeCompare(b[0]))
61+
.map(([name, usage]) => (
62+
<p>{`${name} (${usage.count} uses on ${usage.pages.size} pages)`}</p>
63+
))
64+
}
65+
</Details>
66+
2567
<script>
2668
const params = new URLSearchParams(window.location.search);
2769
console.log(params);

src/content/partials/aegis/clearly-unused.mdx

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/util/components.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ export async function getPartialsUsage(): Promise<Record<string, Usage>> {
8484
withFileTypes: true,
8585
});
8686

87+
const partialEntities = await readdir("./src/content/partials/", {
88+
recursive: true,
89+
withFileTypes: true,
90+
});
91+
92+
// Populate all partials with zero usage
93+
const partialFiles = partialEntities.filter(
94+
(entity) => entity.isFile() && entity.name.endsWith(".mdx"),
95+
);
96+
for (const file of partialFiles) {
97+
const parentPath =
98+
process.platform === "win32"
99+
? file.parentPath.replaceAll("\\", "/")
100+
: file.parentPath;
101+
const product = parentPath.split("/")[3];
102+
const partialName = `${product}/${file.name.replace(".mdx", "")}`;
103+
partials[partialName] = { count: 0, pages: new Set() };
104+
}
105+
87106
const files = entities.filter(
88107
(entity) => entity.isFile() && entity.name.endsWith(".mdx"),
89108
);
@@ -132,6 +151,5 @@ export async function getPartialsUsage(): Promise<Record<string, Usage>> {
132151
});
133152
}
134153
}
135-
136154
return partials;
137155
}

0 commit comments

Comments
 (0)