
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
mdx-collections-svelte
Advanced tools
An easy way to create collections of markdown pages in SvelteKit.
An easy way to create collections of markdown pages in SvelteKit.
$lib/collections.ts
:
import {
useTypedCollections,
type ImportGlobMarkdownMap,
} from "mdx-collections-svelte"
import { z } from "mdx-collections-svelte/zod"
/**
* All markdown pages.
*
* Paths that contain (`_`) in their name are ignored to avoid conflict between pages and components.
*
* [Glob Import](https://vite.dev/guide/features.html#glob-import).
*/
export const pages = import.meta.glob(
[
"/src/content/*/**/*.md",
"!/src/content/*/**/_*/*.md", // ignored
"!/src/content/*/**/_*.md", // ignored
],
{ eager: true },
) satisfies ImportGlobMarkdownMap
const postsSchema = z.object({
title: z.string().min(1),
description: z.string().min(1),
})
const productsSchema = z.object({
title: z.string().min(1),
price: z.number().min(1),
})
export const collections = useTypedCollections(pages, {
posts: postsSchema,
products: productsSchema,
})
posts/+page.ts
:
import { collections } from "$lib/collections.js"
export const load = async () => {
const allPosts = collections.getEntries("posts") // You'll get type suggestions.
const helloWorldPost = collections.getEntry("hello-world") // You'll get type suggestions.
return { allPosts, helloWorldPost }
}
Use this schema if you don't use frontmatter for a collection.
z.object({}).default({})
FAQs
An easy way to create collections of markdown pages in SvelteKit.
We found that mdx-collections-svelte demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.