@jant/core 1.1.0 → 1.2.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.
Files changed (116) hide show
  1. package/bin/lib/site-snapshot.js +10 -0
  2. package/dist/{app-CKQ9PqAr.js → app-CbOZ2Irh.js} +7988 -5166
  3. package/dist/client/.vite/manifest.json +47 -47
  4. package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-hWapNE40.js} +25 -25
  5. package/dist/client/_assets/chunks/footnote-rail-9zwl6jtV.js +2 -0
  6. package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-BBVT8zKj.js} +1 -1
  7. package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-BuCPjSrB.js} +1 -1
  8. package/dist/client/_assets/chunks/sortable-list-DJXwkaOv.js +2 -0
  9. package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
  10. package/dist/client/_assets/chunks/unsafe-svg-CUrgo4Xg.js +1 -0
  11. package/dist/client/_assets/{client-Dp46QSht.js → client-BO8GOFfT.js} +12 -12
  12. package/dist/client/_assets/client-D8Rrsd73.css +2 -0
  13. package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CsUGM718.js} +1 -1
  14. package/dist/client/_assets/client-author-QPm1whbO.css +2 -0
  15. package/dist/client/_assets/client-compose-BB4U7Wz0.js +2004 -0
  16. package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-CI9-eh-8.js} +1 -1
  17. package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-BnGPuqwc.js} +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/node.js +3 -2
  20. package/package.json +1 -1
  21. package/src/app.tsx +9 -0
  22. package/src/client/components/compose-types.ts +1 -0
  23. package/src/client/components/jant-compose-dialog.ts +1 -0
  24. package/src/client/components/jant-compose-editor.ts +30 -0
  25. package/src/client/components/jant-compose-fullscreen.ts +1 -0
  26. package/src/client/compose-bridge.ts +61 -1
  27. package/src/client/feed-video-player.ts +6 -0
  28. package/src/client/tiptap/bubble-menu.ts +25 -2
  29. package/src/client/tiptap/create-editor.ts +2 -0
  30. package/src/client/tiptap/extensions.ts +4 -0
  31. package/src/client/video-processor.ts +106 -52
  32. package/src/client/view-confirm.ts +108 -0
  33. package/src/client.ts +1 -0
  34. package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
  35. package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
  36. package/src/db/migrations/meta/0035_snapshot.json +2877 -0
  37. package/src/db/migrations/meta/0036_snapshot.json +2924 -0
  38. package/src/db/migrations/meta/_journal.json +14 -0
  39. package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
  40. package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
  41. package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
  42. package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
  43. package/src/db/migrations/pg/meta/_journal.json +14 -0
  44. package/src/db/pg/schema.ts +40 -0
  45. package/src/db/schema.ts +61 -0
  46. package/src/i18n/locales/public/en.po +5 -0
  47. package/src/i18n/locales/public/en.ts +1 -1
  48. package/src/i18n/locales/public/zh-Hans.po +5 -0
  49. package/src/i18n/locales/public/zh-Hans.ts +1 -1
  50. package/src/i18n/locales/public/zh-Hant.po +5 -0
  51. package/src/i18n/locales/public/zh-Hant.ts +1 -1
  52. package/src/i18n/locales/settings/en.po +149 -0
  53. package/src/i18n/locales/settings/en.ts +1 -1
  54. package/src/i18n/locales/settings/zh-Hans.po +149 -0
  55. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  56. package/src/i18n/locales/settings/zh-Hant.po +149 -0
  57. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  58. package/src/lib/env.ts +20 -0
  59. package/src/lib/github-app-state.ts +1 -1
  60. package/src/lib/github-app.ts +183 -1
  61. package/src/lib/markdown-manager.ts +129 -1
  62. package/src/lib/post-meta.ts +13 -3
  63. package/src/lib/referrer-aliases.ts +311 -0
  64. package/src/lib/render.tsx +10 -0
  65. package/src/lib/resolve-config.ts +14 -0
  66. package/src/lib/summary.ts +152 -54
  67. package/src/lib/tiptap-render.ts +1 -0
  68. package/src/lib/upload.ts +21 -1
  69. package/src/lib/video-playback.ts +55 -0
  70. package/src/lib/view-buffer.ts +201 -0
  71. package/src/lib/view-counting.ts +539 -0
  72. package/src/lib/view-token.ts +177 -0
  73. package/src/lib/view.ts +13 -1
  74. package/src/middleware/view-counter.ts +140 -0
  75. package/src/node/runtime.ts +4 -0
  76. package/src/preset.css +31 -14
  77. package/src/routes/api/media.ts +21 -3
  78. package/src/routes/dash/settings.tsx +433 -168
  79. package/src/routes/pages/archive.tsx +1 -0
  80. package/src/routes/pages/collection.tsx +6 -0
  81. package/src/routes/pages/collections.tsx +1 -0
  82. package/src/routes/pages/featured.tsx +1 -0
  83. package/src/routes/pages/home.tsx +1 -0
  84. package/src/routes/pages/page.tsx +3 -0
  85. package/src/routes/pages/smart-collection.tsx +2 -0
  86. package/src/routes/pages/subscribe.tsx +1 -0
  87. package/src/routes/view-confirm.ts +63 -0
  88. package/src/services/export-theme/assets/client-site.js +1 -1
  89. package/src/services/export-theme/styles/main.css +39 -21
  90. package/src/services/export.ts +2 -0
  91. package/src/services/index.ts +17 -0
  92. package/src/services/mcp.ts +31 -1
  93. package/src/services/media.ts +63 -0
  94. package/src/services/stats.ts +1130 -0
  95. package/src/styles/components-author.css +177 -0
  96. package/src/styles/components.css +11 -3
  97. package/src/styles/tokens.css +65 -30
  98. package/src/styles/ui.css +56 -13
  99. package/src/types/app-context.ts +9 -0
  100. package/src/types/bindings.ts +5 -0
  101. package/src/types/config.ts +54 -0
  102. package/src/types/views.ts +6 -0
  103. package/src/ui/compose/ComposeDialog.tsx +6 -0
  104. package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
  105. package/src/ui/dash/settings/StatsContent.tsx +855 -0
  106. package/src/ui/font-themes.ts +39 -6
  107. package/src/ui/layouts/BaseLayout.tsx +4 -2
  108. package/src/ui/layouts/SiteLayout.tsx +8 -3
  109. package/src/ui/shared/MediaGallery.tsx +19 -3
  110. package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
  111. package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
  112. package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
  113. package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
  114. package/dist/client/_assets/client-B0-s9sqx.css +0 -2
  115. package/dist/client/_assets/client-author-CGVvrNZ8.css +0 -2
  116. package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Tells the site that this page was seen.
