@jant/core 1.1.0 → 1.3.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/bin/commands/site/import.js +2 -1
- package/bin/lib/site-snapshot.js +10 -0
- package/dist/{app-CKQ9PqAr.js → app-C8dETvgL.js} +9267 -5697
- package/dist/client/.vite/manifest.json +82 -93
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-B8KuszlS.js} +38 -38
- package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
- package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
- package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-Bz2Na2E9.js +2 -0
- package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
- package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
- package/dist/client/_assets/client-CoNHvipV.css +2 -0
- package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CbnZkLJ6.js} +99 -129
- package/dist/client/_assets/{client-author-CGVvrNZ8.css → client-author-2WYBkgni.css} +1 -1
- package/dist/client/_assets/client-compose-DYtDlYm-.js +2008 -0
- package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/client-pq6sVS7y.js +354 -0
- package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-DDpe_tXJ.js} +166 -166
- package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
- package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
- package/dist/index.js +1 -1
- package/dist/node.js +3 -2
- package/package.json +2 -1
- package/src/app.tsx +9 -0
- package/src/client/components/compose-types.ts +6 -1
- package/src/client/components/jant-compose-dialog.ts +26 -4
- package/src/client/components/jant-compose-editor.ts +30 -0
- package/src/client/components/jant-compose-fullscreen.ts +1 -0
- package/src/client/components/jant-media-lightbox.ts +18 -3
- package/src/client/components/jant-nav-manager.ts +2 -0
- package/src/client/components/jant-post-menu.ts +42 -89
- package/src/client/components/nav-manager-types.ts +2 -0
- package/src/client/components/settings-types.ts +1 -1
- package/src/client/compose-bridge.ts +61 -1
- package/src/client/feed-video-player.ts +6 -0
- package/src/client/list-views.ts +382 -0
- package/src/client/media-lightbox-events.ts +12 -0
- package/src/client/runtime-paths.ts +12 -0
- package/src/client/share-capture.ts +63 -0
- package/src/client/share-launch.ts +36 -9
- package/src/client/tiptap/bubble-menu.ts +25 -2
- package/src/client/tiptap/create-editor.ts +6 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/extensions.ts +4 -0
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/video-processor.ts +106 -52
- package/src/client/view-confirm.ts +136 -0
- package/src/client.ts +2 -0
- package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
- package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
- package/src/db/migrations/0037_round_post.sql +16 -0
- package/src/db/migrations/0038_flashy_changeling.sql +15 -0
- package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
- package/src/db/migrations/meta/0035_snapshot.json +2877 -0
- package/src/db/migrations/meta/0036_snapshot.json +2924 -0
- package/src/db/migrations/meta/0037_snapshot.json +2932 -0
- package/src/db/migrations/meta/0038_snapshot.json +2924 -0
- package/src/db/migrations/meta/0039_snapshot.json +2931 -0
- package/src/db/migrations/meta/_journal.json +35 -0
- package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
- package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
- package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
- package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
- package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
- package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
- package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
- package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
- package/src/db/migrations/pg/meta/_journal.json +35 -0
- package/src/db/pg/schema.ts +41 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +64 -0
- package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
- package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
- package/src/i18n/locales/public/en.po +26 -7
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +25 -6
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +25 -6
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +159 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +159 -0
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +159 -0
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/env.ts +20 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/github-app-state.ts +1 -1
- package/src/lib/github-app.ts +183 -1
- package/src/lib/hugo-markdown.ts +7 -0
- package/src/lib/icons.ts +2 -0
- package/src/lib/link-preview.ts +499 -0
- package/src/lib/list-views.ts +117 -0
- package/src/lib/markdown-manager.ts +169 -2
- package/src/lib/navigation.ts +1 -1
- package/src/lib/post-meta.ts +13 -3
- package/src/lib/referrer-aliases.ts +311 -0
- package/src/lib/render.tsx +10 -0
- package/src/lib/resolve-config.ts +14 -0
- package/src/lib/share-card.ts +4 -3
- package/src/lib/summary.ts +152 -54
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/tiptap-render.ts +1 -0
- package/src/lib/upload.ts +21 -1
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/video-playback.ts +55 -0
- package/src/lib/view-buffer.ts +201 -0
- package/src/lib/view-counting.ts +540 -0
- package/src/lib/view-token.ts +199 -0
- package/src/lib/view.ts +30 -1
- package/src/middleware/view-counter.ts +145 -0
- package/src/node/runtime.ts +4 -0
- package/src/preset.css +36 -17
- package/src/routes/api/media.ts +21 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +434 -169
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +26 -19
- package/src/routes/pages/collection.tsx +9 -3
- package/src/routes/pages/collections.tsx +1 -0
- package/src/routes/pages/featured.tsx +1 -0
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/page.tsx +18 -3
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/smart-collection.tsx +2 -0
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/view-confirm.ts +71 -0
- package/src/services/collection.ts +1 -1
- package/src/services/export-theme/assets/client-site.js +19 -19
- package/src/services/export-theme/layouts/archive/list.html +4 -2
- package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
- package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
- package/src/services/export-theme/layouts/partials/head.html +2 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
- package/src/services/export-theme/layouts/partials/post-card.html +1 -9
- package/src/services/export-theme/layouts/partials/reply.html +1 -9
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
- package/src/services/export-theme/layouts/post/list.html +1 -9
- package/src/services/export-theme/styles/main.css +41 -47
- package/src/services/export.ts +12 -3
- package/src/services/index.ts +17 -0
- package/src/services/mcp.ts +36 -6
- package/src/services/media.ts +63 -0
- package/src/services/navigation.ts +9 -4
- package/src/services/post.ts +102 -112
- package/src/services/search.ts +22 -7
- package/src/services/smart-collection.ts +3 -3
- package/src/services/stats.ts +1137 -0
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +242 -3
- package/src/styles/components.css +11 -3
- package/src/styles/tokens.css +89 -55
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +90 -45
- package/src/types/app-context.ts +9 -0
- package/src/types/bindings.ts +5 -0
- package/src/types/config.ts +54 -0
- package/src/types/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +8 -0
- package/src/ui/compose/ComposeDialog.tsx +26 -1
- package/src/ui/dash/StatusBadge.tsx +11 -0
- package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
- package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
- package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
- package/src/ui/dash/settings/StatsContent.tsx +855 -0
- package/src/ui/feed/LinkCard.tsx +19 -2
- package/src/ui/feed/PostStatusBadges.tsx +19 -3
- package/src/ui/feed/TimelineFeed.tsx +3 -0
- package/src/ui/font-themes.ts +56 -6
- package/src/ui/layouts/BaseLayout.tsx +4 -2
- package/src/ui/layouts/SiteLayout.tsx +8 -3
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/shared/MediaGallery.tsx +19 -3
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
- package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
- package/dist/client/_assets/client-B0-s9sqx.css +0 -2
- package/dist/client/_assets/client-Dp46QSht.js +0 -354
- package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Views wait here for a few seconds and leave as one write.
|
|
3
|
+
*
|
|
4
|
+
* Counting a view costs a database write, and a write is the one thing a
|
|
5
|
+
* well-read page must not multiply. So a hit is added to an in-memory map and
|
|
6
|
+
* the map is written out once, five seconds after its first hit: three
|
|
7
|
+
* hundred readers opening one post from one link in those seconds are one row
|
|
8
|
+
* with `count` three hundred. Under ordinary traffic nothing changes — a view
|
|
9
|
+
* is still one write — and under a spike the writes fall by one or two orders
|
|
10
|
+
* of magnitude.
|
|
11
|
+
*
|
|
12
|
+
* The map lives as long as the process that holds it: the whole run on Node,
|
|
13
|
+
* an isolate's lifetime on Workers, where `keepAlive` hands the pending flush
|
|
14
|
+
* to `waitUntil` so the isolate stays up for it. A process that dies between
|
|
15
|
+
* a hit and its flush loses those few seconds of counts, which is the price
|
|
16
|
+
* of never making a reader wait, and is accepted: the numbers are a guide,
|
|
17
|
+
* not a ledger. The Node runtime flushes on `close()`.
|
|
18
|
+
*
|
|
19
|
+
* The buffer also holds the daily stop: once a flush reports the instance's
|
|
20
|
+
* daily limit reached, hits are dropped until the next UTC day, when the
|
|
21
|
+
* free-tier D1 write quota that the limit protects resets.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** How long a hit waits for company before the buffer is written out. */
|
|
25
|
+
export const VIEW_FLUSH_DELAY_MS = 5_000;
|
|
26
|
+
|
|
27
|
+
/** One reader opening one page, or reading one Thread in a list, as the counter files it. */
|
|
28
|
+
export interface ViewHit {
|
|
29
|
+
siteId: string;
|
|
30
|
+
/** The site's calendar day, `YYYY-MM-DD`. */
|
|
31
|
+
day: string;
|
|
32
|
+
/** The site's hour, `YYYY-MM-DDTHH`, for today's chart. */
|
|
33
|
+
hour: string;
|
|
34
|
+
/** A Thread's root id, or the path of any other page. */
|
|
35
|
+
page: string;
|
|
36
|
+
/** The referring host, or `""`. */
|
|
37
|
+
referrer: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A hit with the number of times it happened. */
|
|
41
|
+
export interface ViewCountEntry extends ViewHit {
|
|
42
|
+
count: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What a sink reports back from writing a batch. */
|
|
46
|
+
export interface ViewRecordResult {
|
|
47
|
+
/** The instance has recorded its daily limit of views; stop until tomorrow. */
|
|
48
|
+
limitReached: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Where a flush goes, and how the runtime is kept alive for it. */
|
|
52
|
+
export interface ViewSink {
|
|
53
|
+
record(entries: ViewCountEntry[]): Promise<ViewRecordResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Hands the pending flush to the runtime so it outlives the response that
|
|
56
|
+
* scheduled it. Workers pass `waitUntil`; Node needs nothing.
|
|
57
|
+
*/
|
|
58
|
+
keepAlive?(promise: Promise<unknown>): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface ScheduledFlush {
|
|
62
|
+
timer: ReturnType<typeof setTimeout>;
|
|
63
|
+
settle: () => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function entryKey(hit: ViewHit): string {
|
|
67
|
+
return `${hit.siteId}\n${hit.hour}\n${hit.page}\n${hit.referrer}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function nextUtcMidnight(nowMs: number): number {
|
|
71
|
+
const date = new Date(nowMs);
|
|
72
|
+
return Date.UTC(
|
|
73
|
+
date.getUTCFullYear(),
|
|
74
|
+
date.getUTCMonth(),
|
|
75
|
+
date.getUTCDate() + 1,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Collects view hits and writes them out in batches.
|
|
81
|
+
*
|
|
82
|
+
* One instance per process is the point; tests construct their own with a
|
|
83
|
+
* shorter delay and call `flush()` themselves.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const buffer = new ViewBuffer();
|
|
88
|
+
* buffer.add(hit, { record: (entries) => services.stats.record(entries, opts) });
|
|
89
|
+
* // five seconds later, one write
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export class ViewBuffer {
|
|
93
|
+
readonly #delayMs: number;
|
|
94
|
+
readonly #now: () => number;
|
|
95
|
+
readonly #pending = new Map<string, ViewCountEntry>();
|
|
96
|
+
#sink: ViewSink | null = null;
|
|
97
|
+
#scheduled: ScheduledFlush | null = null;
|
|
98
|
+
#pausedUntil = 0;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param options.delayMs - How long the first hit waits before the flush
|
|
102
|
+
* @param options.now - Clock in milliseconds, for tests
|
|
103
|
+
*/
|
|
104
|
+
constructor(options: { delayMs?: number; now?: () => number } = {}) {
|
|
105
|
+
this.#delayMs = options.delayMs ?? VIEW_FLUSH_DELAY_MS;
|
|
106
|
+
this.#now = options.now ?? Date.now;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Hits waiting to be written, as distinct entries. */
|
|
110
|
+
get size(): number {
|
|
111
|
+
return this.#pending.size;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Whether the daily stop is in force right now. */
|
|
115
|
+
get paused(): boolean {
|
|
116
|
+
return this.#now() < this.#pausedUntil;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Add one hit and make sure a flush is coming.
|
|
121
|
+
*
|
|
122
|
+
* The sink of the latest hit is the one the flush uses: every sink in one
|
|
123
|
+
* process writes to the same database, so any of them will do.
|
|
124
|
+
*
|
|
125
|
+
* @param hit - The view
|
|
126
|
+
* @param sink - Where the batch goes
|
|
127
|
+
* @returns Nothing
|
|
128
|
+
*/
|
|
129
|
+
add(hit: ViewHit, sink: ViewSink): void {
|
|
130
|
+
if (this.paused) return;
|
|
131
|
+
this.#sink = sink;
|
|
132
|
+
|
|
133
|
+
const key = entryKey(hit);
|
|
134
|
+
const entry = this.#pending.get(key);
|
|
135
|
+
if (entry) {
|
|
136
|
+
entry.count += 1;
|
|
137
|
+
} else {
|
|
138
|
+
this.#pending.set(key, { ...hit, count: 1 });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (this.#scheduled) return;
|
|
142
|
+
|
|
143
|
+
let settle!: () => void;
|
|
144
|
+
const done = new Promise<void>((resolve) => {
|
|
145
|
+
settle = resolve;
|
|
146
|
+
});
|
|
147
|
+
const timer = setTimeout(() => {
|
|
148
|
+
this.#scheduled = null;
|
|
149
|
+
void this.flush().finally(settle);
|
|
150
|
+
}, this.#delayMs);
|
|
151
|
+
// A pending flush must not hold a stopping Node process open; the runtime
|
|
152
|
+
// drains the buffer on close instead.
|
|
153
|
+
(timer as { unref?: () => void }).unref?.();
|
|
154
|
+
this.#scheduled = { timer, settle };
|
|
155
|
+
sink.keepAlive?.(done);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Write out everything pending now.
|
|
160
|
+
*
|
|
161
|
+
* Never rejects: a failed write is logged and its hits are gone, because
|
|
162
|
+
* nothing upstream can do anything with the failure.
|
|
163
|
+
*
|
|
164
|
+
* @returns Nothing, once the write has settled
|
|
165
|
+
*/
|
|
166
|
+
async flush(): Promise<void> {
|
|
167
|
+
const scheduled = this.#scheduled;
|
|
168
|
+
if (scheduled) {
|
|
169
|
+
this.#scheduled = null;
|
|
170
|
+
clearTimeout(scheduled.timer);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const entries = [...this.#pending.values()];
|
|
174
|
+
this.#pending.clear();
|
|
175
|
+
const sink = this.#sink;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
if (entries.length === 0 || !sink) return;
|
|
179
|
+
const { limitReached } = await sink.record(entries);
|
|
180
|
+
if (limitReached && !this.paused) {
|
|
181
|
+
this.#pausedUntil = nextUtcMidnight(this.#now());
|
|
182
|
+
// eslint-disable-next-line no-console -- An operator should see why a day's counts stop.
|
|
183
|
+
console.warn(
|
|
184
|
+
`[Jant] View counting paused until ${new Date(this.#pausedUntil).toISOString()}: STATS_DAILY_LIMIT reached.`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
} catch (error: unknown) {
|
|
188
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
189
|
+
// eslint-disable-next-line no-console -- Background failures must be visible.
|
|
190
|
+
console.error(`[Jant] View counting flush error: ${message}`);
|
|
191
|
+
} finally {
|
|
192
|
+
// The sink closes over a request's services and context; once nothing
|
|
193
|
+
// waits for it, let it go. A hit added meanwhile brought its own.
|
|
194
|
+
if (this.#sink === sink && this.#pending.size === 0) this.#sink = null;
|
|
195
|
+
scheduled?.settle();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The process's buffer, shared by every request. */
|
|
201
|
+
export const viewBuffer = new ViewBuffer();
|