@eox/pages-theme-esa 0.8.0 → 0.8.2

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 CHANGED
@@ -18,7 +18,6 @@ export default {
18
18
 
19
19
  See also the [Vitepress Docs](https://vitepress.dev/guide/custom-theme#consuming-a-custom-theme).
20
20
 
21
-
22
21
  ### Feedback Form
23
22
 
24
23
  **Feedback Form** for collecting user feedback can be enabled by configuring the theme:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/pages-theme-esa",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "type": "module",
5
5
  "description": "Vitepress Theme with ESA branding",
6
6
  "main": "src/index.js",
package/src/Layout.vue CHANGED
@@ -2,7 +2,12 @@
2
2
  import { onMounted, watch } from "vue";
3
3
  import { useData, useRouter, withBase } from "vitepress";
4
4
  import DefaultTheme from "vitepress/theme";
5
- import { applyShadowDomEventListener } from "./helpers";
5
+ import {
6
+ applyShadowDomEventListener,
7
+ normalizeTrackingUrl,
8
+ trackEvent,
9
+ trackPageView,
10
+ } from "./helpers";
6
11
 
7
12
  const { Layout } = DefaultTheme;
8
13
  const { site, theme, frontmatter } = useData();
@@ -43,10 +48,19 @@ onMounted(async () => {
43
48
  100: false,
44
49
  };
45
50
  document.addEventListener("scroll", (e) => {
51
+ const currentPath = normalizeTrackingUrl(router.route.path);
46
52
  Object.keys(scrollTargets).forEach((target) => {
47
- if (getScrollPercent() >= parseInt(target) && !scrollTargets[target]) {
53
+ if (
54
+ getScrollPercent() >= parseInt(target, 10) &&
55
+ !scrollTargets[target]
56
+ ) {
48
57
  scrollTargets[target] = true;
49
- _paq.push(["trackEvent", "Scroll_depth", `${target}%`]);
58
+ trackEvent([
59
+ "Interaction",
60
+ "Scroll Depth",
61
+ currentPath,
62
+ parseInt(target, 10),
63
+ ]);
50
64
  }
51
65
  });
52
66
  });
@@ -56,8 +70,11 @@ onMounted(async () => {
56
70
  const routerEventHandler = (event, anchor) => {
57
71
  const href = anchor.getAttribute("href");
58
72
  const target = anchor.getAttribute("target");
73
+ if (!href) return;
59
74
  if (href.startsWith("http") || target === "_blank") {
60
75
  window.open(href, target).focus();
76
+ } else if (href.startsWith("mailto:") || href.startsWith("tel:")) {
77
+ window.location.href = href;
61
78
  } else {
62
79
  router.go(!href.startsWith(site.value.base) ? withBase(href) : href);
63
80
  }
@@ -67,10 +84,10 @@ onMounted(async () => {
67
84
  () => router.route.data.relativePath,
68
85
  () => {
69
86
  if (!window._paq) return;
70
- _paq.push(["setCustomUrl", router.route.path]);
71
- _paq.push(["setDocumentTitle", router.route.data.title]);
72
- _paq.push(["trackPageView"]);
73
- _paq.push(["enableLinkTracking"]);
87
+ trackPageView({
88
+ path: router.route.path,
89
+ title: router.route.data.title,
90
+ });
74
91
  },
75
92
  { immediate: true },
76
93
  );
@@ -106,7 +123,7 @@ onMounted(async () => {
106
123
  ></esa-menu>
107
124
  <esa-header></esa-header>
108
125
  <esa-navbar
109
- :brand-logo="theme.logo? withBase(theme.logo) : undefined"
126
+ :brand-logo="theme.logo ? withBase(theme.logo) : undefined"
110
127
  :brand-title="site.title"
111
128
  .menuItems="theme.nav.map((n) => ({ title: n.text, href: withBase(n.link) }))"
112
129
  :enable-login="theme.login"
@@ -121,10 +138,18 @@ onMounted(async () => {
121
138
  :background-image="frontmatter.hero.background"
122
139
  :underline="frontmatter.hero.tagline"
123
140
  :cta="frontmatter.hero.actions?.[0]"
124
- :cta-link="frontmatter.hero.actions?.[0]?.link ? withBase(frontmatter.hero.actions?.[0]?.link) : undefined"
141
+ :cta-link="
142
+ frontmatter.hero.actions?.[0]?.link
143
+ ? withBase(frontmatter.hero.actions?.[0]?.link)
144
+ : undefined
145
+ "
125
146
  :cta-text="frontmatter.hero.actions?.[0]?.text"
126
147
  :alt="frontmatter.hero.actions?.[1]"
127
- :alt-link="frontmatter.hero.actions?.[1]?.link ? withBase(frontmatter.hero.actions?.[1]?.link) : undefined"
148
+ :alt-link="
149
+ frontmatter.hero.actions?.[1]?.link
150
+ ? withBase(frontmatter.hero.actions?.[1]?.link)
151
+ : undefined
152
+ "
128
153
  :alt-text="frontmatter.hero.actions?.[1]?.text"
129
154
  :image="frontmatter.hero.image"
130
155
  ></esa-cover>
@@ -184,7 +209,7 @@ onMounted(async () => {
184
209
  </ClientOnly>
185
210
  </template>
186
211
  <template #not-found>
187
- <section class="blue" style="margin-top: var(--vp-nav-height);">
212
+ <section class="blue" style="margin-top: var(--vp-nav-height)">
188
213
  <h1>404</h1>
189
214
  <p>Page not found</p>
190
215
  <a class="VPButton cta" :href="withBase('/')">Go to Home</a>
@@ -36,6 +36,7 @@ onMounted(async () => {
36
36
  eox-storytelling {
37
37
  --header-font-family: NotesESAbold, sans-serif;
38
38
  --body-font-family: Arial, sans-serif;
39
+ --color: var(--vp-c-black, #101213);
39
40
  margin: var(--vp-nav-height) 0 var(--vp-nav-height) 0;
40
41
  background: white;
41
42
  color: var(--vp-c-black);
package/src/helpers.js CHANGED
@@ -30,3 +30,134 @@ export const applyShadowDomEventListener = (
30
30
  });
31
31
  });
32
32
  };
33
+
34
+ /**
35
+ * Normalizes a URL / path for tracking
36
+ *
37
+ * @param {string} inputUrl - URL or path
38
+ * @param {Object} [options] - Options
39
+ * @returns {string} Normalized URL / path
40
+ */
41
+ export const normalizeTrackingUrl = (inputUrl, options = {}) => {
42
+ if (!inputUrl || typeof inputUrl !== "string") return inputUrl;
43
+ const { ignoredParams = ["x", "y", "z"], stripTrailingSlash = true } =
44
+ options;
45
+
46
+ try {
47
+ const base =
48
+ typeof window !== "undefined" && window.location?.href
49
+ ? window.location.href
50
+ : "https://eox.at";
51
+ const url = new URL(inputUrl, base);
52
+ let pathname = url.pathname;
53
+
54
+ if (stripTrailingSlash && pathname.length > 1 && pathname.endsWith("/")) {
55
+ pathname = pathname.replace(/\/+$/, "");
56
+ }
57
+
58
+ const searchParams = new URLSearchParams(url.search);
59
+ for (const key of ignoredParams) {
60
+ searchParams.delete(key);
61
+ }
62
+ searchParams.sort();
63
+
64
+ const search = searchParams.toString();
65
+ const isRelativeInput = !/^https?:\/\//i.test(inputUrl);
66
+
67
+ if (isRelativeInput) {
68
+ return pathname + (search ? `?${search}` : "");
69
+ }
70
+ url.pathname = pathname;
71
+ url.search = search ? `?${search}` : "";
72
+ return url.toString();
73
+ } catch {
74
+ if (stripTrailingSlash && inputUrl.length > 1 && inputUrl.endsWith("/")) {
75
+ return inputUrl.replace(/\/+$/, "");
76
+ }
77
+ return inputUrl;
78
+ }
79
+ };
80
+
81
+ /**
82
+ * Track Matomo event with normalized path parameters.
83
+ *
84
+ * @param {Array<string|number>|string} eventDetails - Array of details or Category string
85
+ * @param {...*} rest - Remaining event details
86
+ */
87
+ export const trackEvent = (eventDetails, ...rest) => {
88
+ if (typeof window === "undefined") return;
89
+ const _paq = (window._paq = window._paq || []);
90
+
91
+ const details = Array.isArray(eventDetails)
92
+ ? [...eventDetails]
93
+ : [eventDetails, ...rest];
94
+
95
+ if (typeof details[1] === "string" && details[1].startsWith("/")) {
96
+ details[1] = normalizeTrackingUrl(details[1]);
97
+ }
98
+ if (typeof details[2] === "string" && details[2].startsWith("/")) {
99
+ details[2] = normalizeTrackingUrl(details[2]);
100
+ }
101
+
102
+ _paq.push(["trackEvent", ...details]);
103
+ };
104
+
105
+ /**
106
+ * Track page view with normalized URL and standardized document title.
107
+ *
108
+ * @param {Object|string} [options] - Router instance, options object, or path string
109
+ */
110
+ export const trackPageView = (options = {}) => {
111
+ if (typeof window === "undefined") return;
112
+ const _paq = (window._paq = window._paq || []);
113
+
114
+ let rawPath = "";
115
+ let rawTitle = "";
116
+
117
+ if (typeof options === "string") {
118
+ rawPath = options;
119
+ } else if (options && typeof options === "object") {
120
+ if (options.route) {
121
+ rawPath = options.route.path;
122
+ rawTitle = options.route.data?.title;
123
+ } else {
124
+ rawPath =
125
+ options.path ||
126
+ options.customUrl ||
127
+ (typeof window !== "undefined"
128
+ ? window.location.pathname + window.location.search
129
+ : "");
130
+ rawTitle =
131
+ options.title ||
132
+ options.customTitle ||
133
+ (typeof document !== "undefined" ? document.title : "");
134
+ }
135
+ }
136
+
137
+ const normalizedUrl = normalizeTrackingUrl(rawPath);
138
+ if (normalizedUrl) {
139
+ _paq.push(["setCustomUrl", normalizedUrl]);
140
+ }
141
+ if (rawTitle) {
142
+ _paq.push(["setDocumentTitle", rawTitle.trim()]);
143
+ }
144
+ _paq.push(["trackPageView"]);
145
+ _paq.push(["enableLinkTracking"]);
146
+ };
147
+
148
+ /**
149
+ * Track site search keyword query in Matomo.
150
+ *
151
+ * @param {string} keyword - Searched term
152
+ * @param {string|boolean} [category=false] - Search category
153
+ * @param {number} [resultsCount=0] - Result count
154
+ */
155
+ export const trackSiteSearch = (
156
+ keyword,
157
+ category = false,
158
+ resultsCount = 0,
159
+ ) => {
160
+ if (typeof window === "undefined") return;
161
+ const _paq = (window._paq = window._paq || []);
162
+ _paq.push(["trackSiteSearch", keyword, category, resultsCount]);
163
+ };
@@ -0,0 +1,57 @@
1
+ import { describe, it, beforeEach } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import {
4
+ normalizeTrackingUrl,
5
+ trackPageView,
6
+ trackEvent,
7
+ trackSiteSearch,
8
+ } from "./helpers.js";
9
+
10
+ describe("ESA helpers - normalizeTrackingUrl", () => {
11
+ it("strips trailing slashes from path", () => {
12
+ assert.equal(normalizeTrackingUrl("/explore/"), "/explore");
13
+ assert.equal(normalizeTrackingUrl("/explore"), "/explore");
14
+ });
15
+
16
+ it("removes map coordinates x, y, z while keeping template", () => {
17
+ assert.equal(
18
+ normalizeTrackingUrl("/explore/?x=15&y=48&z=4&template=expert"),
19
+ "/explore?template=expert",
20
+ );
21
+ });
22
+ });
23
+
24
+ describe("ESA helpers - trackEvent", () => {
25
+ beforeEach(() => {
26
+ globalThis._paq = [];
27
+ globalThis.window = globalThis;
28
+ });
29
+
30
+ it("pushes event and normalizes path in payload", () => {
31
+ trackEvent(["Interaction", "Scroll Depth", "/explore/", 25]);
32
+ assert.deepEqual(globalThis._paq, [
33
+ ["trackEvent", "Interaction", "Scroll Depth", "/explore", 25],
34
+ ]);
35
+ });
36
+ });
37
+
38
+ describe("ESA helpers - trackPageView", () => {
39
+ beforeEach(() => {
40
+ globalThis._paq = [];
41
+ globalThis.window = globalThis;
42
+ globalThis.document = { title: "Test Title" };
43
+ });
44
+
45
+ it("tracks normalized pageview", () => {
46
+ trackPageView({
47
+ path: "/story/",
48
+ title: "Story Page",
49
+ });
50
+ assert.deepEqual(globalThis._paq, [
51
+ ["setCustomUrl", "/story"],
52
+ ["setDocumentTitle", "Story Page"],
53
+ ["trackPageView"],
54
+ ["enableLinkTracking"],
55
+ ]);
56
+ });
57
+ });
package/src/style.css CHANGED
@@ -57,15 +57,15 @@ h6,
57
57
  }
58
58
 
59
59
  a:not(.VPButton) {
60
- border-bottom: 0.125rem solid #00AE9D;
60
+ border-bottom: 0.125rem solid #00ae9d;
61
61
  padding-bottom: 0.15625rem;
62
- transition: all .5s ease;
62
+ transition: all 0.5s ease;
63
63
  text-decoration: none;
64
64
  color: currentColor;
65
65
  }
66
66
  a:not(.VPButton):hover {
67
- padding-bottom: .3125rem;
68
- color: #00AE9D;
67
+ padding-bottom: 0.3125rem;
68
+ color: #00ae9d;
69
69
  }
70
70
 
71
71
  body {
@@ -239,3 +239,115 @@ section > p {
239
239
  eox-feedback-button {
240
240
  z-index: calc(var(--vp-z-index-footer) + 1);
241
241
  }
242
+
243
+ /*
244
+ * Lists
245
+ */
246
+ section ul,
247
+ section ol,
248
+ .VPPage ul,
249
+ .VPPage ol {
250
+ padding-left: 1.25rem;
251
+ margin: 16px 0;
252
+ }
253
+
254
+ section ul,
255
+ .VPPage ul {
256
+ list-style: disc;
257
+ }
258
+
259
+ section ol,
260
+ .VPPage ol {
261
+ list-style: decimal;
262
+ }
263
+
264
+ section ul ul,
265
+ .VPPage ul ul {
266
+ list-style: circle;
267
+ }
268
+
269
+ section ul ul ul,
270
+ .VPPage ul ul ul {
271
+ list-style: square;
272
+ }
273
+
274
+ section li + li,
275
+ .VPPage li + li {
276
+ margin-top: 8px;
277
+ }
278
+
279
+ section li > ol,
280
+ section li > ul,
281
+ .VPPage li > ol,
282
+ .VPPage li > ul {
283
+ margin: 8px 0 0;
284
+ }
285
+
286
+ section li,
287
+ .VPPage li {
288
+ line-height: 1.75rem;
289
+ font-size: 1.125rem;
290
+ }
291
+
292
+ /*
293
+ * Tables
294
+ */
295
+ section table,
296
+ .VPPage table {
297
+ width: 100%;
298
+ border-collapse: collapse;
299
+ margin: 24px 0;
300
+ display: table;
301
+ overflow-x: auto;
302
+ }
303
+
304
+ section tr,
305
+ .VPPage tr {
306
+ border-top: 1px solid rgba(255, 255, 255, 0.15);
307
+ transition: background-color 0.3s ease;
308
+ }
309
+
310
+ section.white tr,
311
+ section.light-grey tr {
312
+ border-top: 1px solid rgba(0, 0, 0, 0.12);
313
+ }
314
+
315
+ section th,
316
+ section td,
317
+ .VPPage th,
318
+ .VPPage td {
319
+ border: 1px solid rgba(255, 255, 255, 0.15);
320
+ padding: 10px 16px;
321
+ text-align: left;
322
+ font-size: 1rem;
323
+ line-height: 1.5rem;
324
+ }
325
+
326
+ section.white th,
327
+ section.white td,
328
+ section.light-grey th,
329
+ section.light-grey td {
330
+ border: 1px solid rgba(0, 0, 0, 0.12);
331
+ }
332
+
333
+ section th,
334
+ .VPPage th {
335
+ font-family: "NotesESAbold", sans-serif;
336
+ font-weight: 600;
337
+ background-color: rgba(255, 255, 255, 0.08);
338
+ }
339
+
340
+ section.white th,
341
+ section.light-grey th {
342
+ background-color: rgba(0, 0, 0, 0.05);
343
+ }
344
+
345
+ section tbody tr:nth-child(2n),
346
+ .VPPage tbody tr:nth-child(2n) {
347
+ background-color: rgba(255, 255, 255, 0.03);
348
+ }
349
+
350
+ section.white tbody tr:nth-child(2n),
351
+ section.light-grey tbody tr:nth-child(2n) {
352
+ background-color: rgba(0, 0, 0, 0.02);
353
+ }