Skip to content

Commit

Permalink
update docs for content as data config option and patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Oct 13, 2024
1 parent 14eaf7f commit c9a994e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 11 additions & 0 deletions www/pages/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
basePath: '',
port: 8080,
activeFrontmatter: false,
contentAsData: false,
markdown: {
plugins: [],
settings: {}
Expand Down Expand Up @@ -109,6 +110,16 @@ For convenience, the value of `basePath` will also be made available as a global
> _User content, like `<a>` and `<img>` tags will require manually prefixing the basePath in your code._
### Content As Data
To enable support for Greenwood's [content as data](/docs/data/) capabilities, set the `contentAsData` flag to `true`.

```js
export default {
contentAsData: true
};
```

### Dev Server
Configuration for Greenwood's development server is available using the `devServer` option.
- `extensions`: Provide an array of extensions to watch for changes and reload the live server with. By default, Greenwood will already watch all "standard" web assets (HTML, CSS, JS, etc) it supports by default, as well as any extensions set by [resource plugins](/plugins/resource) you are using in your _greenwood.config.json_.
Expand Down
22 changes: 19 additions & 3 deletions www/pages/docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,28 @@ render() {
}
```

To assist with this, Greenwood provides all your content as data, so let's review.
To assist with this, Greenwood provides all your content as data, so let's check it out!

> First thing though, make sure you've set the [`contentAsData` flag to `true`](/docs/configuration/#content-as-data) in your _greenwood.config.js_.
>
> This feature works best when used for build time templating combining our [**prerender**](/docs/configuration/#prerender) and [**static** optimization](/docs/configuration/#optimization) configurations.
### Pages Data

To get started with, let's review the kind of content you can get as data. Each page will return data in the following schema:
To get started with, let's review the kind of content you can get as data.


#### Schema

Each page will return data in the following schema:

* `id` - a unique kebabe-case transformation of the filename
* `title` (customizable) - inferred title based on the filename
* `label` (customizable) - inferred from the `title` if not configured
* `route` - the filename converted into a path as per file based routing
* `data` (customizable) - any custom frontmatter keys you've added to your page


So for a page at _src/pages/blog/first-post.md_, this is the data you would get back
```md
---
Expand Down Expand Up @@ -127,7 +141,9 @@ Using our [Source plugin](/plugins/source/), just as you can get your content as

### Data Client

To fetch content as data, there are three pre-made APIs you can use, based your needs.
To fetch content as data, there are three pre-made APIs you can use, based your needs. These are isomorphic in that it will consume live data during development, and statically build out each query at build time to its own JSON file and fetched client side.

This way, you can serialize and / or hydrate from this data as needed based on your application's needs.

```js
// get turn the entire set of pages as an array
Expand Down

0 comments on commit c9a994e

Please sign in to comment.