Runtime integration
Node.js
Use Fuma Content in Node.js
Installation
npm i fuma-contentCreate a config file to define collections:
import { defineConfig } from "fuma-content/config";
import { mdxCollection } from "fuma-content/collections/mdx";
const docs = mdxCollection({
dir: "content/docs",
});
export default defineConfig({
collections: { docs },
});Each collection generates its files in the .content folder, it's recommended to add a path alias:
{
"compilerOptions": {
"paths": {
"content/*": ["./.content/*"]
}
}
}Register Fuma Content as a Node.js hook:
import { register } from "fuma-content/node";
register();Usage
To interact with Fuma Content, create a Standalone instance.
For example, to generate collection files:
await content.emit();The Node.js hook allows you to access the generated collection outputs, which may require compilation beforehand (e.g. MDX files).
import { docs } from "content/docs";
// the content inside is compiled
console.log(docs.list());