-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): #268 add a function to access sibling documents
Extend the context collection with a documents function, which returns all documents of the current collection. Closes: #268
- Loading branch information
Showing
7 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@content-collections/core": minor | ||
--- | ||
|
||
Add a function to access sibling documents during transformation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineCollection, defineConfig } from "@content-collections/core"; | ||
|
||
const posts = defineCollection({ | ||
name: "posts", | ||
directory: "sources/posts", | ||
include: "**/*.md(x)?", | ||
schema: (z) => ({ | ||
title: z.string(), | ||
}), | ||
transform: async (doc, {collection}) => { | ||
const docs = await collection.documents(); | ||
const idx = docs.findIndex(d => doc._meta.filePath === d._meta.filePath); | ||
return { | ||
...doc, | ||
prev: idx > 0 ? docs[idx - 1] : null, | ||
next: idx < docs.length - 1 ? docs[idx + 1] : null, | ||
}; | ||
}, | ||
}); | ||
|
||
export default defineConfig({ | ||
collections: [posts], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters