@hollware/nuxt 0.4.0 → 0.6.0
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/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,13 @@ export interface ModuleOptions {
|
|
|
22
22
|
token?: string;
|
|
23
23
|
/** Whether pages carry `<meta name="generator" content="Hollware">`. */
|
|
24
24
|
generator: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The public URL of the Hollware that counts this site's page views (ADR-031), such as
|
|
27
|
+
* `https://cms.example.com`: each page the reader sees is sent to its `/events`, as the site and
|
|
28
|
+
* the path, with no cookie. The site's `url` in the Hollware config must be this site's origin.
|
|
29
|
+
* No views are counted when it is not set.
|
|
30
|
+
*/
|
|
31
|
+
beacon?: string;
|
|
25
32
|
}
|
|
26
33
|
export declare const name = "@hollware/nuxt";
|
|
27
34
|
/** The routes of the site that read Hollware for its pages, on the server. */
|
package/dist/index.mjs
CHANGED
|
@@ -52,6 +52,16 @@ var src_default = defineNuxtModule({
|
|
|
52
52
|
filePath: resolve("./runtime/components/HollwareContent")
|
|
53
53
|
});
|
|
54
54
|
if (options.generator) addPlugin(resolve("./runtime/generator"));
|
|
55
|
+
if (options.beacon !== void 0 && options.beacon !== "") {
|
|
56
|
+
nuxt.options.runtimeConfig.public["hollware"] = {
|
|
57
|
+
site: options.site,
|
|
58
|
+
beacon: options.beacon
|
|
59
|
+
};
|
|
60
|
+
addPlugin({
|
|
61
|
+
src: resolve("./runtime/beacon.client"),
|
|
62
|
+
mode: "client"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
55
65
|
}
|
|
56
66
|
});
|
|
57
67
|
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { sendView } from "./beacon.mjs";
|
|
2
|
+
import { defineNuxtPlugin, useRouter, useRuntimeConfig } from "nuxt/app";
|
|
3
|
+
//#region src/runtime/beacon.client.ts
|
|
4
|
+
var beacon_client_default = defineNuxtPlugin((nuxtApp) => {
|
|
5
|
+
const config = useRuntimeConfig().public["hollware"];
|
|
6
|
+
if (typeof config !== "object" || config === null) return;
|
|
7
|
+
const site = "site" in config && typeof config.site === "string" ? config.site : "";
|
|
8
|
+
const beacon = "beacon" in config && typeof config.beacon === "string" ? config.beacon : "";
|
|
9
|
+
if (site === "" || beacon === "") return;
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
nuxtApp.hook("page:finish", () => {
|
|
12
|
+
sendView((url, init) => fetch(url, init), beacon, site, router.currentRoute.value.path);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
export { beacon_client_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/runtime/beacon.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a page sends to count a view (ADR-031): the site and the path, nothing else. It goes with
|
|
4
|
+
* `fetch` and not `navigator.sendBeacon`, so that it can leave cookies out: `credentials: 'omit'`.
|
|
5
|
+
* `keepalive` lets it finish when the page is left; `no-cors` with a text body needs no preflight,
|
|
6
|
+
* and the page never reads the answer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sendView(send: (url: string, init: RequestInit) => Promise<unknown>, hollwareUrl: string, site: string, path: string): void;
|
|
9
|
+
//#endregion
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/runtime/beacon.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a page sends to count a view (ADR-031): the site and the path, nothing else. It goes with
|
|
4
|
+
* `fetch` and not `navigator.sendBeacon`, so that it can leave cookies out: `credentials: 'omit'`.
|
|
5
|
+
* `keepalive` lets it finish when the page is left; `no-cors` with a text body needs no preflight,
|
|
6
|
+
* and the page never reads the answer.
|
|
7
|
+
*/
|
|
8
|
+
function sendView(send, hollwareUrl, site, path) {
|
|
9
|
+
send(`${hollwareUrl.replace(/\/+$/, "")}/events`, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
site,
|
|
13
|
+
path
|
|
14
|
+
}),
|
|
15
|
+
headers: { "content-type": "text/plain;charset=UTF-8" },
|
|
16
|
+
credentials: "omit",
|
|
17
|
+
keepalive: true,
|
|
18
|
+
mode: "no-cors"
|
|
19
|
+
}).catch(() => {});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { sendView };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hollware/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Read Hollware from a Nuxt site, over a service binding or HTTP.",
|
|
5
5
|
"homepage": "https://hollware.com",
|
|
6
6
|
"bugs": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@comark/vue": "0.7.0",
|
|
32
|
-
"@hollware/client": "0.
|
|
32
|
+
"@hollware/client": "0.6.0",
|
|
33
33
|
"@nuxt/kit": "4.6.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|