Skip to content

Commit

Permalink
feat: support environments (#202)
Browse files Browse the repository at this point in the history
Co-authored-by: lihbr <[email protected]>
  • Loading branch information
lihbr and lihbr authored Oct 24, 2023
1 parent b8f3757 commit ec6dcc9
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16, 18, 20]
node: [16, 18, 20.7]

steps:
- name: Set up Node
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: [16]
node: [18]
typescript: ["4.9", "5.0", "5.1"]

steps:
Expand Down
1 change: 0 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default defineNuxtConfig({
path: '/'
}
]

}
}
})
6 changes: 6 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismicModuleOptions } from '../types'
import type { PrismicModuleOptions } from '../types'
import { defineNuxtPlugin, refreshNuxtData, useRuntimeConfig } from '#imports'

export default defineNuxtPlugin((nuxtApp) => {
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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,
Expand Down Expand Up @@ -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: [{
Expand Down
81 changes: 80 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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<PrismicPluginOptions, 'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer' | 'richTextSerializer'> & {
/**
* 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;
};

0 comments on commit ec6dcc9

Please sign in to comment.