Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions src/pages/wiki/special/mostlinkedpages.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,19 @@ export const GET: APIRoute = async ({ site }) => {
const summaryBySlug = publishedSummaryBySlug();
const pageBySlug = await contentPagesBySlug(rankedSlugs);

// sectionCount is the article's table-of-contents section count — the same
// figure toc.json exposes as `count` and info.json / history.json expose on
// their envelopes, derived from the shared getArticleToc helper. Rendered only
// for the ranked pages so a consumer can gauge each top page's depth (how many
// sections it has) alongside its link popularity without a second fetch.
// Gather each ranked page's section count and revision history in a single pass
// over the ranked list. These were two separate loops over `ranked`; the history
// read is folded into the render pass so the list is traversed once. History is
// read before the no-page guard so every ranked entry still gets a history entry
// (the render/sectionCount step is what requires a resolved page), keeping the
// output byte-identical.
const sectionCountBySlug: Record<string, number> = {};
const historyBySlug: Record<string, ReturnType<typeof historyForSlug>> = {};
const wordCountBySlug: Record<string, number> = {};
for (const entry of ranked) {
historyBySlug[entry.slug] = historyForSlug(entry.slug);
const page = pageBySlug[entry.slug];
if (!page) continue;
const { headings } = await render(page);
sectionCountBySlug[entry.slug] = getArticleToc(headings).length;
wordCountBySlug[entry.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}
await Promise.all(
ranked.map(async (entry) => {
historyBySlug[entry.slug] = historyForSlug(entry.slug);
const page = pageBySlug[entry.slug];
if (!page) return;
const { headings } = await render(page);
sectionCountBySlug[entry.slug] = getArticleToc(headings).length;
wordCountBySlug[entry.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}),
);

const body = JSON.stringify(
{
Expand Down
22 changes: 9 additions & 13 deletions src/pages/wiki/special/recentchanges.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,17 @@ export const GET: APIRoute = async ({ site }) => {
// feed-member pages instead of indexing the whole collection up front.
const pageBySlug = await contentPagesBySlug(feedMemberSlugs);

// sectionCount is the changed article's table-of-contents section count — the
// same figure toc.json exposes as `count` and info.json / history.json expose
// on their envelopes, derived from the shared getArticleToc helper. Rendered
// only for the changed articles in the feed so a change-feed consumer can gauge
// each article's depth without a second fetch. Cached per slug because an
// article can appear in multiple changes.
const wordCountBySlug: Record<string, number> = {};
const sectionCountBySlug: Record<string, number> = {};
for (const slug of feedMemberSlugs) {
const page = pageBySlug[slug];
if (!page) continue;
const { headings } = await render(page);
sectionCountBySlug[slug] = getArticleToc(headings).length;
wordCountBySlug[slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}
await Promise.all(
[...feedMemberSlugs].map(async (slug) => {
const page = pageBySlug[slug];
if (!page) return;
const { headings } = await render(page);
sectionCountBySlug[slug] = getArticleToc(headings).length;
wordCountBySlug[slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}),
);
// revisionCount/firstEdited/lastEdited are the changed article's own commit-
// history stats (history is newest-first) — the same trio info.json /
// allpages.json expose per article, and mostlinkedpages.json / subnets.json /
Expand Down
35 changes: 10 additions & 25 deletions src/pages/wiki/special/subnets.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,19 @@ export const GET: APIRoute = async ({ site }) => {
const subnetSlugs = new Set(subnets.map((subnet) => subnet.slug));
const pageBySlug = await contentPagesBySlug(subnetSlugs);

// sectionCount is the subnet article's table-of-contents section count — the
// same figure toc.json exposes as `count` and info.json / history.json expose
// on their envelopes, derived from the shared getArticleToc helper. Rendered
// only for the registry's subnet articles so a subnet dashboard can gauge each
// subnet's depth (how many sections it documents) without a second fetch.
// Gather each subnet's section count and revision history in a single pass over
// the registry list. These were two separate loops over `subnets`; the history
// read is folded into the render pass so the list is traversed once. History is
// read before the no-page guard so every subnet still gets a history entry (the
// render/sectionCount step is what requires a resolved page), keeping output
// byte-identical.
const sectionCountBySlug: Record<string, number> = {};
const historyBySlug: Record<string, ReturnType<typeof historyForSlug>> = {};
// wordCount is only ever read by subnet.slug below, for the registry's subnet
// articles (a subset of the full page collection — e.g. 128 of ~350) — not
// every published article. Previously tokenized for the full collection up
// front; gated into this same subnets-only loop that already scopes
// sectionCount, the same compute-only-for-used-members pattern #1213 / #1232 /
// #1240 use elsewhere.
const wordCountBySlug: Record<string, number> = {};
for (const subnet of subnets) {
historyBySlug[subnet.slug] = historyForSlug(subnet.slug);
const page = pageBySlug[subnet.slug];
if (!page) continue;
const { headings } = await render(page);
sectionCountBySlug[subnet.slug] = getArticleToc(headings).length;
wordCountBySlug[subnet.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}
await Promise.all(
subnets.map(async (subnet) => {
historyBySlug[subnet.slug] = historyForSlug(subnet.slug);
const page = pageBySlug[subnet.slug];
if (!page) return;
const { headings } = await render(page);
sectionCountBySlug[subnet.slug] = getArticleToc(headings).length;
wordCountBySlug[subnet.slug] = (page.body ?? '').trim().split(/\s+/).filter(Boolean).length;
}),
);

const body = JSON.stringify(
{
Expand Down
Loading