Skip to content

Commit

Permalink
docs(project): readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jun 25, 2024
1 parent e740963 commit 6734d63
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 49 deletions.
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

# Redac

Redac is a content authoring library to source content into your website. The library handles Markdown, MDX, Yaml files by default.

## Installation

Redac is only available as an ESM package for now. Please drop a feature request if you desire a CommonJS version.

Install the dependency into your package using your favorite package manager.

```
npm install redac
```

## Documentation

- [Dataset model](./docs/1.model.md)
- [Engine initialisation](./docs/2.initialisation.md)
- [Querying the dataset](./docs/3.query.md)
- [Plugin "mdx"](./docs/plugins/mdx.md)
- [Plugin "yaml"](./docs/plugins/yaml.md)

## Usage

Import the `redac` package, source some data and start querying your dataset.

Short form:

```js
// Import the redac package
import redac from 'redac'
// Initializethe engine
const articles = await redac
// Source Markdown documents
.mdx('./articles')
// Start querying
.from('articles')
.filter( document => document.lang === 'fr')
.list()
```

Long form:

```js
// Import the redac package
import redac from 'redac'
// Initialize the engine
const engine = redac([
// Source Markdown documents
{
module: 'redac/plugins/mdx',
config: './articles',
},
// Source Yaml documents
{
module: 'redac/plugins/yaml',
config: './tags',
},
])
// Start querying
const articles = await engine
.from('articles')
.filter((document) => document.lang === 'fr')
.list()
```

[Next.js](https://nextjs.org/) integration with [next-mdx-remote](https://github.com/hashicorp/next-mdx-remote).

```jsx
import 'server-only'
import redac from 'redac'
import mdx from 'redac/plugins/mdx'
import { MDXRemote } from 'next-mdx-remote/rsc'
import components from '@/mdx/components/index.js'
import rehype from '/src/mdx/rehype.js'
import remark from '/src/mdx/remark.js'
import recma from '/src/mdx/recma.js'

export default async function Page({ params }) {
const page = await redac([
{
module: mdx,
config: './docs',
},
])
.from('pages')
.map(page => ({
...page,
lang: page.lang || 'en'
}))
.filter(
(page) =>
page.lang === params.lang &&
JSON.stringify(page.slug) === JSON.stringify(params.slug)
)
.get()
return (
<div className="prose dark:prose-invert max-w-none">
<h1>{page.data.title}</h1>
<MDXRemote
source={page.content_md}
components={components}
options={{
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: remark,
rehypePlugins: rehype,
recmaPlugins: recma,
format: 'mdx',
}
}}
/>
</div>
)
}
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 5 additions & 49 deletions packages/redac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,8 @@ npm install redac

## Documentation

- [Dataset model](./content/docs/1.model.md)
- [Engine initialisation](./content/docs/2.initialisation.md)
- [Querying the dataset](./content/docs/3.query.md)
- [Plugin "mdx"](./content/docs/plugins/mdx.md)
- [Plugin "yaml"](./content/docs/plugins/yaml.md)

## Usage

Import the `redac` package, source some data and start querying your dataset.

Short form:

```js
// Import the redac package
import redac from 'redac'
// Initializethe engine
const articles = await redac
// Source Markdown documents
.mdx('./articles')
// Start querying
.from('articles')
.filter( document => document.lang === 'fr')
.list()
```

Long form:

```js
// Import the redac package
import redac from 'redac'
// Initialize the engine
const engine = redac([
// Source Markdown documents
{
module: 'redac/plugins/mdx',
config: './articles',
},
// Source Yaml documents
{
module: 'redac/plugins/yaml',
config: './tags',
},
])
// Start querying
const articles = await engine
.from('articles')
.filter((document) => document.lang === 'fr')
.list()
```
- [Dataset model](../../docs/1.model.md)
- [Engine initialisation](../../docs/2.initialisation.md)
- [Querying the dataset](../../docs/3.query.md)
- [Plugin "mdx"](../../docs/plugins/mdx.md)
- [Plugin "yaml"](../../docs/plugins/yaml.md)

0 comments on commit 6734d63

Please sign in to comment.