Skip to content

Commit 0ce3347

Browse files
Changesets for ao3 loader
1 parent e67e2a9 commit 0ce3347

8 files changed

Lines changed: 951 additions & 12 deletions

File tree

.changeset/small-planets-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fujocoded/astro-ao3-loader": patch
3+
---
4+
5+
Updated to latest @fujocoded/ao3.js

.changeset/tricky-flies-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fujocoded/astro-ao3-loader": patch
3+
---
4+
5+
Supports Astro 5 (Astro 4 will work still with TS errors)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- 1728802
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineCollection } from "astro:content";
2-
import { worksLoader } from "@fujocoded/astro-ao3-loader";
2+
import { worksLoader, seriesLoader } from "@fujocoded/astro-ao3-loader";
33

44
export const collections = {
55
fanfictions: defineCollection({ loader: worksLoader }),
6+
series: defineCollection({ loader: seriesLoader }),
67
};

astro-ao3-loader/__examples__/astro-5/src/pages/index.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import { getCollection } from "astro:content";
33
44
const fanfictions = await getCollection("fanfictions");
5+
const series = await getCollection("series");
56
67
// Uncomment the next line to see what's inside the `fanfictions`
78
// variable and what data you can access
89
// console.dir(fanfictions, { depth: null });
10+
console.dir(series, {depth: null})
911
---
1012

1113
<html lang="en">

astro-ao3-loader/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"yaml": "^2.8.2"
3535
},
3636
"devDependencies": {
37-
"astro": "^5.16.9"
37+
"astro": "^5.16.9",
38+
"ts-to-zod": "^5.1.0"
3839
},
3940
"publishConfig": {
4041
"access": "public"

astro-ao3-loader/src/index.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getWork, setFetcher } from "@fujocoded/ao3.js";
1+
import { getWork, getSeries, setFetcher } from "@fujocoded/ao3.js";
22
import { readFileSync } from "node:fs";
33
import { WorkSummarySchema } from "./schemas.ts";
44
import { parse } from "yaml";
@@ -38,3 +38,38 @@ export const worksLoader: Loader = {
3838
},
3939
schema: WorkSummarySchema,
4040
};
41+
42+
43+
export const seriesLoader: Loader = {
44+
name: "ao3-series-loader",
45+
load: async ({ store, logger }: LoaderContext) => {
46+
setFetcher(getFetcher(logger));
47+
const file = readFileSync("./src/content/ao3/series.yaml", {
48+
encoding: "utf-8",
49+
});
50+
const seriesId = (parse(file) as any[]).map((workId) => workId.toString());
51+
const ficGroupsFetcher = getNextFicGroupFetcher(seriesId, logger)();
52+
while (true) {
53+
const nextBatch = ficGroupsFetcher.next();
54+
logger.info(`Loading fics ${nextBatch.value?.join(", ")}`);
55+
const fetchedWorks = await Promise.allSettled(
56+
nextBatch.value?.map((workId) =>
57+
getSeries({ seriesId: workId.toString() })
58+
) ?? []
59+
);
60+
fetchedWorks.forEach((response) => {
61+
if (response.status == "rejected") {
62+
return;
63+
}
64+
logger.info(`Setting data for fic ${response.value.id}`);
65+
// @ts-expect-error TODO: apparently interfaces and types treat
66+
// index signatures differently
67+
store.set({ id: response.value.id, data: response.value });
68+
});
69+
if (nextBatch.done) {
70+
break;
71+
}
72+
}
73+
},
74+
schema: WorkSummarySchema,
75+
};

0 commit comments

Comments
 (0)