3
+ *
4
+ * The server embeds a signed token in a page it would count as a view
5
+ * (`<meta name="jant-view">`, see `lib/view-token.ts`). It counts the view
6
+ * only once this script posts the token back, which it does once the page
7
+ * has been in front of the reader for five seconds in total, or sooner, on
8
+ * the first scroll, tap, key or pointer movement. A crawler that runs a real
9
+ * browser closes the page long before either, and an automated browser that
10
+ * admits to it (`navigator.webdriver`) is not asked at all.
11
+ *
12
+ * The token names the page and where the reader came from, decided on the
13
+ * server from the request; nothing about the reader is read here or sent.
14
+ * No cookie, no storage, one request, and nothing waits for its answer.
15
+ */
16
+
17
+ import { publicPath } from "./runtime-paths.js";
18
+
19
+ /** Visible time after which a page counts as seen, without any interaction. */
20
+ export const VIEW_CONFIRM_DWELL_MS = 5_000;
21
+
22
+ /** Where the token goes; the same path `lib/view-token.ts` names. */
23
+ const CONFIRM_PATH = "/_/seen";
24
+
25
+ /** Anything a reader does that a crawler fetching a page does not. */
26
+ const INTERACTION_EVENTS = [
27
+ "pointerdown",
28
+ "pointermove",
29
+ "keydown",
30
+ "wheel",
31
+ "touchstart",
32
+ "scroll",
33
+ ] as const;
34
+
35
+ function deliver(url: string, token: string): void {
36
+ const sent =
37
+ typeof navigator.sendBeacon === "function" &&
38
+ navigator.sendBeacon(url, new Blob([token], { type: "text/plain" }));
39
+ if (sent) return;
40
+ void fetch(url, {
41
+ method: "POST",
42
+ body: token,
43
+ keepalive: true,
44
+ headers: { "content-type": "text/plain" },
45
+ }).catch(() => {});
46
+ }
47
+
48
+ /**
49
+ * Arm the page's confirmation, if the page carries a token.
50
+ *
51
+ * @param doc - The document, the current one unless a test passes another
52
+ * @returns Nothing
53
+ * @example
54
+ * confirmView();
55
+ */
56
+ export function confirmView(doc: globalThis.Document = document): void {
57
+ const token = doc
58
+ .querySelector<globalThis.HTMLMetaElement>('meta[name="jant-view"]')
59
+ ?.getAttribute("content");
60
+ if (!token) return;
61
+ if (navigator.webdriver) return;
62
+
63
+ const url = publicPath(CONFIRM_PATH);
64
+ let done = false;
65
+ let remaining = VIEW_CONFIRM_DWELL_MS;
66
+ let visibleSince: number | null = null;
67
+ let timer: ReturnType<typeof setTimeout> | null = null;
68
+
69
+ const stopClock = () => {
70
+ if (timer === null) return;
71
+ clearTimeout(timer);
72
+ timer = null;
73
+ remaining = Math.max(0, remaining - (Date.now() - (visibleSince ?? 0)));
74
+ };
75
+ const startClock = () => {
76
+ if (done || timer !== null || doc.visibilityState !== "visible") return;
77
+ visibleSince = Date.now();
78
+ timer = setTimeout(send, remaining);
79
+ };
80
+ const onVisibility = () => {
81
+ if (doc.visibilityState === "visible") startClock();
82
+ else stopClock();
83
+ };
84
+ const send = () => {
85
+ if (done) return;
86
+ done = true;
87
+ stopClock();
88
+ for (const event of INTERACTION_EVENTS) {
89
+ doc.removeEventListener(event, send);
90
+ }
91
+ doc.removeEventListener("visibilitychange", onVisibility);
92
+ deliver(url, token);
93
+ };
94
+
95
+ for (const event of INTERACTION_EVENTS) {
96
+ doc.addEventListener(event, send, { passive: true });
97
+ }
98
+ doc.addEventListener("visibilitychange", onVisibility);
99
+ startClock();
100
+ }
101
+
102
+ if (document.readyState === "loading") {
103
+ document.addEventListener("DOMContentLoaded", () => confirmView(), {
104
+ once: true,
105
+ });
106
+ } else {
107
+ confirmView();
108
+ }
package/src/client.ts CHANGED
@@ -9,6 +9,7 @@ import "./vendor/datastar.js";
9
9
  import { installPrefixedFetch } from "./client/runtime-paths.js";
