🗃
@flatbread/source-filesystem Transform files into content that can be fetched with GraphQL.
💾 Install
Use pnpm
, npm
, or yarn
:
pnpm i @flatbread/source-filesystem
👩🍳 Usage
Add the source as a property of the default export within your flatbread.config.js
file:
// flatbread.config.js
import defineConfig from '@flatbread/config';
import transformer from '@flatbread/transformer-markdown';
import filesystem from '@flatbread/source-filesystem';
const transformerConfig = {
markdown: {
gfm: true,
externalLinks: true,
},
};
export default defineConfig({
source: filesystem(),
transformer: transformer(transformerConfig),
content: [
{
path: 'content/posts',
collection: 'Post',
},
],
});
A filesystem source will also require a transformer in order to parse the files into the proper internal schema. The example above is looking for a set of Markdown files, so in order to let Flatbread understand the content of markdown (.md, .markdown, .mdx) files, you must install @flatbread/transformer-markdown as a dependency. Register the transformer which coresponds to your content filetype as the transformer
property in your flatbread.config.js
.
Options
content
- Type:
Content
required
An array of content types - each of which will appear in GraphQL.
collection
- Type:
string
- Default:
'FileNode'
The name for this content type that will appear in GraphQL.
path
- Type:
string
required
Where to look for files of the current content type.
- you can use
**
or*
to match all files or folders - you can capture the file or folder names to store them as data on the resulting nodes
[category]
[title].md
refs
- Type:
object
Define fields that will have a reference to another node. The referenced collection
is expected to exist within an element of the content
array.
export default defineConfig({
source: filesystem(),
transformer: transformer(transformerConfig),
content: [
{
path: 'content/posts',
collection: 'Post',
refs: {
author: 'Author',
},
},
{
path: 'content/authors',
collection: 'Author',
},
],
});