@uniweb/core 1.6.3 → 1.6.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,8 +53,8 @@
53
53
  "vitest": "^4.1.7"
54
54
  },
55
55
  "dependencies": {
56
- "@uniweb/theming": "~1.2.1",
57
- "@uniweb/semantic-parser": "~1.13.2"
56
+ "@uniweb/semantic-parser": "~1.13.2",
57
+ "@uniweb/theming": "~1.2.1"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest run"
@@ -334,6 +334,33 @@ export function recordImage(record) {
334
334
  return typeof image === 'string' && image.trim() !== '' ? image : undefined
335
335
  }
336
336
 
337
+ /**
338
+ * A record's DESCRIPTION — the line the page about it is described by (its meta description),
339
+ * and the line under it in a search result and in `llms.txt`.
340
+ *
341
+ * ONE RULE, read where `recordTitle` is: the parametric page (`Website._createDynamicPage`), the
342
+ * static build's page expansion, and the record search index (`@uniweb/projections`).
343
+ *
344
+ * description → excerpt
345
+ *
346
+ * Only a non-empty string describes a record. A rich-text field named `description` is a
347
+ * document, which this rule cannot write into a meta tag, so it is passed over for `excerpt`.
348
+ * ⛔ Until 2026-11-06 the page and the build took either field as it came, so a rich-text
349
+ * `description` described the page as `[object Object]`, and the search index never read
350
+ * either: its excerpt was the record's strings run together, icon names and colours included,
351
+ * and `llms.txt` described each record's page with it.
352
+ *
353
+ * @param {Object} record
354
+ * @returns {string|undefined}
355
+ */
356
+ export function recordDescription(record) {
357
+ if (!record || typeof record !== 'object') return undefined
358
+ for (const value of [record.description, record.excerpt]) {
359
+ if (typeof value === 'string' && value.trim() !== '') return value
360
+ }
361
+ return undefined
362
+ }
363
+
337
364
  /**
338
365
  * The record field a route param is matched on — ONE MAP, read by the local match
339
366
  * (`routeParamValue`, below) and by the records service's record question (`match`,
package/src/tracker.js CHANGED
@@ -292,10 +292,6 @@ export default class Tracker {
292
292
  // already run.
293
293
  /** When the current path became active. */
294
294
  this.pageEnteredAt = null
295
- /** Hidden time accrued on the current path, in ms. */
296
- this.hiddenMs = 0
297
- /** When the document last became hidden, or `null` while visible. */
298
- this.hiddenSince = null
299
295
  /** Guards against a second report for one page visit — see `reportTimeOnPage`. */
300
296
  this.pageReported = false
301
297
 
@@ -662,8 +658,6 @@ export default class Tracker {
662
658
  */
663
659
  startTimeOnPage() {
664
660
  this.pageEnteredAt = Date.now()
665
- this.hiddenMs = 0
666
- this.hiddenSince = null
667
661
  this.pageReported = false
668
662
  }
669
663
 
@@ -677,21 +671,20 @@ export default class Tracker {
677
671
  * skewed — a tab left open overnight sits in the same mean as forty readers —
678
672
  * so a clamp is genuinely needed; it is just not needed *here*.
679
673
  *
680
- * ⛔ **Hidden time is subtracted**, or this measures tab-open rather than
681
- * reading. A backgrounded tab accrues nothing.
682
- *
683
- * ⛔ **Reported at a route change and at `pagehide` — NOT when the document
684
- * merely becomes hidden.** Visibility is a *pause*, not an end: someone who
685
- * switches tabs to look something up and comes back is still reading. Emitting
686
- * on hidden would truncate exactly the engaged readers this metric exists to
687
- * find, and — because the consumer derives a mean from a sum and a count —
688
- * emitting more than once per page visit would inflate the count and make
689
- * every mean wrong. Hence `pageReported`: **at most one per page visit.**
690
- *
691
- * ⚠️ **The cost of that choice, stated rather than hidden:** a page discarded
692
- * while hidden, without `pagehide`, is never reported. That is an
693
- * under-count, it is bounded, and it fails in the direction that does not
694
- * corrupt the statistic.
674
+ * ⭐ **Reported at the first of three ends: a route change, `pagehide`, or the
675
+ * document becoming hidden** [Diego, 2026-11-03]. A phone visitor who switches
676
+ * apps, to paste a copied prompt or answer a message, may never come back, and
677
+ * the phone can then discard the page with no `pagehide`. Reported only at
678
+ * `pagehide`, about four in ten views on a mostly-phone site carried no time
679
+ * at all (24robert.ca, 2026-11-01, measured by hosting). So every view now
680
+ * reports the time until the visitor first left it, and the number is a floor.
681
+ *
682
+ * ⚖️ **The cost, stated rather than hidden:** a reader who switches away and
683
+ * comes back is counted only up to the switch. The view still reports once,
684
+ * since the consumer derives a mean from a sum and a count: a second event for
685
+ * one visit would inflate the count and make every mean wrong. Hence
686
+ * `pageReported`: **at most one per page visit.** The next page starts a new
687
+ * one. *(Until that day, hidden was a pause and its time was subtracted.)*
695
688
  *
696
689
  * @private
697
690
  */
@@ -699,11 +692,7 @@ export default class Tracker {
699
692
  if (this.pageReported || this.pageEnteredAt === null || !this.currentPath) return
700
693
  if (!this.arms('time_on_page')) return
701
694
 
702
- const now = Date.now()
703
- // A tab hidden at this instant has not yet had its span folded in.
704
- const openHidden = this.hiddenSince === null ? 0 : now - this.hiddenSince
705
- const durationMs = now - this.pageEnteredAt - this.hiddenMs - openHidden
706
-
695
+ const durationMs = Date.now() - this.pageEnteredAt
707
696
  this.pageReported = true
708
697
  // Negative is not reachable by arithmetic, but a clock adjustment mid-visit
709
698
  // would produce one, and a negative duration poisons a sum the consumer
@@ -726,13 +715,12 @@ export default class Tracker {
726
715
  this.flush(true)
727
716
  })
728
717
  window.addEventListener('visibilitychange', () => {
718
+ // The last moment a phone promises: a page hidden may be discarded with no
719
+ // `pagehide`. So the view's time is queued first, as at `pagehide`, and
720
+ // everything goes by beacon.
729
721
  if (document.visibilityState === 'hidden') {
730
- // A pause, not an end — see `reportTimeOnPage`. Only the clock stops.
731
- if (this.hiddenSince === null) this.hiddenSince = Date.now()
722
+ this.reportTimeOnPage()
732
723
  this.flush(true)
733
- } else if (this.hiddenSince !== null) {
734
- this.hiddenMs += Date.now() - this.hiddenSince
735
- this.hiddenSince = null
736
724
  }
737
725
  })
738
726
  }
package/src/website.js CHANGED
@@ -12,7 +12,7 @@ import ObservableState from './observable-state.js'
12
12
  import { normalizeSeo } from './seo.js'
13
13
  import { siteAddress, pageUrl } from './site-address.js'
14
14
  import { resolveDefaultLocale, localeLabel } from './locale-config.js'
15
- import { isDynamicRoute, matchDynamicRoute, recordTitle, recordImage, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
15
+ import { isDynamicRoute, matchDynamicRoute, recordTitle, recordImage, recordDescription, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
16
16
  import { resolveFetchConfigs, pageRouteQuery, recordPages } from './fetch-config.js'
17
17
  import { declaredKeys } from './data-keys.js'
18
18
  import { pageRecordConfig, planFor, runPlanSync } from './page-data.js'
@@ -682,9 +682,11 @@ export default class Website {
682
682
  // read `title` alone, so a person record kept the template's title — `:slug`.
683
683
  const title = recordTitle(currentItem)
684
684
  if (title) pageData.title = title
685
- if (currentItem.description || currentItem.excerpt) {
686
- pageData.description = currentItem.description || currentItem.excerpt
687
- }
685
+ // ⭐ And described by its text: `description`, else `excerpt` (`recordDescription`).
686
+ // ⛔ Until 2026-11-06 either was taken as it came, and a rich-text `description`
687
+ // described the page as `[object Object]`.
688
+ const description = recordDescription(currentItem)
689
+ if (description) pageData.description = description
688
690
  // ⭐ And by its picture: a link to the page shows the record's image (`recordImage`).
689
691
  // ⛔ Until 2026-10-05 it showed the page's or the site's `seo.image`, the same for
690
692
  // every record.