10
10
  import "./client/audio-player.js";
11
11
  import "./client/feed-video-player.js";
12
+ import "./client/view-confirm.js";
12
13
  import "./client/media-scroll-hint.js";
13
14
  import "./client/form-enter-submit.js";
14
15
  import "./client/copy-field.js";
@@ -0,0 +1,9 @@
1
+ CREATE TABLE `view_count` (
2
+ `site_id` text NOT NULL,
3
+ `day` text NOT NULL,
4
+ `page` text NOT NULL,
5
+ `referrer` text NOT NULL,
6
+ `count` integer DEFAULT 0 NOT NULL,
7
+ PRIMARY KEY(`site_id`, `day`, `page`, `referrer`),
8
+ FOREIGN KEY (`site_id`) REFERENCES `site`(`id`) ON UPDATE no action ON DELETE cascade
9
+ );
@@ -0,0 +1,7 @@
1
+ CREATE TABLE `view_hour` (
2
+ `site_id` text NOT NULL,
3
+ `hour` text NOT NULL,
4
+ `count` integer DEFAULT 0 NOT NULL,
5
+ PRIMARY KEY(`site_id`, `hour`),
6
+ FOREIGN KEY (`site_id`) REFERENCES `site`(`id`) ON UPDATE no action ON DELETE cascade
7
+ );