Installations
npm install mdx-collections-svelte
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.18.0
NPM Version
10.8.2
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (97.33%)
JavaScript (2.67%)
Developer
babakfp
Download Statistics
Total Downloads
238
Last Day
4
Last Week
9
Last Month
19
Last Year
238
GitHub Statistics
24 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
57.88 kB
Minified
13.98 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.0
Package Id
mdx-collections-svelte@2.0.0
Unpacked Size
13.47 kB
Size
3.93 kB
File Count
17
NPM Version
10.8.2
Node Version
20.18.0
Publised On
08 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
238
Last day
0%
4
Compared to previous day
Last week
80%
9
Compared to previous week
Last month
5.6%
19
Compared to previous month
Last year
0%
238
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
3
MDX Collections Svelte
An easy way to create collections of markdown pages in SvelteKit.
Example
$lib/collections.ts
:
1import { 2 useTypedCollections, 3 type ImportGlobMarkdownMap, 4} from "mdx-collections-svelte" 5import { z } from "mdx-collections-svelte/zod" 6 7/** 8 * All markdown pages. 9 * 10 * Paths that contain (`_`) in their name are ignored to avoid conflict between pages and components. 11 * 12 * [Glob Import](https://vite.dev/guide/features.html#glob-import). 13 */ 14export const pages = import.meta.glob( 15 [ 16 "/src/content/*/**/*.md", 17 "!/src/content/*/**/_*/*.md", // ignored 18 "!/src/content/*/**/_*.md", // ignored 19 ], 20 { eager: true }, 21) satisfies ImportGlobMarkdownMap 22 23const postsSchema = z.object({ 24 title: z.string().min(1), 25 description: z.string().min(1), 26}) 27 28const productsSchema = z.object({ 29 title: z.string().min(1), 30 price: z.number().min(1), 31}) 32 33export const collections = useTypedCollections(pages, { 34 posts: postsSchema, 35 products: productsSchema, 36})
posts/+page.ts
:
1import { collections } from "$lib/collections.js" 2 3export const load = async () => { 4 const allPosts = collections.getEntries("posts") // You'll get type suggestions. 5 const helloWorldPost = collections.getEntry("hello-world") // You'll get type suggestions. 6 return { allPosts, helloWorldPost } 7}
Empty frontmatter
Use this schema if you don't use frontmatter for a collection.
1z.object({}).default({})
No vulnerabilities found.
No security vulnerabilities found.