Olivér Falvai
2023-12-28 68f53352e715861b155bd11baffe9f6e3032ff1e
feat: Self-hosted Plausible support (#656)

* Self-hosted Plausible support

* Remove leftover import
1 files deleted
4 files modified
31 ■■■■ changed files
package-lock.json 9 ●●●●● patch | view | raw | blame | history
package.json 1 ●●●● patch | view | raw | blame | history
quartz/cfg.ts 1 ●●●● patch | view | raw | blame | history
quartz/components/scripts/plausible.inline.ts 3 ●●●●● patch | view | raw | blame | history
quartz/plugins/emitters/componentResources.ts 17 ●●●● patch | view | raw | blame | history
package-lock.json
@@ -32,7 +32,6 @@
        "mdast-util-to-hast": "^13.0.2",
        "mdast-util-to-string": "^4.0.0",
        "micromorph": "^0.4.5",
        "plausible-tracker": "^0.3.8",
        "preact": "^10.19.3",
        "preact-render-to-string": "^6.3.1",
        "pretty-bytes": "^6.1.1",
@@ -4451,14 +4450,6 @@
        "url": "https://github.com/sponsors/jonschlinkert"
      }
    },
    "node_modules/plausible-tracker": {
      "version": "0.3.8",
      "resolved": "https://registry.npmjs.org/plausible-tracker/-/plausible-tracker-0.3.8.tgz",
      "integrity": "sha512-lmOWYQ7s9KOUJ1R+YTOR3HrjdbxIS2Z4de0P/Jx2dQPteznJl2eX3tXxKClpvbfyGP59B5bbhW8ftN59HbbFSg==",
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/preact": {
      "version": "10.19.3",
      "resolved": "https://registry.npmjs.org/preact/-/preact-10.19.3.tgz",
package.json
@@ -57,7 +57,6 @@
    "mdast-util-to-hast": "^13.0.2",
    "mdast-util-to-string": "^4.0.0",
    "micromorph": "^0.4.5",
    "plausible-tracker": "^0.3.8",
    "preact": "^10.19.3",
    "preact-render-to-string": "^6.3.1",
    "pretty-bytes": "^6.1.1",
quartz/cfg.ts
@@ -7,6 +7,7 @@
  | null
  | {
      provider: "plausible"
      host?: string
    }
  | {
      provider: "google"
quartz/components/scripts/plausible.inline.ts
File was deleted
quartz/plugins/emitters/componentResources.ts
@@ -4,8 +4,6 @@
// @ts-ignore
import spaRouterScript from "../../components/scripts/spa.inline"
// @ts-ignore
import plausibleScript from "../../components/scripts/plausible.inline"
// @ts-ignore
import popoverScript from "../../components/scripts/popover.inline"
import styles from "../../styles/custom.scss"
import popoverStyle from "../../components/styles/popover.scss"
@@ -103,7 +101,20 @@
        });
      });`)
  } else if (cfg.analytics?.provider === "plausible") {
    componentResources.afterDOMLoaded.push(plausibleScript)
    const plausibleHost = cfg.analytics.host ?? "https://plausible.io"
    componentResources.afterDOMLoaded.push(`
      const plausibleScript = document.createElement("script")
      plausibleScript.src = "${plausibleHost}/js/script.manual.js"
      plausibleScript.setAttribute("data-domain", location.hostname)
      plausibleScript.defer = true
      document.head.appendChild(plausibleScript)
      window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }
      document.addEventListener("nav", () => {
        plausible("pageview")
      })
    `)
  } else if (cfg.analytics?.provider === "umami") {
    componentResources.afterDOMLoaded.push(`
      const umamiScript = document.createElement("script")