From f8ef7912ea945cace0832182cee63b265113912f Mon Sep 17 00:00:00 2001 From: lihbr Date: Tue, 24 Oct 2023 13:57:01 +0200 Subject: [PATCH 1/2] feat: support environments --- playground/nuxt.config.ts | 1 - src/module.ts | 6 +++ src/runtime/plugin.client.ts | 2 +- src/runtime/plugin.ts | 10 +++-- src/types.ts | 81 +++++++++++++++++++++++++++++++++++- 5 files changed, 93 insertions(+), 7 deletions(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 3377b50..2888d56 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -24,7 +24,6 @@ export default defineNuxtConfig({ path: '/' } ] - } } }) diff --git a/src/module.ts b/src/module.ts index 61bc68c..d1c0dd9 100644 --- a/src/module.ts +++ b/src/module.ts @@ -21,6 +21,12 @@ export type { PrismicModuleOptions } from './types' declare module '@nuxt/schema' { interface PublicRuntimeConfig { + /** + * `@nuxtjs/prismic` module options. + * + * @see Module documentation: {@link https://prismic.nuxtjs.org} + * @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup} + */ prismic: PrismicModuleOptions } } diff --git a/src/runtime/plugin.client.ts b/src/runtime/plugin.client.ts index d02a393..be181c2 100644 --- a/src/runtime/plugin.client.ts +++ b/src/runtime/plugin.client.ts @@ -1,4 +1,4 @@ -import { PrismicModuleOptions } from '../types' +import type { PrismicModuleOptions } from '../types' import { defineNuxtPlugin, refreshNuxtData, useRuntimeConfig } from '#imports' export default defineNuxtPlugin((nuxtApp) => { diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index cf02890..d860ba6 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,7 +1,7 @@ import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client' import { createPrismic } from '@prismicio/vue' -import { PrismicModuleOptions } from '../types' +import type { PrismicModuleOptions } from '../types' import NuxtLink from '#app/components/nuxt-link' import { defineNuxtPlugin, useCookie, useRequestEvent, onNuxtReady, refreshNuxtData, useHead, useRuntimeConfig, useRouter } from '#imports' @@ -14,9 +14,11 @@ import richTextSerializer from '#build/prismic/proxy/richTextSerializer' export default defineNuxtPlugin((nuxtApp) => { const options: PrismicModuleOptions = useRuntimeConfig().public.prismic + const endpoint = options.environment || options.endpoint const prismicPlugin = createPrismic({ ...options, + endpoint, client, linkResolver, richTextSerializer, @@ -69,9 +71,9 @@ export default defineNuxtPlugin((nuxtApp) => { if (options.toolbar) { // Add toolbar - const repositoryName = isRepositoryEndpoint(options.endpoint) - ? getRepositoryName(options.endpoint) - : options.endpoint + const repositoryName = isRepositoryEndpoint(endpoint) + ? getRepositoryName(endpoint) + : endpoint useHead({ script: [{ diff --git a/src/types.ts b/src/types.ts index 2a4f7fd..c9359ce 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,89 @@ -import { PrismicPluginOptions } from '@prismicio/vue' +import type { PrismicPluginOptions } from '@prismicio/vue' +/** + * `@nuxtjs/prismic` module options. + * + * @see Module documentation: {@link https://prismic.nuxtjs.org} + * @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup} + */ export type PrismicModuleOptions = Omit & { + /** + * A Prismic repository endpoint to init the module's `@prismicio/client` + * instance used to fetch content from a Prismic repository with. + * + * @remarks + * Said client will be used exposed through `this.$prismic.client` and + * `usePrismic().client`. + * @example + * + * ```javascript + * // A repository ID + * "my-repo"; + * + * //A full repository endpoint + * "https://my-repo.cdn.prismic.io/api/v2"; + * ``` + * + * @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client} + */ endpoint: string; + + /** + * The Prismic environment in use by Slice Machine configured through + * environment variables. + * + * @defaultValue `endpoint` value. + * + * @internal + */ + environment?: string; + + /** + * An optional path to a file exporting a `@prismicio/client` instance used + * to fetch content from a Prismic repository to configure the module with. + * + * @remarks + * Said client will be used exposed through `this.$prismic.client` and + * `usePrismic().client`. + * @see Prismic client documentation {@link https://prismic.io/docs/technical-reference/prismicio-client} + */ client?: string; + + /** + * An optional path to a file exporting a link resolver function used to + * resolve links to Prismic documents when not using the route resolver + * parameter with `@prismicio/client`. + * + * @see Link resolver documentation {@link https://prismic.io/docs/route-resolver#link-resolver} + */ linkResolver?: string; + + /** + * An optional path to a file exporting an HTML serializer to customize + * the way rich text fields are rendered. + * + * @see HTML serializer documentation {@link https://prismic.io/docs/rich-text} + */ richTextSerializer?: string; + + /** + * Desired path of the preview page used by Prismic to enter preview + * session. + * + * @remarks + * `false` can be used to disable the preview page. + * + * @defaultValue `"/preview"` + */ preview?: string | false; + + /** + * Whether or not to inject Prismic toolbar script. + * + * @remarks + * The toolbar script is required for previews to work. + * + * @defaultValue `true` + */ toolbar?: boolean; }; From ff0e83bf68a1e1d410cd696f6d640adb6ea2ab2c Mon Sep 17 00:00:00 2001 From: lihbr Date: Tue, 24 Oct 2023 14:32:39 +0200 Subject: [PATCH 2/2] ci: pin node 20 --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a5f374..9a6d733 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node: [16, 18, 20] + node: [16, 18, 20.7] steps: - name: Set up Node @@ -41,7 +41,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - node: [16, 18, 20] + node: [16, 18, 20.7] steps: - name: Set up Node @@ -81,7 +81,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - node: [16] + node: [18] typescript: ["4.9", "5.0", "5.1"] steps: