@nuxtjs/prismic 5.2.1 → 5.3.0-canary.365b9b8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -12
- package/dist/module.d.mts +3 -3
- package/dist/module.json +3 -3
- package/dist/module.mjs +57 -3
- package/package.json +17 -18
- package/src/module.ts +176 -97
- package/src/runtime/PrismicPreview.vue +3 -3
- package/src/runtime/plugin.client.ts +6 -6
- package/src/runtime/plugin.ts +34 -34
- package/src/runtime/usePrismicPreview.ts +8 -8
package/README.md
CHANGED
|
@@ -27,18 +27,7 @@ Install the module to your Nuxt application with one command:
|
|
|
27
27
|
npx nuxi@latest module add prismic
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
import { defineNuxtConfig } from "nuxt"
|
|
34
|
-
|
|
35
|
-
export default defineNuxtConfig({
|
|
36
|
-
modules: ["@nuxtjs/prismic"],
|
|
37
|
-
prismic: {
|
|
38
|
-
endpoint: "my-repository",
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
```
|
|
30
|
+
The module automatically loads your repository name and `routes` from `prismic.config.json`, so for most projects all you need to do is register the module (done by the `module add` command). If needed, you can still override those values and configure the Nuxt module further in `nuxt.config.ts` or Nuxt's `runtimeConfig`.
|
|
42
31
|
|
|
43
32
|
That's it! You can now use Prismic in your Nuxt app ✨
|
|
44
33
|
|
package/dist/module.d.mts
CHANGED
|
@@ -82,9 +82,9 @@ type PrismicModuleOptions = {
|
|
|
82
82
|
* Controls which auto-imports are added by the module.
|
|
83
83
|
*
|
|
84
84
|
* - `"all"` will add all imports.
|
|
85
|
-
* - `
|
|
86
|
-
* - `
|
|
87
|
-
* - `
|
|
85
|
+
* - `"vue"` will add `@nuxtjs/prismic` and `@prismicio/vue` imports.
|
|
86
|
+
* - `"javascript"` will add `@prismicio/client` imports.
|
|
87
|
+
* - `"content"` will add the `Content` type import.
|
|
88
88
|
* - `false` will not add any import.
|
|
89
89
|
*
|
|
90
90
|
* @defaultValue `["vue"]`
|
package/dist/module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0-canary.365b9b8",
|
|
4
4
|
"configKey": "prismic",
|
|
5
5
|
"compatibility": {
|
|
6
6
|
"nuxt": ">=3.7.0"
|
|
7
7
|
},
|
|
8
8
|
"builder": {
|
|
9
|
-
"@nuxt/module-builder": "1.0.
|
|
10
|
-
"unbuild": "
|
|
9
|
+
"@nuxt/module-builder": "1.0.3",
|
|
10
|
+
"unbuild": "unknown"
|
|
11
11
|
}
|
|
12
12
|
}
|
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { useLogger, defineNuxtModule, createResolver, addPlugin, addComponent, addImports, extendPages, getNuxtVersion, addTemplate } from '@nuxt/kit';
|
|
@@ -7,9 +7,10 @@ import { addDependency } from 'nypm';
|
|
|
7
7
|
import { readPackage } from 'pkg-types';
|
|
8
8
|
|
|
9
9
|
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "5.
|
|
10
|
+
const version = "5.3.0-canary.365b9b8";
|
|
11
11
|
|
|
12
12
|
const logger = useLogger("nuxt:prismic");
|
|
13
|
+
const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
|
|
13
14
|
async function addPrismicClient() {
|
|
14
15
|
try {
|
|
15
16
|
const pkg = await readPackage();
|
|
@@ -73,6 +74,7 @@ const module$1 = defineNuxtModule({
|
|
|
73
74
|
nuxt.options.runtimeConfig.public?.prismic,
|
|
74
75
|
options
|
|
75
76
|
);
|
|
77
|
+
loadPrismicConfig();
|
|
76
78
|
exposeRuntimeConfig();
|
|
77
79
|
transpileDependencies();
|
|
78
80
|
const ok = proxyUserFiles();
|
|
@@ -81,6 +83,34 @@ const module$1 = defineNuxtModule({
|
|
|
81
83
|
addAutoImports();
|
|
82
84
|
addPreviewRoute();
|
|
83
85
|
extendESLintConfig();
|
|
86
|
+
function loadPrismicConfig() {
|
|
87
|
+
const prismicConfigPath = join(
|
|
88
|
+
nuxt.options.rootDir,
|
|
89
|
+
PRISMIC_CONFIG_FILENAME
|
|
90
|
+
);
|
|
91
|
+
const prismicConfig = readPrismicConfig(prismicConfigPath);
|
|
92
|
+
const configKeys = [];
|
|
93
|
+
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
94
|
+
moduleOptions.endpoint = prismicConfig.repositoryName;
|
|
95
|
+
configKeys.push("repository name");
|
|
96
|
+
}
|
|
97
|
+
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
98
|
+
moduleOptions.clientConfig.routes = prismicConfig.routes;
|
|
99
|
+
configKeys.push("routes");
|
|
100
|
+
}
|
|
101
|
+
if (configKeys.length > 0) {
|
|
102
|
+
nuxt.options.watch.push(prismicConfigPath);
|
|
103
|
+
nuxt.hook("builder:watch", async (_, path) => {
|
|
104
|
+
if (path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")) {
|
|
105
|
+
logger.info(`${PRISMIC_CONFIG_FILENAME} updated`);
|
|
106
|
+
await nuxt.callHook("restart");
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
logger.info(
|
|
110
|
+
`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
84
114
|
function exposeRuntimeConfig() {
|
|
85
115
|
nuxt.options.runtimeConfig.public ||= {};
|
|
86
116
|
nuxt.options.runtimeConfig.public.prismic = moduleOptions;
|
|
@@ -263,7 +293,9 @@ const module$1 = defineNuxtModule({
|
|
|
263
293
|
const configs = [];
|
|
264
294
|
try {
|
|
265
295
|
if (existsSync(configPath)) {
|
|
266
|
-
const config = JSON.parse(
|
|
296
|
+
const config = JSON.parse(
|
|
297
|
+
await readFile(configPath, "utf-8")
|
|
298
|
+
);
|
|
267
299
|
if (config && "libraries" in config && Array.isArray(config.libraries)) {
|
|
268
300
|
configs.push(
|
|
269
301
|
JSON.stringify({
|
|
@@ -298,5 +330,27 @@ function fileExists(path, extensions = ["js", "ts"]) {
|
|
|
298
330
|
);
|
|
299
331
|
return extension ? `${path}.${extension}` : null;
|
|
300
332
|
}
|
|
333
|
+
function readPrismicConfig(configPath) {
|
|
334
|
+
if (!existsSync(configPath)) {
|
|
335
|
+
return {};
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
const contents = readFileSync(configPath, "utf-8");
|
|
339
|
+
const rawConfig = JSON.parse(contents);
|
|
340
|
+
if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
|
|
341
|
+
return {};
|
|
342
|
+
}
|
|
343
|
+
const config = {};
|
|
344
|
+
if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
|
|
345
|
+
config.repositoryName = rawConfig.repositoryName;
|
|
346
|
+
}
|
|
347
|
+
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
348
|
+
config.routes = rawConfig.routes;
|
|
349
|
+
}
|
|
350
|
+
return config;
|
|
351
|
+
} catch {
|
|
352
|
+
return {};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
301
355
|
|
|
302
356
|
export { module$1 as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0-canary.365b9b8",
|
|
4
4
|
"description": "Easily connect your Nuxt application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -52,27 +52,26 @@
|
|
|
52
52
|
"test": "npm run lint && npm run types && npm run unit && npm run build"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nuxt/kit": "^4.
|
|
56
|
-
"@prismicio/vue": "^6.1.
|
|
55
|
+
"@nuxt/kit": "^4.5.2",
|
|
56
|
+
"@prismicio/vue": "^6.1.4",
|
|
57
57
|
"defu": "^6.1.7",
|
|
58
|
-
"nypm": "^0.6.
|
|
59
|
-
"pkg-types": "^2.3.
|
|
58
|
+
"nypm": "^0.6.9",
|
|
59
|
+
"pkg-types": "^2.3.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@nuxt/module-builder": "^1.0.
|
|
63
|
-
"@nuxt/schema": "^4.
|
|
62
|
+
"@nuxt/module-builder": "^1.0.3",
|
|
63
|
+
"@nuxt/schema": "^4.5.2",
|
|
64
64
|
"@nuxt/test-utils": "^3.23.0",
|
|
65
|
-
"@prismicio/client": "^7.
|
|
65
|
+
"@prismicio/client": "^7.22.0",
|
|
66
66
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
67
|
-
"@types/node": "^
|
|
68
|
-
"@vitest/coverage-v8": "^4.1.
|
|
69
|
-
"nuxt": "^4.
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"vue-tsc": "^3.2.6"
|
|
67
|
+
"@types/node": "^26.4.0",
|
|
68
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
69
|
+
"nuxt": "^4.5.2",
|
|
70
|
+
"oxfmt": "^0.65.0",
|
|
71
|
+
"oxlint": "^1.80.0",
|
|
72
|
+
"typescript": "^6.0.3",
|
|
73
|
+
"vitest": "^4.1.11",
|
|
74
|
+
"vue-tsc": "^3.3.11"
|
|
76
75
|
},
|
|
77
76
|
"peerDependencies": {
|
|
78
77
|
"@prismicio/client": "^7.21.8"
|
|
@@ -83,5 +82,5 @@
|
|
|
83
82
|
"publishConfig": {
|
|
84
83
|
"access": "public"
|
|
85
84
|
},
|
|
86
|
-
"packageManager": "pnpm@
|
|
85
|
+
"packageManager": "pnpm@11.24.0"
|
|
87
86
|
}
|
package/src/module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { existsSync } from "node:fs"
|
|
2
|
-
import { readFile } from "node:fs/promises"
|
|
3
|
-
import { join } from "node:path"
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
addComponent,
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
extendPages,
|
|
13
13
|
getNuxtVersion,
|
|
14
14
|
useLogger,
|
|
15
|
-
} from "@nuxt/kit"
|
|
16
|
-
import type { ClientConfig } from "@prismicio/client"
|
|
17
|
-
import { defu } from "defu"
|
|
18
|
-
import { addDependency } from "nypm"
|
|
19
|
-
import { readPackage } from "pkg-types"
|
|
15
|
+
} from "@nuxt/kit";
|
|
16
|
+
import type { ClientConfig, Route } from "@prismicio/client";
|
|
17
|
+
import { defu } from "defu";
|
|
18
|
+
import { addDependency } from "nypm";
|
|
19
|
+
import { readPackage } from "pkg-types";
|
|
20
20
|
|
|
21
|
-
import { name, version } from "../package.json"
|
|
21
|
+
import { name, version } from "../package.json";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Prismic Nuxt module options.
|
|
@@ -44,7 +44,7 @@ export type PrismicModuleOptions = {
|
|
|
44
44
|
*
|
|
45
45
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
46
46
|
*/
|
|
47
|
-
endpoint?: string
|
|
47
|
+
endpoint?: string;
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* The Prismic environment in use by Slice Machine configured through
|
|
@@ -54,7 +54,7 @@ export type PrismicModuleOptions = {
|
|
|
54
54
|
*
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
|
-
environment?: string
|
|
57
|
+
environment?: string;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Configuration options that determines how content will be queries from the
|
|
@@ -62,7 +62,7 @@ export type PrismicModuleOptions = {
|
|
|
62
62
|
*
|
|
63
63
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
64
64
|
*/
|
|
65
|
-
clientConfig?: ClientConfig
|
|
65
|
+
clientConfig?: ClientConfig;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* An optional path to a file exporting a Prismic client instance used to
|
|
@@ -74,7 +74,7 @@ export type PrismicModuleOptions = {
|
|
|
74
74
|
*
|
|
75
75
|
* @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
|
|
76
76
|
*/
|
|
77
|
-
client?: string
|
|
77
|
+
client?: string;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* The path to a file exporting a default link resolver used to resolve links
|
|
@@ -82,7 +82,7 @@ export type PrismicModuleOptions = {
|
|
|
82
82
|
*
|
|
83
83
|
* @see {@link https://prismic.io/docs/routes}
|
|
84
84
|
*/
|
|
85
|
-
linkResolver?: string
|
|
85
|
+
linkResolver?: string;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Desired path of the preview page used by Prismic to enter preview session.
|
|
@@ -92,7 +92,7 @@ export type PrismicModuleOptions = {
|
|
|
92
92
|
*
|
|
93
93
|
* @defaultValue `"/preview"`
|
|
94
94
|
*/
|
|
95
|
-
preview?: string | false
|
|
95
|
+
preview?: string | false;
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* Whether to inject Prismic toolbar script.
|
|
@@ -102,22 +102,22 @@ export type PrismicModuleOptions = {
|
|
|
102
102
|
*
|
|
103
103
|
* @defaultValue `true`
|
|
104
104
|
*/
|
|
105
|
-
toolbar?: boolean
|
|
105
|
+
toolbar?: boolean;
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Controls which auto-imports are added by the module.
|
|
109
109
|
*
|
|
110
110
|
* - `"all"` will add all imports.
|
|
111
|
-
* - `
|
|
112
|
-
* - `
|
|
113
|
-
* - `
|
|
111
|
+
* - `"vue"` will add `@nuxtjs/prismic` and `@prismicio/vue` imports.
|
|
112
|
+
* - `"javascript"` will add `@prismicio/client` imports.
|
|
113
|
+
* - `"content"` will add the `Content` type import.
|
|
114
114
|
* - `false` will not add any import.
|
|
115
115
|
*
|
|
116
116
|
* @defaultValue `["vue"]`
|
|
117
117
|
*
|
|
118
118
|
* @experimental
|
|
119
119
|
*/
|
|
120
|
-
imports?: false | "all" | ("vue" | "javascript" | "content")[]
|
|
120
|
+
imports?: false | "all" | ("vue" | "javascript" | "content")[];
|
|
121
121
|
|
|
122
122
|
/** Options used by Prismic Vue components. */
|
|
123
123
|
components?: {
|
|
@@ -128,9 +128,9 @@ export type PrismicModuleOptions = {
|
|
|
128
128
|
* @see {@link https://prismic.io/docs/fields/rich-text}
|
|
129
129
|
* @see {@link https://prismic.io/docs/fields/table}
|
|
130
130
|
*/
|
|
131
|
-
richTextComponents?: string
|
|
132
|
-
}
|
|
133
|
-
}
|
|
131
|
+
richTextComponents?: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Prismic Nuxt module options.
|
|
@@ -138,27 +138,28 @@ export type PrismicModuleOptions = {
|
|
|
138
138
|
* @see {@link https://prismic.io/docs/nuxt}
|
|
139
139
|
* @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
|
|
140
140
|
*/
|
|
141
|
-
export type ModuleOptions = PrismicModuleOptions
|
|
141
|
+
export type ModuleOptions = PrismicModuleOptions;
|
|
142
142
|
|
|
143
143
|
declare module "@nuxt/schema" {
|
|
144
144
|
interface PublicRuntimeConfig {
|
|
145
145
|
/** The Prismic Nuxt module options. */
|
|
146
|
-
prismic: PrismicModuleOptions
|
|
146
|
+
prismic: PrismicModuleOptions;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
const logger = useLogger("nuxt:prismic")
|
|
150
|
+
const logger = useLogger("nuxt:prismic");
|
|
151
|
+
const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
|
|
151
152
|
|
|
152
153
|
async function addPrismicClient() {
|
|
153
154
|
try {
|
|
154
|
-
const pkg = await readPackage()
|
|
155
|
+
const pkg = await readPackage();
|
|
155
156
|
|
|
156
157
|
if (
|
|
157
158
|
!pkg.dependencies?.["@prismicio/client"] &&
|
|
158
159
|
!pkg.devDependencies?.["@prismicio/client"]
|
|
159
160
|
) {
|
|
160
|
-
await addDependency("@prismicio/client")
|
|
161
|
-
logger.info("Added `@prismicio/client` required peer dependency")
|
|
161
|
+
await addDependency("@prismicio/client");
|
|
162
|
+
logger.info("Added `@prismicio/client` required peer dependency");
|
|
162
163
|
}
|
|
163
164
|
} catch {
|
|
164
165
|
// noop
|
|
@@ -173,18 +174,18 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
173
174
|
compatibility: { nuxt: ">=3.7.0" },
|
|
174
175
|
},
|
|
175
176
|
onInstall() {
|
|
176
|
-
return addPrismicClient()
|
|
177
|
+
return addPrismicClient();
|
|
177
178
|
},
|
|
178
179
|
onUpgrade(_options: unknown, _nuxt: unknown, previousVersion: string) {
|
|
179
|
-
const previousMajor = parseInt(previousVersion.split(".")[0]!)
|
|
180
|
+
const previousMajor = parseInt(previousVersion.split(".")[0]!);
|
|
180
181
|
if (previousMajor < 4) {
|
|
181
|
-
return addPrismicClient()
|
|
182
|
+
return addPrismicClient();
|
|
182
183
|
}
|
|
183
184
|
},
|
|
184
185
|
defaults: (nuxt): Required<PrismicModuleOptions> => {
|
|
185
186
|
const nuxt3flavor =
|
|
186
187
|
getNuxtVersion(nuxt).startsWith("3") &&
|
|
187
|
-
!nuxt.options?.future?.compatibilityVersion
|
|
188
|
+
!nuxt.options?.future?.compatibilityVersion;
|
|
188
189
|
|
|
189
190
|
if (nuxt3flavor) {
|
|
190
191
|
return {
|
|
@@ -199,7 +200,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
199
200
|
components: {
|
|
200
201
|
richTextComponents: "~/app/prismic/richTextComponents ",
|
|
201
202
|
},
|
|
202
|
-
}
|
|
203
|
+
};
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
return {
|
|
@@ -214,29 +215,65 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
214
215
|
components: {
|
|
215
216
|
richTextComponents: "~/prismic/richTextComponents",
|
|
216
217
|
},
|
|
217
|
-
}
|
|
218
|
+
};
|
|
218
219
|
},
|
|
219
220
|
setup(options, nuxt) {
|
|
220
|
-
const resolver = createResolver(import.meta.url)
|
|
221
|
+
const resolver = createResolver(import.meta.url);
|
|
221
222
|
|
|
222
223
|
const moduleOptions: PrismicModuleOptions = defu(
|
|
223
|
-
nuxt.options.runtimeConfig.public?.prismic,
|
|
224
|
+
nuxt.options.runtimeConfig.public?.prismic as PrismicModuleOptions,
|
|
224
225
|
options,
|
|
225
|
-
)
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
loadPrismicConfig();
|
|
229
|
+
exposeRuntimeConfig();
|
|
230
|
+
transpileDependencies();
|
|
231
|
+
const ok = proxyUserFiles();
|
|
232
|
+
if (!ok) return;
|
|
233
|
+
addRuntimePlugins();
|
|
234
|
+
addAutoImports();
|
|
235
|
+
addPreviewRoute();
|
|
236
|
+
extendESLintConfig();
|
|
237
|
+
|
|
238
|
+
function loadPrismicConfig() {
|
|
239
|
+
const prismicConfigPath = join(
|
|
240
|
+
nuxt.options.rootDir,
|
|
241
|
+
PRISMIC_CONFIG_FILENAME,
|
|
242
|
+
);
|
|
243
|
+
const prismicConfig = readPrismicConfig(prismicConfigPath);
|
|
244
|
+
|
|
245
|
+
const configKeys: string[] = [];
|
|
246
|
+
if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
|
|
247
|
+
moduleOptions.endpoint = prismicConfig.repositoryName;
|
|
248
|
+
configKeys.push("repository name");
|
|
249
|
+
}
|
|
250
|
+
if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
|
|
251
|
+
moduleOptions.clientConfig!.routes = prismicConfig.routes;
|
|
252
|
+
configKeys.push("routes");
|
|
253
|
+
}
|
|
226
254
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
255
|
+
if (configKeys.length > 0) {
|
|
256
|
+
nuxt.options.watch.push(prismicConfigPath);
|
|
257
|
+
nuxt.hook("builder:watch", async (_, path) => {
|
|
258
|
+
if (
|
|
259
|
+
path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")
|
|
260
|
+
) {
|
|
261
|
+
logger.info(`${PRISMIC_CONFIG_FILENAME} updated`);
|
|
262
|
+
await nuxt.callHook("restart");
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
logger.info(
|
|
267
|
+
`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
235
271
|
|
|
236
272
|
function exposeRuntimeConfig() {
|
|
237
273
|
nuxt.options.runtimeConfig.public ||=
|
|
238
|
-
{} as typeof nuxt.options.runtimeConfig.public
|
|
239
|
-
nuxt.options.runtimeConfig.public.prismic =
|
|
274
|
+
{} as typeof nuxt.options.runtimeConfig.public;
|
|
275
|
+
(nuxt.options.runtimeConfig.public.prismic as PrismicModuleOptions) =
|
|
276
|
+
moduleOptions;
|
|
240
277
|
}
|
|
241
278
|
|
|
242
279
|
function transpileDependencies() {
|
|
@@ -244,10 +281,10 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
244
281
|
resolver.resolve("runtime"),
|
|
245
282
|
"@nuxtjs/prismic",
|
|
246
283
|
"@prismicio/vue",
|
|
247
|
-
)
|
|
248
|
-
nuxt.options.vite.optimizeDeps ||= {}
|
|
249
|
-
nuxt.options.vite.optimizeDeps.exclude ||= []
|
|
250
|
-
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue")
|
|
284
|
+
);
|
|
285
|
+
nuxt.options.vite.optimizeDeps ||= {};
|
|
286
|
+
nuxt.options.vite.optimizeDeps.exclude ||= [];
|
|
287
|
+
nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue");
|
|
251
288
|
}
|
|
252
289
|
|
|
253
290
|
function proxyUserFiles() {
|
|
@@ -255,44 +292,44 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
255
292
|
filename: string,
|
|
256
293
|
path: string,
|
|
257
294
|
): boolean => {
|
|
258
|
-
const resolvedFilename = `prismic/proxy/${filename}.ts
|
|
295
|
+
const resolvedFilename = `prismic/proxy/${filename}.ts`;
|
|
259
296
|
const resolvedPath = path
|
|
260
297
|
.replace(/^(~~|@@)/, nuxt.options.rootDir)
|
|
261
|
-
.replace(/^(~|@)/, nuxt.options.srcDir)
|
|
298
|
+
.replace(/^(~|@)/, nuxt.options.srcDir);
|
|
262
299
|
const maybeUserFile = fileExists(resolvedPath, [
|
|
263
300
|
"js",
|
|
264
301
|
"mjs",
|
|
265
302
|
"ts",
|
|
266
303
|
"vue",
|
|
267
|
-
])
|
|
304
|
+
]);
|
|
268
305
|
|
|
269
306
|
if (maybeUserFile) {
|
|
270
307
|
// If user file exists, proxy it with vfs
|
|
271
308
|
logger.info(
|
|
272
309
|
`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``,
|
|
273
|
-
)
|
|
310
|
+
);
|
|
274
311
|
|
|
275
312
|
addTemplate({
|
|
276
313
|
filename: resolvedFilename,
|
|
277
314
|
getContents: () => `export { default } from '${path}'`,
|
|
278
|
-
})
|
|
315
|
+
});
|
|
279
316
|
|
|
280
|
-
return true
|
|
317
|
+
return true;
|
|
281
318
|
} else {
|
|
282
319
|
// Else provide `undefined` fallback
|
|
283
320
|
addTemplate({
|
|
284
321
|
filename: resolvedFilename,
|
|
285
322
|
getContents: () => "export default undefined",
|
|
286
|
-
})
|
|
323
|
+
});
|
|
287
324
|
|
|
288
|
-
return false
|
|
325
|
+
return false;
|
|
289
326
|
}
|
|
290
|
-
}
|
|
327
|
+
};
|
|
291
328
|
|
|
292
329
|
const proxiedUserClient = proxyUserFileWithUndefinedFallback(
|
|
293
330
|
"client",
|
|
294
331
|
moduleOptions.client!,
|
|
295
|
-
)
|
|
332
|
+
);
|
|
296
333
|
if (
|
|
297
334
|
!moduleOptions.endpoint &&
|
|
298
335
|
!proxiedUserClient &&
|
|
@@ -300,34 +337,34 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
300
337
|
) {
|
|
301
338
|
logger.warn(
|
|
302
339
|
`\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`,
|
|
303
|
-
)
|
|
304
|
-
return false
|
|
340
|
+
);
|
|
341
|
+
return false;
|
|
305
342
|
}
|
|
306
343
|
proxyUserFileWithUndefinedFallback(
|
|
307
344
|
"linkResolver",
|
|
308
345
|
moduleOptions.linkResolver!,
|
|
309
|
-
)
|
|
346
|
+
);
|
|
310
347
|
proxyUserFileWithUndefinedFallback(
|
|
311
348
|
"richTextComponents",
|
|
312
349
|
moduleOptions.components!.richTextComponents!,
|
|
313
|
-
)
|
|
350
|
+
);
|
|
314
351
|
|
|
315
|
-
return true
|
|
352
|
+
return true;
|
|
316
353
|
}
|
|
317
354
|
|
|
318
355
|
function addRuntimePlugins() {
|
|
319
|
-
addPlugin(resolver.resolve("runtime/plugin"))
|
|
320
|
-
addPlugin(resolver.resolve("runtime/plugin.client"))
|
|
356
|
+
addPlugin(resolver.resolve("runtime/plugin"));
|
|
357
|
+
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
321
358
|
}
|
|
322
359
|
|
|
323
360
|
function addAutoImports() {
|
|
324
|
-
if (!moduleOptions.imports) return
|
|
361
|
+
if (!moduleOptions.imports) return;
|
|
325
362
|
|
|
326
363
|
if (
|
|
327
364
|
moduleOptions.imports === "all" ||
|
|
328
365
|
moduleOptions.imports.includes("vue")
|
|
329
366
|
) {
|
|
330
|
-
|
|
367
|
+
[
|
|
331
368
|
"PrismicImage",
|
|
332
369
|
"PrismicLink",
|
|
333
370
|
"PrismicText",
|
|
@@ -340,8 +377,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
340
377
|
name: entry,
|
|
341
378
|
export: entry,
|
|
342
379
|
filePath: "@prismicio/vue",
|
|
343
|
-
})
|
|
344
|
-
})
|
|
380
|
+
});
|
|
381
|
+
});
|
|
345
382
|
|
|
346
383
|
addImports(
|
|
347
384
|
[
|
|
@@ -355,12 +392,12 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
355
392
|
as: entry,
|
|
356
393
|
from: "@prismicio/vue",
|
|
357
394
|
})),
|
|
358
|
-
)
|
|
395
|
+
);
|
|
359
396
|
addImports({
|
|
360
397
|
name: "usePrismicPreview",
|
|
361
398
|
as: "usePrismicPreview",
|
|
362
399
|
from: resolver.resolve("runtime/usePrismicPreview"),
|
|
363
|
-
})
|
|
400
|
+
});
|
|
364
401
|
}
|
|
365
402
|
|
|
366
403
|
if (
|
|
@@ -383,7 +420,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
383
420
|
as: entry,
|
|
384
421
|
from: "@prismicio/client",
|
|
385
422
|
})),
|
|
386
|
-
)
|
|
423
|
+
);
|
|
387
424
|
}
|
|
388
425
|
|
|
389
426
|
if (
|
|
@@ -395,7 +432,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
395
432
|
from: "@prismicio/client",
|
|
396
433
|
typeFrom: "@prismicio/client",
|
|
397
434
|
type: true,
|
|
398
|
-
})
|
|
435
|
+
});
|
|
399
436
|
}
|
|
400
437
|
}
|
|
401
438
|
|
|
@@ -408,7 +445,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
408
445
|
moduleOptions.preview,
|
|
409
446
|
),
|
|
410
447
|
["js", "ts", "vue"],
|
|
411
|
-
)
|
|
448
|
+
);
|
|
412
449
|
|
|
413
450
|
if (maybeUserPreviewPage) {
|
|
414
451
|
logger.info(
|
|
@@ -419,25 +456,25 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
419
456
|
/\\/g,
|
|
420
457
|
"/",
|
|
421
458
|
)}\`, available at \`${moduleOptions.preview}\``,
|
|
422
|
-
)
|
|
459
|
+
);
|
|
423
460
|
} else {
|
|
424
461
|
logger.info(
|
|
425
462
|
`Using default preview page, available at \`${moduleOptions.preview}\``,
|
|
426
|
-
)
|
|
463
|
+
);
|
|
427
464
|
|
|
428
465
|
extendPages((pages) => {
|
|
429
466
|
pages.unshift({
|
|
430
467
|
name: "prismic-preview",
|
|
431
468
|
path: moduleOptions.preview as string, // Checked before
|
|
432
469
|
file: resolver.resolve("runtime/PrismicPreview.vue"),
|
|
433
|
-
})
|
|
434
|
-
})
|
|
470
|
+
});
|
|
471
|
+
});
|
|
435
472
|
}
|
|
436
473
|
|
|
437
474
|
if (!moduleOptions.toolbar) {
|
|
438
475
|
logger.warn(
|
|
439
476
|
"`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.",
|
|
440
|
-
)
|
|
477
|
+
);
|
|
441
478
|
}
|
|
442
479
|
}
|
|
443
480
|
}
|
|
@@ -448,8 +485,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
448
485
|
"eslint:config:addons",
|
|
449
486
|
(
|
|
450
487
|
addons: {
|
|
451
|
-
name: string
|
|
452
|
-
getConfigs: () => Promise<{ configs: string[] }
|
|
488
|
+
name: string;
|
|
489
|
+
getConfigs: () => Promise<{ configs: string[] }>;
|
|
453
490
|
}[],
|
|
454
491
|
) => {
|
|
455
492
|
addons.push({
|
|
@@ -458,13 +495,15 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
458
495
|
const configPath = resolver.resolve(
|
|
459
496
|
nuxt.options.rootDir,
|
|
460
497
|
"slicemachine.config.json",
|
|
461
|
-
)
|
|
498
|
+
);
|
|
462
499
|
|
|
463
|
-
const configs: string[] = []
|
|
500
|
+
const configs: string[] = [];
|
|
464
501
|
|
|
465
502
|
try {
|
|
466
503
|
if (existsSync(configPath)) {
|
|
467
|
-
const config = JSON.parse(
|
|
504
|
+
const config = JSON.parse(
|
|
505
|
+
await readFile(configPath, "utf-8"),
|
|
506
|
+
);
|
|
468
507
|
|
|
469
508
|
if (
|
|
470
509
|
config &&
|
|
@@ -481,32 +520,72 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
481
520
|
"vue/multi-word-component-names": "off",
|
|
482
521
|
},
|
|
483
522
|
}),
|
|
484
|
-
)
|
|
523
|
+
);
|
|
485
524
|
}
|
|
486
525
|
}
|
|
487
526
|
} catch {
|
|
488
527
|
// noop
|
|
489
528
|
}
|
|
490
529
|
|
|
491
|
-
return { configs }
|
|
530
|
+
return { configs };
|
|
492
531
|
},
|
|
493
|
-
})
|
|
532
|
+
});
|
|
494
533
|
},
|
|
495
|
-
)
|
|
534
|
+
);
|
|
496
535
|
}
|
|
497
536
|
},
|
|
498
|
-
})
|
|
537
|
+
});
|
|
499
538
|
|
|
500
539
|
function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
|
|
501
540
|
if (!path) {
|
|
502
|
-
return null
|
|
541
|
+
return null;
|
|
503
542
|
} else if (existsSync(path)) {
|
|
504
|
-
return path
|
|
543
|
+
return path;
|
|
505
544
|
}
|
|
506
545
|
|
|
507
546
|
const extension = extensions.find((extension) =>
|
|
508
547
|
existsSync(`${path}.${extension}`),
|
|
509
|
-
)
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
return extension ? `${path}.${extension}` : null;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
type PrismicConfig = {
|
|
554
|
+
repositoryName?: string;
|
|
555
|
+
routes?: Route[];
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
function readPrismicConfig(configPath: string): PrismicConfig {
|
|
559
|
+
if (!existsSync(configPath)) {
|
|
560
|
+
return {};
|
|
561
|
+
}
|
|
510
562
|
|
|
511
|
-
|
|
563
|
+
try {
|
|
564
|
+
const contents = readFileSync(configPath, "utf-8");
|
|
565
|
+
const rawConfig = JSON.parse(contents) as unknown;
|
|
566
|
+
|
|
567
|
+
if (
|
|
568
|
+
!rawConfig ||
|
|
569
|
+
typeof rawConfig !== "object" ||
|
|
570
|
+
Array.isArray(rawConfig)
|
|
571
|
+
) {
|
|
572
|
+
return {};
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const config: PrismicConfig = {};
|
|
576
|
+
if (
|
|
577
|
+
"repositoryName" in rawConfig &&
|
|
578
|
+
typeof rawConfig.repositoryName === "string"
|
|
579
|
+
) {
|
|
580
|
+
config.repositoryName = rawConfig.repositoryName;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
|
|
584
|
+
config.routes = rawConfig.routes;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
return config;
|
|
588
|
+
} catch {
|
|
589
|
+
return {};
|
|
590
|
+
}
|
|
512
591
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { usePrismicPreview, useSeoMeta } from "#imports"
|
|
2
|
+
import { usePrismicPreview, useSeoMeta } from "#imports";
|
|
3
3
|
|
|
4
|
-
useSeoMeta({ title: "Prismic Preview - Loading" })
|
|
5
|
-
usePrismicPreview()
|
|
4
|
+
useSeoMeta({ title: "Prismic Preview - Loading" });
|
|
5
|
+
usePrismicPreview();
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from "#app"
|
|
2
|
-
import { refreshNuxtData, useRuntimeConfig } from "#imports"
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import { refreshNuxtData, useRuntimeConfig } from "#imports";
|
|
3
3
|
|
|
4
4
|
export default defineNuxtPlugin({
|
|
5
5
|
name: "prismic:plugin:client",
|
|
@@ -7,9 +7,9 @@ export default defineNuxtPlugin({
|
|
|
7
7
|
setup() {
|
|
8
8
|
if (useRuntimeConfig().public.prismic?.preview) {
|
|
9
9
|
window.addEventListener("prismicPreviewUpdate", (event) => {
|
|
10
|
-
event.preventDefault()
|
|
11
|
-
refreshNuxtData()
|
|
12
|
-
})
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
refreshNuxtData();
|
|
12
|
+
});
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
})
|
|
15
|
+
});
|
package/src/runtime/plugin.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from "#app"
|
|
2
|
-
import NuxtLink from "#app/components/nuxt-link"
|
|
3
|
-
import _client from "#build/prismic/proxy/client"
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import NuxtLink from "#app/components/nuxt-link";
|
|
3
|
+
import _client from "#build/prismic/proxy/client";
|
|
4
4
|
// @ts-expect-error - Proxy file
|
|
5
|
-
import linkResolver from "#build/prismic/proxy/linkResolver"
|
|
5
|
+
import linkResolver from "#build/prismic/proxy/linkResolver";
|
|
6
6
|
// @ts-expect-error - Proxy file
|
|
7
|
-
import richTextComponents from "#build/prismic/proxy/richTextComponents"
|
|
7
|
+
import richTextComponents from "#build/prismic/proxy/richTextComponents";
|
|
8
8
|
import {
|
|
9
9
|
onNuxtReady,
|
|
10
10
|
refreshNuxtData,
|
|
@@ -13,57 +13,57 @@ import {
|
|
|
13
13
|
useRequestEvent,
|
|
14
14
|
useRouter,
|
|
15
15
|
useRuntimeConfig,
|
|
16
|
-
} from "#imports"
|
|
17
|
-
import { Client, cookie, createClient, getToolbarSrc } from "@prismicio/client"
|
|
18
|
-
import { createPrismic } from "@prismicio/vue"
|
|
16
|
+
} from "#imports";
|
|
17
|
+
import { Client, cookie, createClient, getToolbarSrc } from "@prismicio/client";
|
|
18
|
+
import { createPrismic } from "@prismicio/vue";
|
|
19
19
|
|
|
20
20
|
export default defineNuxtPlugin({
|
|
21
21
|
name: "prismic:setup",
|
|
22
22
|
parallel: true,
|
|
23
23
|
async setup(nuxtApp) {
|
|
24
|
-
const options = useRuntimeConfig().public.prismic
|
|
24
|
+
const options = useRuntimeConfig().public.prismic;
|
|
25
25
|
|
|
26
|
-
const client = await resolveClient()
|
|
27
|
-
handlePreview()
|
|
28
|
-
addToolbar()
|
|
26
|
+
const client = await resolveClient();
|
|
27
|
+
handlePreview();
|
|
28
|
+
addToolbar();
|
|
29
29
|
|
|
30
30
|
async function resolveClient() {
|
|
31
31
|
if ((_client as unknown) instanceof Client) {
|
|
32
|
-
return _client
|
|
32
|
+
return _client!;
|
|
33
33
|
} else if (typeof _client === "function") {
|
|
34
34
|
try {
|
|
35
35
|
return await nuxtApp.runWithContext(() =>
|
|
36
36
|
(_client as unknown as () => Client)(),
|
|
37
|
-
)
|
|
37
|
+
);
|
|
38
38
|
} catch (error) {
|
|
39
39
|
console.error(
|
|
40
40
|
"[@nuxtjs/prismic] An error happened while resolving your Prismic custom client, disabling Prismic module gracefully...",
|
|
41
41
|
error,
|
|
42
|
-
)
|
|
42
|
+
);
|
|
43
43
|
|
|
44
44
|
// The Vue plugin still requires a client to work, we're providing an obviously broken one.
|
|
45
45
|
return createClient(
|
|
46
46
|
"error-resolving-custom-client",
|
|
47
47
|
options.clientConfig,
|
|
48
|
-
)
|
|
48
|
+
);
|
|
49
49
|
}
|
|
50
50
|
} else {
|
|
51
51
|
return createClient(
|
|
52
52
|
options.environment || options.endpoint || "endpoint-not-provided",
|
|
53
53
|
options.clientConfig,
|
|
54
|
-
)
|
|
54
|
+
);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function handlePreview() {
|
|
59
59
|
if (options.preview) {
|
|
60
|
-
const previewCookie = useCookie("io.prismic.preview").value
|
|
60
|
+
const previewCookie = useCookie("io.prismic.preview").value;
|
|
61
61
|
|
|
62
62
|
// Update client with req when running server side
|
|
63
63
|
if (import.meta.server) {
|
|
64
|
-
const req = useRequestEvent()?.node.req
|
|
64
|
+
const req = useRequestEvent()?.node.req;
|
|
65
65
|
if (req) {
|
|
66
|
-
client.enableAutoPreviewsFromReq(req)
|
|
66
|
+
client.enableAutoPreviewsFromReq(req);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@ export default defineNuxtPlugin({
|
|
|
72
72
|
const session =
|
|
73
73
|
typeof previewCookie === "string"
|
|
74
74
|
? JSON.parse(decodeURIComponent(previewCookie))
|
|
75
|
-
: previewCookie
|
|
75
|
+
: previewCookie;
|
|
76
76
|
|
|
77
77
|
if (
|
|
78
78
|
Object.keys(session).some(
|
|
@@ -84,19 +84,19 @@ export default defineNuxtPlugin({
|
|
|
84
84
|
session[key].preview,
|
|
85
85
|
)
|
|
86
86
|
) {
|
|
87
|
-
let afterEachCalled = false
|
|
87
|
+
let afterEachCalled = false;
|
|
88
88
|
onNuxtReady(() => {
|
|
89
89
|
if (!afterEachCalled) {
|
|
90
|
-
refreshNuxtData()
|
|
90
|
+
refreshNuxtData();
|
|
91
91
|
}
|
|
92
|
-
})
|
|
92
|
+
});
|
|
93
93
|
useRouter().afterEach(() => {
|
|
94
|
-
afterEachCalled = true
|
|
95
|
-
refreshNuxtData()
|
|
96
|
-
})
|
|
94
|
+
afterEachCalled = true;
|
|
95
|
+
refreshNuxtData();
|
|
96
|
+
});
|
|
97
97
|
}
|
|
98
98
|
} catch (error) {
|
|
99
|
-
console.warn("Failed to parse Prismic preview cookie", error)
|
|
99
|
+
console.warn("Failed to parse Prismic preview cookie", error);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -115,10 +115,10 @@ export default defineNuxtPlugin({
|
|
|
115
115
|
crossorigin: "anonymous",
|
|
116
116
|
},
|
|
117
117
|
],
|
|
118
|
-
})
|
|
118
|
+
});
|
|
119
119
|
} else {
|
|
120
120
|
// TODO: We might want to let user disable this behavior because it might have unexpected side effects
|
|
121
|
-
useCookie(cookie.preview).value = null
|
|
121
|
+
useCookie(cookie.preview).value = null;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -130,11 +130,11 @@ export default defineNuxtPlugin({
|
|
|
130
130
|
linkExternalComponent: NuxtLink,
|
|
131
131
|
richTextComponents,
|
|
132
132
|
},
|
|
133
|
-
})
|
|
133
|
+
});
|
|
134
134
|
|
|
135
|
-
nuxtApp.vueApp.use(prismicPlugin)
|
|
135
|
+
nuxtApp.vueApp.use(prismicPlugin);
|
|
136
136
|
return {
|
|
137
137
|
provide: { prismic: prismicPlugin },
|
|
138
|
-
}
|
|
138
|
+
};
|
|
139
139
|
},
|
|
140
|
-
})
|
|
140
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// @ts-expect-error - Proxy file
|
|
2
|
-
import { usePrismic, useRouter } from "#imports"
|
|
3
|
-
import { onMounted } from "vue"
|
|
2
|
+
import { usePrismic, useRouter } from "#imports";
|
|
3
|
+
import { onMounted } from "vue";
|
|
4
4
|
|
|
5
5
|
/** Resolves Prismic previews on the preview entry page (`/preview`) */
|
|
6
6
|
export const usePrismicPreview = (defaultURL = "/"): void => {
|
|
7
|
-
const { client, linkResolver } = usePrismic()
|
|
8
|
-
const { push } = useRouter()
|
|
7
|
+
const { client, linkResolver } = usePrismic();
|
|
8
|
+
const { push } = useRouter();
|
|
9
9
|
onMounted(async () => {
|
|
10
10
|
const redirectURL = await client.resolvePreviewURL({
|
|
11
11
|
linkResolver,
|
|
12
12
|
defaultURL,
|
|
13
|
-
})
|
|
13
|
+
});
|
|
14
14
|
|
|
15
|
-
push(redirectURL)
|
|
16
|
-
})
|
|
17
|
-
}
|
|
15
|
+
push(redirectURL);
|
|
16
|
+
});
|
|
17
|
+
};
|