From 1509e09933db9d7d50685cf0f72ad6e7fdfcd848 Mon Sep 17 00:00:00 2001 From: Brian Perry Date: Thu, 23 Jan 2025 09:30:01 -0600 Subject: [PATCH] docs: add remaining examples to getResourceFromContext typedoc --- packages/next-drupal/src/next-drupal-pages.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/next-drupal/src/next-drupal-pages.ts b/packages/next-drupal/src/next-drupal-pages.ts index 381edef9..821d4b8e 100644 --- a/packages/next-drupal/src/next-drupal-pages.ts +++ b/packages/next-drupal/src/next-drupal-pages.ts @@ -126,7 +126,32 @@ export class NextDrupalPages extends NextDrupal { * } * ``` * @examples + * Fetch a resource from context. + * ```ts title=pages/[[...slug]].tsx + * export async function getStaticProps(context) { + * const node = await drupal.getResourceFromContext("node--page", context) * + * return { + * props: { + * node, + * }, + * } + * } + * ``` + * Fetch a resource from context in a sub directory. + * ```ts title=pages/articles/[[...slug]].tsx + * export async function getStaticProps(context) { + * const node = await drupal.getResourceFromContext("node--page", context, { + * pathPrefix: "/articles", + * }) + * + * return { + * props: { + * node, + * }, + * } + * } + * ``` * Using DrupalNode type: * ```ts * import { DrupalNode } from "next-drupal"