Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Nov 26, 2023
1 parent 86f8456 commit cd64367
Showing 1 changed file with 116 additions and 29 deletions.
145 changes: 116 additions & 29 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,142 @@
# Configuration

This documentation is still being written. Please check back later.

<!-- When running vite from the command line, Vite will automatically try to resolve a config file named vite.config.js inside project root (other JS and TS extensions are also supported).
The most basic config file looks like this:
When running `velite` from the command line, Velite will automatically try to resolve a config file named `velite.config.js` inside project root (other JS and TS extensions are also supported).

## Velite Config File

Velite uses `velite.config.js` as the config file. You can create it in the root directory of your project.

```js
// velite.config.js
module.exports = {
export default {
// ...
}
```

::: tip
Config file supports TypeScript & ESM, so you can use the full power of TypeScript to write your config file.
Config file supports TypeScript & ESM & CommonJS. you can use the full power of TypeScript to write your config file, and it's recommended strongly.
:::

## Config Schema
## Typed Config

The config file is a commonjs module that exports a function that returns a config object.
For the better experience, Velite provides a `defineConfig` identity function to define the config file type.

```js
// velite.config.js
module.exports = () => ({
import { defineConfig } from 'velite'

export default defineConfig({
// ...
})
```

The config object is a plain object that contains the following properties:
In addition, Velite also provides a `UserConfig` type to describe the config file type.

- `contentDir`: The directory where the content files are located. Default to `content`.
- `outDir`: The directory where the built content files are located. Default to `.velite`.
- `schemas`: The schemas of the content files. Default to `{}`.
```ts
import type { UserConfig } from 'velite'

```js
// velite.config.js
module.exports = () => ({
contentDir: 'content',
outDir: '.velite',
schemas: {
posts: {
// ...
},
others: {
// ...
}
const config: UserConfig = {
// ...
}

export default config
```

And other identity functions to help you define the config file type:

- `defineCollection`: define collection options
- `defineLoader`: define a file loader

## Config Options

The config object is a plain object that contains the following properties:

```ts
interface UserConfig<C extends Collections = Collections> {
/**
* resolved config file path
*/
configPath: string
/**
* The root directory of the contents
* @default 'content'
*/
root: string
/**
* Output configuration
*/
output: {
/**
* The output directory of the data
* @default '.velite'
*/
data: string
/**
* The output directory of the static assets,
* should be served statically by the app
* @default 'public'
*/
static: string
/**
* The public base path of the static files.
* Must include one level of directory, otherwise `--clean` will automatically clear the static root dir,
* this means that other files in the static dir will also be cleared together
* @default '/static/[name]-[hash:8].[ext]'
*/
filename: `/${string}/${string}`
/**
* The ext blacklist of the static files, such as ['md', 'yml']
* @default []
*/
ignoreFileExtensions: string[]
/**
* Whether to clean the output directories before build
* @default false
*/
clean: boolean
}
})
``` -->
/**
* Collections
*/
collections: C
/**
* File loaders
* @default [] (built-in loaders: 'json', 'yaml', 'markdown')
*/
loaders: Loader[]
/**
* Global markdown options
*/
markdown: MarkdownOptions
/**
* Global MDX options
*/
mdx: MdxOptions
/**
* Data prepare hook, before write to file
* @description
* You can apply additional processing to the output data, such as modify them, add missing data, handle relationships, or write them to files.
* return false to prevent the default output to a file if you wanted
*/
prepare?: (data: {
[name in keyof C]: C[name]['single'] extends true ? C[name]['schema']['_output'] : Array<C[name]['schema']['_output']>
}) => Promisable<void | false>
/**
* Build success hook
* @description
* You can do anything after the build is complete, such as print some tips or deploy the output files.
*/
complete?: () => Promisable<void>
}
```

<!-- ### `root`
- Type: `string`
- Default: `'content'`
The directory where the content files are located.
### `output`
- Type: `object`
- Default: `{ dir: '.velite' }` -->

0 comments on commit cd64367

Please sign in to comment.