Skip to content

Commit

Permalink
chore: merge branch 'main' of https://github.com/zce/velite
Browse files Browse the repository at this point in the history
  • Loading branch information
zce committed Nov 26, 2023
2 parents c63b684 + cd64367 commit 4db2b58
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 46 deletions.
14 changes: 14 additions & 0 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
:root {
--vp-c-brand-1: #0f766e;
--vp-c-brand-2: #0d9488;
--vp-c-brand-3: #14b8a6;
--vp-c-brand-soft: #0d948822;
}

.dark {
--vp-c-brand-1: #2dd4bf;
--vp-c-brand-2: #14b8a6;
--vp-c-brand-3: #0f766e;
--vp-c-brand-soft: #14b8a622;
}

.stackblitz {
width: 100%;
aspect-ratio: 3 / 2;
Expand Down
16 changes: 15 additions & 1 deletion docs/guide/define-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const site = defineCollection({

Velite uses [Zod](https://zod.dev) to validate the content items in a collection. The `schema` option is used to define the Zod schema used to validate the content items in the collection.

To use Zod in Velite, import the `z` utility from `'velite'`. This is a re-export of the Zod library, and it supports all of the features of Zod. See [Zods Docs](https://zod.dev) for complete documentation on how Zod works and what features are available.
To use Zod in Velite, import the `z` utility from `'velite'`. This is a re-export of the Zod library, and it supports all of the features of Zod. See [Zod's Docs](https://zod.dev) for complete documentation on how Zod works and what features are available.

```js
const posts = defineCollection({
Expand Down Expand Up @@ -189,6 +189,11 @@ const posts = defineCollection({

The `content` field will be transformed from markdown to html, and the result will be available in the `content` field of the content item.

#### Reference

- [`s.markdown(options)`](velite-shemas.md#s-markdown-options)
- [`s.mdx(options)`](velite-shemas.md#s-mdx-options)

### Metadata

Velite can extract metadata from content files. This is useful for adding computed fields to the content items in a collection.
Expand All @@ -201,6 +206,10 @@ const posts = defineCollection({
})
```

#### Reference

- [`s.metadata()`](velite-shemas.md#s-metadata)

### Excerpt

Velite can extract excerpt from content files. This is useful for adding computed fields to the content items in a collection.
Expand All @@ -213,3 +222,8 @@ const posts = defineCollection({
})
})
```

#### Reference

- [`s.summary()`](velite-shemas.md#s-summary)
- [`s.excerpt()`](velite-shemas.md#s-excerpt)
15 changes: 8 additions & 7 deletions docs/guide/velite-shemas.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Field Schemas
# Velite Schemas

To use Zod in Velite, import the `z` utility from `'velite'`. This is a re-export of the Zod library, and it supports all of the features of Zod. See [Zods Docs](https://zod.dev) for complete documentation on how Zod works and what features are available.
To use Zod in Velite, import the `z` utility from `'velite'`. This is a re-export of the Zod library, and it supports all of the features of Zod. See [Zod's Docs](https://zod.dev) for complete documentation on how Zod works and what features are available.

```js
import { z } from 'velite'
Expand All @@ -13,7 +13,8 @@ In addition, Velite has extended Zod schemas, added some commonly used features
```js
import { s } from 'velite'

// `s` is extended from Zod with some custom schemas, s also includes all members of zod
// `s` is extended from Zod with some custom schemas,
// `s` also includes all members of zod, so you can use `s` as `z`
```

## `s.isodate()`
Expand Down Expand Up @@ -54,9 +55,9 @@ name: s.unique('taxonomies')
**by**: unique identifier

- type: `string`
- default: `global`
- default: `'global'`

## `s.slug(unique, reserved)`
## `s.slug(by, reserved)`

`string => string`

Expand All @@ -79,10 +80,10 @@ slug: s.slug('taxonomies', ['admin', 'login'])

### Parameters

**unique**: unique identifier
**by**: unique identifier

- type: `string`
- default: `global`
- default: `'global'`

**reserved**: reserved values

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hero:
features:
- icon: 📦
title: Out of the Box
details: Turns your Markdown, YAML, JSON, or other files into application data layer.
details: Turns your Markdown / MDX, YAML, JSON, or other files into application data layer.
- icon: 😍
title: Type-safe Contents
details: Content Fields validation based on Zod schema, and auto-generated TypeScript types.
Expand Down
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' }` -->
35 changes: 35 additions & 0 deletions docs/reference/types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Types

## Image

```ts
/**
* Image object with metadata & blur image
*/
interface Image {
/**
* public url of the image
*/
src: string
/**
* image width
*/
width: number
/**
* image height
*/
height: number
/**
* blurDataURL of the image
*/
blurDataURL: string
/**
* blur image width
*/
blurWidth: number
/**
* blur image height
*/
blurHeight: number
}
```
8 changes: 4 additions & 4 deletions examples/basic/content/posts/1970-01-01-style-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Doloremque dolor voluptas est sequi omnis. Pariatur ut aut. Sed enim tempora qui

It's very easy to make some words **bold** and other words _italic_ with Markdown. You can even [link to Google!](http://google.com)

Lorem ipsum dolor sit amet, test link adipiscing elit. This is strong. Nullam dignissim convallis est. Quisque aliquam. This is emphasized. Donec faucibus. Nunc iaculis suscipit dui. 53 = 125. Water is H2O. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. The New York Times (Thats a citation). Underline. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.
Lorem ipsum dolor sit amet, test link adipiscing elit. This is strong. Nullam dignissim convallis est. Quisque aliquam. This is emphasized. Donec faucibus. Nunc iaculis suscipit dui. 53 = 125. Water is H2O. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. The New York Times (That's a citation). Underline. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.

HTML and CSS are our tools. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. To copy a file type COPY filename. Dinners at 5:00. Lets make that 7. This text has been struck.
HTML and CSS are our tools. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. To copy a file type COPY filename. Dinner's at 5:00. Let's make that 7. This text has been struck.

#### Emphasis

Expand Down Expand Up @@ -140,12 +140,12 @@ But I have to admit, tasks lists are my favorite:

### Blockquotes

Lets keep it simple. Italics are good to help set it off from the body text. Be sure to style the citation.
Let's keep it simple. Italics are good to help set it off from the body text. Be sure to style the citation.

> Good afternoon, gentlemen. I am a HAL 9000 computer. I became operational at the H.A.L. plant in Urbana, Illinois on the 12th of January 1992. My instructor was Mr. Langley, and he taught me to sing a song. If you’d like to hear it I can sing it for you.
> [HAL 9000](http://en.wikipedia.org/wiki/HAL_9000)
And heres a bit of trailing text.
And here's a bit of trailing text.

---

Expand Down
8 changes: 4 additions & 4 deletions examples/nextjs/content/posts/1970-01-01-style-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Doloremque dolor voluptas est sequi omnis. Pariatur ut aut. Sed enim tempora qui

It's very easy to make some words **bold** and other words _italic_ with Markdown. You can even [link to Google!](http://google.com)

Lorem ipsum dolor sit amet, test link adipiscing elit. This is strong. Nullam dignissim convallis est. Quisque aliquam. This is emphasized. Donec faucibus. Nunc iaculis suscipit dui. 53 = 125. Water is H2O. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. The New York Times (Thats a citation). Underline. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.
Lorem ipsum dolor sit amet, test link adipiscing elit. This is strong. Nullam dignissim convallis est. Quisque aliquam. This is emphasized. Donec faucibus. Nunc iaculis suscipit dui. 53 = 125. Water is H2O. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. The New York Times (That's a citation). Underline. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.

HTML and CSS are our tools. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. To copy a file type COPY filename. Dinners at 5:00. Lets make that 7. This text has been struck.
HTML and CSS are our tools. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. To copy a file type COPY filename. Dinner's at 5:00. Let's make that 7. This text has been struck.

#### Emphasis

Expand Down Expand Up @@ -140,12 +140,12 @@ But I have to admit, tasks lists are my favorite:

### Blockquotes

Lets keep it simple. Italics are good to help set it off from the body text. Be sure to style the citation.
Let's keep it simple. Italics are good to help set it off from the body text. Be sure to style the citation.

> Good afternoon, gentlemen. I am a HAL 9000 computer. I became operational at the H.A.L. plant in Urbana, Illinois on the 12th of January 1992. My instructor was Mr. Langley, and he taught me to sing a song. If you’d like to hear it I can sing it for you.
> [HAL 9000](http://en.wikipedia.org/wiki/HAL_9000)
And heres a bit of trailing text.
And here's a bit of trailing text.

---

Expand Down

0 comments on commit 4db2b58

Please sign in to comment.