Skip to content

Commit

Permalink
add map<id, data> yaml test
Browse files Browse the repository at this point in the history
  • Loading branch information
rgodha24 committed Sep 24, 2024
1 parent 6f8749e commit 5a59ecc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/astro/src/content/loaders/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface FileOptions {
* */
parser?: (
text: string,
) => Record<string, unknown> | Array<{ id: string } & Record<string, unknown>>;
) => Record<string, Record<string, unknown>> | Array<Record<string, unknown>>;
}

/**
Expand Down Expand Up @@ -46,7 +46,7 @@ export function file(fileName: string, options?: FileOptions): Loader {
}

async function syncData(filePath: string, { logger, parseData, store, config }: LoaderContext) {
let data: Array<Record<string, unknown>>;
let data: Array<Record<string, unknown>> | Record<string, Record<string, unknown>>;

try {
const contents = await fs.readFile(filePath, 'utf-8');
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Content Layer', () => {
assert.ok(json.hasOwnProperty('yamlLoader'));
assert.ok(Array.isArray(json.yamlLoader));

const ids = json.yamlLoader.map((item) => item.data.id);
const ids = json.yamlLoader.map((item) => item.id);
assert.deepEqual(ids, [
'bubbles',
'finn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const cats = defineCollection({
const fish = defineCollection({
loader: file('src/data/fish.yaml'),
schema: z.object({
id: z.string(),
name: z.string(),
breed: z.string(),
age: z.number(),
Expand Down
21 changes: 11 additions & 10 deletions packages/astro/test/fixtures/content-layer/src/data/fish.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
- id: "bubbles"
# map of ids to data
bubbles:
name: "Bubbles"
breed: "Goldfish"
age: 2
- id: "finn"
finn:
name: "Finn"
breed: "Betta"
age: 1
- id: "shadow"
shadow:
name: "Shadow"
breed: "Catfish"
age: 3
- id: "spark"
spark:
name: "Spark"
breed: "Tetra"
age: 1
- id: "splash"
splash:
name: "Splash"
breed: "Guppy"
age: 2
- id: "nemo"
nemo:
name: "Nemo"
breed: "Clownfish"
age: 3
- id: "angel-fish"
angel-fish:
name: "Angel Fish"
breed: "Angelfish"
age: 4
- id: "gold-stripe"
gold-stripe:
name: "Gold Stripe"
breed: "Molly"
age: 1
- id: "blue-tail"
blue-tail:
name: "Blue Tail"
breed: "Swordtail"
age: 2
- id: "bubble-buddy"
bubble-buddy:
name: "Bubble Buddy"
breed: "Betta"
age: 3
Expand Down

0 comments on commit 5a59ecc

Please sign in to comment.