-
-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: Raw Content | ||
description: Access to contents raw data in appliction | ||
--- | ||
|
||
There were lots of requests in Content version 2 about accessing contents raw data in production. We're happy to announce that in version 3 it is possible to ship contents raw data to production. | ||
|
||
In order to ship raw contents to production you need to define `rawbody` field in your collection's schema. | ||
That's it. | ||
|
||
Nuxt Content will detect this magical field in your schema and fill it with the raw content. | ||
|
||
```ts [content.config.ts] | ||
import { defineCollection, z } from '@nuxt/content' | ||
|
||
export const collections = { | ||
docs: defineCollection({ | ||
source: '**', | ||
type: 'page', | ||
schema: z.object({ | ||
rawbody: z.string() | ||
}) | ||
}) | ||
} | ||
``` | ||
|
||
And you can use `queryCollection()`{lang="ts-type"} to fetch the raw content. | ||
|
||
```vue [pages/index.vue] | ||
<script setup lang="ts"> | ||
const route = useRoute() | ||
const { data } = useAsyncData('page-' + route.path, () => queryCollection('docs').path(route.path).first()) | ||
</script> | ||
<template> | ||
<pre>{{ data.rawbody }}</pre> | ||
</template> | ||
``` | ||
|
||
|
||
In case you don't want to ship raw content of a specific file you can add `rawbody: ''` to frontmatter of that file. The auto filled value of `rawbody` is acting like default value and when you define `rawbody` in the frontmater it will overwriten. | ||
|
||
```md [content.md] | ||
--- | ||
title: My page | ||
rawbody: '' | ||
--- | ||
|
||
``` | ||
|
||
|
||
::callout | ||
It is important to fill frontmatter fields with a same type of data that defined in collection schema. In this case `rawbody` is a string, and you should consider passing empry string. Do not use `boolean` or other type of values. | ||
:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters