Skip to content

Commit 0cef20e

Browse files
final feedback and draft review
1 parent b9959e0 commit 0cef20e

7 files changed

Lines changed: 58 additions & 20 deletions

File tree

src/pages/docs/content-as-data/collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ tocHeading: 2
66

77
# Collections
88

9-
Collections are a feature in Greenwood by which you can use [frontmatter](/docs/resources/markdown/#frontmatter) to group pages that can then be referenced through [JavaScript](/docs/content-as-data/data-client/) or [active frontmatter](/docs/content-as-data/active-frontmatter/).
9+
Collections are a feature in Greenwood by which you can use [frontmatter](/docs/resources/markdown/#frontmatter) to group pages that can then be referenced through [JavaScript](/docs/content-as-data/data-client/) or [active frontmatter](/docs/content-as-data/active-frontmatter/). This can be a useful way to group pages for things like navigation menus based on the content in your pages directory.
1010

11-
This can be a useful way to group pages for things like navigation menus based on the content in your pages directory.
11+
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
1212

1313
## Usage
1414

src/pages/docs/content-as-data/data-client.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ tocHeading: 2
66

77
# Data Client
88

9-
To access your content as data with Greenwood, there are three pre-made APIs you can use, based on your use case. These are isomorphic in that they will consume live data during development, and statically build out each query at build time to its own JSON file that will be fetched client side without needing a. This way, you can serialize and / or hydrate from this data as needed based on your needs.
9+
To access your content as data with Greenwood, there are three pre-made APIs you can use, based on your use case. These are isomorphic in that they will consume live data during development, and statically build out each query at build time to its own JSON file that will be fetched client side without needing a server. This way, you can serialize and / or hydrate from this data as needed based on your needs.
10+
11+
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
1012

1113
> This feature works best when used for build time templating when combined with the [**static** optimization](/docs/reference/configuration/#optimization) setting.
1214

src/pages/docs/plugins/css-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Types should automatically be inferred through this package's exports map, but c
154154

155155
To support typing of `.module.css` imports, you can add this type definition to your project:
156156

157-
<app-ctc-block variant="snippet" heading="types.d.ts">
157+
<app-ctc-block variant="snippet" heading="src/types.d.ts">
158158

159159
```ts
160160
declare module "*.module.css" {

src/pages/docs/plugins/raw.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ Types should automatically be inferred through this package's exports map, but c
140140

141141
<!-- prettier-ignore-end -->
142142

143-
To support typing of `.module.css` imports, you can add this type definition to your project:
143+
To support typing of raw file imports, you can add this type definition to your project:
144144

145-
<app-ctc-block variant="snippet" heading="types.d.ts">
145+
<app-ctc-block variant="snippet" heading="src/types.d.ts">
146146

147147
```ts
148148
declare module "*?type=raw" {

src/pages/docs/reference/appendix.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tocHeading: 2
88

99
## Types
1010

11-
In addition to [supporting TypeScript](/docs/resources/typescript/) out of the box, Greenwood also exports a number of useful types that you can use if authoring your configuration files, plugins, etc as TypeScript. You can find all available types for the CLI [here](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/src/types/index.d.ts) including types for configuration, content as data APIs, graph and compilation objects, plugins, and more. Each of Greenwood's plugin will also provide their own set of types within their package at _src/types/index.d.ts_.
11+
In addition to [supporting TypeScript](/docs/resources/typescript/) out of the box, Greenwood also exports a number of useful types that you can use when authoring your configuration files, plugins, data clients, etc as TypeScript. You can find all available types for the CLI [here](https://github.com/ProjectEvergreen/greenwood/blob/master/packages/cli/src/types/index.d.ts) including types for configuration, content as data APIs, graph and compilation objects, plugins, and more. Each of Greenwood's plugin will also provide their own set of types within their package at _src/types/index.d.ts_.
1212

1313
For example, here is how to author a TypeScript based configuration file:
1414

@@ -22,6 +22,40 @@ const config: Config = {
2222
export default config;
2323
```
2424

25+
Here's an example of authoring with Greenwood's Collection capability.
26+
27+
```ts
28+
import { getContentByRoute } from "@greenwood/cli/src/data/client.js";
29+
import type { Page } from "@greenwood/cli";
30+
31+
type BlogPost = Page & {
32+
data: {
33+
author: string;
34+
};
35+
};
36+
37+
export default class BlogPostsList extends HTMLElement {
38+
async connectedCallback() {
39+
const posts: BlogPost[] = await getContentByRoute("/blog/");
40+
41+
this.innerHTML = `
42+
<div>
43+
${posts
44+
.reverse()
45+
.map((post) => {
46+
return `
47+
<li><a href="${post.route}">"${post.title}"</a><span>by: ${post.data.author}</span></li>
48+
`;
49+
})
50+
.join("")}
51+
</div>
52+
`;
53+
}
54+
}
55+
56+
customElements.define("blog-posts-list", BlogPostsList);
57+
```
58+
2559
## Build Output
2660

2761
Greenwood produces a consistent build output that typically mirrors the source directory as it persists all file naming, albeit with hashes included. For static content, this can be used by static hosting sites with no additional configuration, on serverless hosting with our adapters, or self-hosted.

src/pages/docs/reference/plugins-api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ An adapter plugin is simply an `async` function that gets invoked by the Greenwo
7474
<app-ctc-block variant="snippet">
7575

7676
```js
77-
/** @type {import("@greenwood/cll").AdapterPlugin} */
77+
/** @type {import("@greenwood/cli").AdapterPlugin} */
7878
const greenwoodPluginMyPlatformAdapter = () => {
7979
return {
8080
type: "adapter",
@@ -227,7 +227,7 @@ Your plugin might look like this:
227227
* acme-theme-pack.js
228228
* package.json
229229
*/
230-
/** @type {import("@greenwood/cll").ContextPlugin} */
230+
/** @type {import("@greenwood/cli").ContextPlugin} */
231231
export function myContextPlugin() {
232232
return {
233233
type: "context",
@@ -263,7 +263,7 @@ This plugin supports providing an array of "paired" URL objects that can either
263263
<app-ctc-block variant="snippet" heading="my-copy-plugin.js">
264264
265265
```js
266-
/** @type {import("@greenwood/cll").CopyPlugin} */
266+
/** @type {import("@greenwood/cli").CopyPlugin} */
267267
export function myCopyPlugin() {
268268
return {
269269
type: "copy",
@@ -349,7 +349,7 @@ This plugin expects to be given a path to a module that exports a function to ex
349349
<app-ctc-block variant="snippet" heading="my-renderer-plugin.js">
350350
351351
```js
352-
/** @type {import("@greenwood/cll").RendererPlugin} */
352+
/** @type {import("@greenwood/cli").RendererPlugin} */
353353
const greenwoodPluginMyCustomRenderer = () => {
354354
return {
355355
type: "renderer",
@@ -422,7 +422,7 @@ A [resource "interface"](https://github.com/ProjectEvergreen/greenwood/tree/mast
422422
// lifecycles go here
423423
}
424424

425-
/** @type {import("@greenwood/cll").ResourcePlugin} */
425+
/** @type {import("@greenwood/cli").ResourcePlugin} */
426426
export function myExampleResourcePlugin(options = {}) {
427427
return {
428428
type: "resource",
@@ -722,7 +722,7 @@ Simply use the `provider` method to return an array of Rollup plugins:
722722

723723
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
724724

725-
/** @type {import("@greenwood/cll").RollupPlugin} */
725+
/** @type {import("@greenwood/cli").RollupPlugin} */
726726
export function myRollupPlugin() {
727727
const now = new Date().now();
728728

@@ -806,7 +806,7 @@ The below is an excerpt of [Greenwood's internal LiveReload server](https://gith
806806
}
807807
}
808808

809-
/** @type {import("@greenwood/cll").ServerPlugin} */
809+
/** @type {import("@greenwood/cli").ServerPlugin} */
810810
export function myServerPlugin(options = {}) {
811811
return {
812812
type: "server",
@@ -833,7 +833,7 @@ This plugin supports providing an array of "page" objects that will be added as
833833
<app-ctc-block variant="snippet" heading="my-source-plugin.js">
834834
835835
```js
836-
/** @type {import("@greenwood/cll").SourcePlugin} */
836+
/** @type {import("@greenwood/cli").SourcePlugin} */
837837
export const customExternalSourcesPlugin = () => {
838838
return {
839839
type: "source",

src/pages/docs/resources/typescript.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ tocHeading: 2
88

99
# TypeScript
1010

11-
Greenwood provide built-in support for TypeScript, either through type-stripping (default behavior) or with the ability to fallback to [using the TypeScript compiler](/docs/reference/configuration/#use-typescript-compiler) if you're leveraging certain transformation based TypeScript features (like [`enums` and `namespaces`](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8/#the---erasablesyntaxonly-option)) or JavaScript syntax like Decorators. You can see an example repo [here](https://github.com/thescientist13/greenwood-native-typescript)
11+
Greenwood provides built-in support for TypeScript, either through type-stripping (default behavior) or with the ability to fallback to [using the TypeScript compiler](/docs/reference/configuration/#use-typescript-compiler) if you're leveraging certain transformation based TypeScript features (like [`enums` and `namespaces`](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8/#the---erasablesyntaxonly-option)) or JavaScript syntax like Decorators. If you need these additional capabilities, you can set the [`useTsc` option](/docs/reference/configuration/#use-typescript-compiler) in your Greenwood configuration file.
1212

13-
> You can read [this guide](https://nodejs.org/en/learn/typescript/run-natively) to learn more about running TypeScript with NodeJS, including the [`--experimental-transform-types`](https://nodejs.org/docs/latest-v23.x/api/cli.html#--experimental-transform-types) flag.
13+
> You can read [this guide](https://nodejs.org/en/learn/typescript/run-natively) to learn more about running TypeScript with NodeJS, including the [`--experimental-transform-types`](https://nodejs.org/docs/latest-v23.x/api/cli.html#--experimental-transform-types) flag. You can see an example Greenwood TypeScript repo [here](https://github.com/thescientist13/greenwood-native-typescript).
1414
1515
## Setup
1616

1717
The below steps will help you get up and running with TypeScript in your Greenwood project. The general recommendation is to use type-stripping during development for faster live reload, and then run TypeScript during CI (e.g. GitHub Actions) to check and enforce all types, e.g. `tsc --project tsconfig.json`.
1818

1919
1. You will need to use Node **>= 22.6.0** and set the `--experimental-strip-types` flag
2020
1. Install TypeScript into your project, e.g. `npm i typescript --save-dev`
21-
1. Create a _tsconfig.json_ file at the root of your project with these minimum configuration settings
21+
1. Create a _tsconfig.json_ file at the root of your project with these minimum configuration settings. We recommend adding the [`erasableSyntaxOnly` setting](https://www.typescriptlang.org/tsconfig/#erasableSyntaxOnly)
2222

2323
<!-- prettier-ignore-start -->
2424

@@ -46,7 +46,7 @@ The below steps will help you get up and running with TypeScript in your Greenwo
4646

4747
### Configuration
4848

49-
In addition to be able to author your components, SSR pages, and API routes in TypeScript, you can also author your configuration file (and plugins) in TypeScript by using a _greenwood.config.ts_ file.
49+
In addition to being able to author your components, SSR pages, and API routes in TypeScript, you can also author your configuration file (and plugins) in TypeScript by using a _greenwood.config.ts_ file.
5050

5151
<!-- prettier-ignore-start -->
5252

@@ -66,13 +66,15 @@ In addition to be able to author your components, SSR pages, and API routes in T
6666

6767
<!-- prettier-ignore-end -->
6868

69+
See our [reference docs on Greenwood's available types](/docs/reference/appendix/#types) for more information on authoring with TypeScript.
70+
6971
### Import Attributes
7072

7173
Currently TypeScript does not support types for standard [JSON and CSS Import Attributes](https://github.com/microsoft/TypeScript/issues/46135). You can use the below snippets as a reference for providing these types for your own project in the meantime.
7274

7375
<!-- prettier-ignore-start -->
7476

75-
<app-ctc-block variant="snippet" heading="types.d.ts">
77+
<app-ctc-block variant="snippet" heading="src/types.d.ts">
7678

7779
```ts
7880
declare module "*.css" {

0 commit comments

Comments
 (0)