@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
package/src/lib/summary.ts
CHANGED
|
@@ -39,7 +39,9 @@ export const NOTE_SUMMARY_MIN_HIDDEN_CHARS = 200;
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Block node types that carry user-visible content for summary extraction.
|
|
42
|
-
* Structural nodes (horizontalRule, moreBreak
|
|
42
|
+
* Structural nodes (horizontalRule, moreBreak) are excluded. Images are not
|
|
43
|
+
* content blocks either: they never count toward a summary's limits, and only
|
|
44
|
+
* an HTML summary that asks for them keeps any (see `SummaryImageOptions`).
|
|
43
45
|
*/
|
|
44
46
|
const SUMMARY_BLOCK_TYPES = new Set([
|
|
45
47
|
"paragraph",
|
|
@@ -51,6 +53,36 @@ const SUMMARY_BLOCK_TYPES = new Set([
|
|
|
51
53
|
"table",
|
|
52
54
|
]);
|
|
53
55
|
|
|
56
|
+
/**
|
|
57
|
+
* How much room a run of text takes on the page, in Latin characters.
|
|
58
|
+
*
|
|
59
|
+
* A Han, kana or hangul character is a full em wide where a Latin letter is
|
|
60
|
+
* about half of one, so a 500-character Chinese teaser stands twice as tall as
|
|
61
|
+
* a 500-character English one. Each East Asian wide or fullwidth character
|
|
62
|
+
* counts as two, which keeps the character budgets below meaning the same
|
|
63
|
+
* amount of screen in either script.
|
|
64
|
+
*
|
|
65
|
+
* @param text - Plain text
|
|
66
|
+
* @returns Its length with wide characters counted twice
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* textWidth("hello"); // 5
|
|
71
|
+
* textWidth("你好"); // 4
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function textWidth(text: string): number {
|
|
75
|
+
let width = 0;
|
|
76
|
+
for (const char of text) {
|
|
77
|
+
width += WIDE_CHAR.test(char) ? 2 : 1;
|
|
78
|
+
}
|
|
79
|
+
return width;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Han, kana, hangul, CJK punctuation and fullwidth forms: one em wide. */
|
|
83
|
+
const WIDE_CHAR =
|
|
84
|
+
/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\u3000-\u303F\uFF00-\uFF60\uFFE0-\uFFE6]/u;
|
|
85
|
+
|
|
54
86
|
/**
|
|
55
87
|
* Recursively extracts plain text from a Tiptap node, ignoring marks.
|
|
56
88
|
*/
|
|
@@ -222,6 +254,33 @@ export function extractSummary(
|
|
|
222
254
|
return blocks.length > 0 ? blocks.join("\n\n") : null;
|
|
223
255
|
}
|
|
224
256
|
|
|
257
|
+
/**
|
|
258
|
+
* What an HTML summary keeps beyond the block and character limits.
|
|
259
|
+
*/
|
|
260
|
+
export interface SummaryOptions {
|
|
261
|
+
/**
|
|
262
|
+
* Keep images in the excerpt, each in its place. Before a `moreBreak`
|
|
263
|
+
* marker every image is kept, since the author chose that range. Otherwise
|
|
264
|
+
* the first image ahead of the cut is kept — one that sits after the last
|
|
265
|
+
* kept block but before the next dropped one counts as ahead of it — and
|
|
266
|
+
* the rest are left for the full page. Images never count toward the block
|
|
267
|
+
* or character limit, so keeping one never pushes text out. Default
|
|
268
|
+
* `false`: the excerpt is text only.
|
|
269
|
+
*/
|
|
270
|
+
includeImages?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Stop ahead of the first heading once the summary holds a text block, so
|
|
273
|
+
* the summary is the post's lead: a heading opens the body proper, and a
|
|
274
|
+
* teaser that ran past one showed a section title with its first paragraph
|
|
275
|
+
* and nothing of the section. Headings the post opens with are kept, so a
|
|
276
|
+
* post that starts with one still has a summary. This cut is structural,
|
|
277
|
+
* never softened by `minHiddenChars`. Default `false`: headings are blocks
|
|
278
|
+
* like any other, which is what a note wants — its body is the content and
|
|
279
|
+
* the limits only cap runaway length.
|
|
280
|
+
*/
|
|
281
|
+
stopAtHeading?: boolean;
|
|
282
|
+
}
|
|
283
|
+
|
|
225
284
|
/**
|
|
226
285
|
* Extracts an HTML summary from a Tiptap JSON body by taking the first
|
|
227
286
|
* N content-bearing block nodes and rendering them as HTML.
|
|
@@ -229,9 +288,14 @@ export function extractSummary(
|
|
|
229
288
|
* Unlike the plain-text `extractSummary`, this preserves the original
|
|
230
289
|
* structure (lists, blockquotes, headings, etc.) for rich previews.
|
|
231
290
|
*
|
|
291
|
+
* Character limits count East Asian wide characters as two
|
|
292
|
+
* ({@link textWidth}), so a Chinese teaser takes the room an English one
|
|
293
|
+
* does. With `stopAtHeading`, the summary is the post's lead and ends ahead
|
|
294
|
+
* of its first heading; see {@link SummaryOptions}.
|
|
295
|
+
*
|
|
232
296
|
* @param bodyJson - Tiptap JSON string
|
|
233
297
|
* @param maxBlocks - Maximum number of top-level blocks to include
|
|
234
|
-
* @param maxChars - Maximum total plain-text
|
|
298
|
+
* @param maxChars - Maximum total plain-text width, in Latin characters
|
|
235
299
|
* @param minHiddenChars - Tolerance for limit-based truncation: when > 0 and a
|
|
236
300
|
* block/char limit would hide a tail shorter than this many plain-text
|
|
237
301
|
* characters, the truncation is cancelled — all remaining content blocks are
|
|
@@ -239,15 +303,21 @@ export function extractSummary(
|
|
|
239
303
|
* sliver of text. Explicit `moreBreak` markers reflect author intent and are
|
|
240
304
|
* never subject to this tolerance.
|
|
241
305
|
* @param renderOptions - Renderer options such as the post footnote namespace
|
|
306
|
+
* @param options - Whether the excerpt keeps images and whether it stops at
|
|
307
|
+
* a heading; see {@link SummaryOptions}
|
|
242
308
|
* @returns HTML summary, whether content was truncated, and the index in
|
|
243
309
|
* `doc.content` where the content after the summary boundary begins, or null.
|
|
244
310
|
* `breakAtIndex` lets callers align the summary with the full-body rendering
|
|
245
311
|
* when splitting at the "read more" boundary (e.g. to insert an anchor).
|
|
312
|
+
* With images kept, `hasMore` is also true when an image was left out.
|
|
246
313
|
*
|
|
247
314
|
* @example
|
|
248
315
|
* ```ts
|
|
249
316
|
* const result = extractSummaryHtml(body, 5, 500);
|
|
250
317
|
* // { html: "<ul><li><p>Item</p></li></ul>", hasMore: true, breakAtIndex: 1 }
|
|
318
|
+
*
|
|
319
|
+
* extractSummaryHtml(body, 5, 500, 0, {}, { includeImages: true });
|
|
320
|
+
* // { html: "<figure><img src=\"…\"></figure><p>Intro</p>", hasMore: true, breakAtIndex: 2 }
|
|
251
321
|
* ```
|
|
252
322
|
*/
|
|
253
323
|
export function extractSummaryHtml(
|
|
@@ -256,6 +326,7 @@ export function extractSummaryHtml(
|
|
|
256
326
|
maxChars: number = 500,
|
|
257
327
|
minHiddenChars: number = 0,
|
|
258
328
|
renderOptions: TiptapRenderOptions = {},
|
|
329
|
+
options: SummaryOptions = {},
|
|
259
330
|
): { html: string; hasMore: boolean; breakAtIndex: number } | null {
|
|
260
331
|
let doc: TiptapNode;
|
|
261
332
|
try {
|
|
@@ -267,26 +338,38 @@ export function extractSummaryHtml(
|
|
|
267
338
|
if (doc.type !== "doc" || !doc.content) return null;
|
|
268
339
|
|
|
269
340
|
const nodes = doc.content;
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
// Check for moreBreak — take all content nodes before it
|
|
275
|
-
const moreBreakIdx = nodes.findIndex((n) => n.type === "moreBreak");
|
|
276
|
-
if (moreBreakIdx !== -1) {
|
|
277
|
-
const selected = nodes
|
|
278
|
-
.slice(0, moreBreakIdx)
|
|
279
|
-
.filter((n) => SUMMARY_BLOCK_TYPES.has(n.type));
|
|
280
|
-
if (selected.length === 0) return null;
|
|
341
|
+
const includeImages = options.includeImages === true;
|
|
342
|
+
const stopAtHeading = options.stopAtHeading === true;
|
|
343
|
+
const render = (indices: number[]): string => {
|
|
281
344
|
const subDoc: JSONContent = {
|
|
282
345
|
type: "doc",
|
|
283
346
|
content: [
|
|
284
|
-
...
|
|
347
|
+
...indices
|
|
348
|
+
.sort((a, b) => a - b)
|
|
349
|
+
.map((i) => nodes[i])
|
|
350
|
+
.filter((node): node is TiptapNode => node !== undefined),
|
|
285
351
|
...nodes.filter((node) => node.type === "footnoteDefinition"),
|
|
286
352
|
] as JSONContent[],
|
|
287
353
|
};
|
|
354
|
+
return renderTiptapDocument(subDoc, renderOptions);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Check for moreBreak — take all content nodes before it
|
|
358
|
+
const moreBreakIdx = nodes.findIndex((n) => n.type === "moreBreak");
|
|
359
|
+
if (moreBreakIdx !== -1) {
|
|
360
|
+
const selected: number[] = [];
|
|
361
|
+
for (let i = 0; i < moreBreakIdx; i++) {
|
|
362
|
+
const type = nodes[i]?.type ?? "";
|
|
363
|
+
if (
|
|
364
|
+
SUMMARY_BLOCK_TYPES.has(type) ||
|
|
365
|
+
(includeImages && type === "image")
|
|
366
|
+
) {
|
|
367
|
+
selected.push(i);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (selected.length === 0) return null;
|
|
288
371
|
return {
|
|
289
|
-
html:
|
|
372
|
+
html: render(selected),
|
|
290
373
|
hasMore: true,
|
|
291
374
|
// Anchor goes in place of the moreBreak marker, so the marker itself
|
|
292
375
|
// is NOT part of the pre-anchor body. It remains in the post-anchor
|
|
@@ -305,63 +388,77 @@ export function extractSummaryHtml(
|
|
|
305
388
|
if (!node || !SUMMARY_BLOCK_TYPES.has(node.type)) continue;
|
|
306
389
|
const text = extractPlainText(node).trim();
|
|
307
390
|
contentText.set(i, text);
|
|
308
|
-
totalContentChars += text
|
|
391
|
+
totalContentChars += textWidth(text);
|
|
309
392
|
}
|
|
310
393
|
|
|
311
|
-
const selected:
|
|
394
|
+
const selected: number[] = [];
|
|
312
395
|
let totalChars = 0;
|
|
313
396
|
let lastSelectedIdx = -1;
|
|
397
|
+
let hasTextBlock = false;
|
|
398
|
+
let cutAtHeading = false;
|
|
399
|
+
// Index of the first content block left out, or the end of the document
|
|
400
|
+
// when every block made it in.
|
|
401
|
+
let cutIdx = nodes.length;
|
|
402
|
+
|
|
403
|
+
for (const [i, text] of contentText) {
|
|
404
|
+
const isHeading = nodes[i]?.type === "heading";
|
|
405
|
+
const width = textWidth(text);
|
|
406
|
+
if (selected.length > 0) {
|
|
407
|
+
if (stopAtHeading && isHeading && hasTextBlock) {
|
|
408
|
+
cutIdx = i;
|
|
409
|
+
cutAtHeading = true;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
if (selected.length >= maxBlocks || totalChars + width > maxChars) {
|
|
413
|
+
cutIdx = i;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
314
417
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (!node || !SUMMARY_BLOCK_TYPES.has(node.type)) continue;
|
|
318
|
-
|
|
319
|
-
const text = contentText.get(i) ?? "";
|
|
320
|
-
if (
|
|
321
|
-
(selected.length >= maxBlocks || totalChars + text.length > maxChars) &&
|
|
322
|
-
selected.length > 0
|
|
323
|
-
)
|
|
324
|
-
break;
|
|
325
|
-
|
|
326
|
-
selected.push(node);
|
|
327
|
-
totalChars += text.length;
|
|
418
|
+
selected.push(i);
|
|
419
|
+
totalChars += width;
|
|
328
420
|
lastSelectedIdx = i;
|
|
421
|
+
if (!isHeading) hasTextBlock = true;
|
|
329
422
|
}
|
|
330
423
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
let hasMore = selected.length < totalContentNodes;
|
|
424
|
+
let hasMore = selected.length < contentText.size;
|
|
334
425
|
|
|
335
426
|
// Tolerance: don't truncate just to hide a tiny tail. When a block/char limit
|
|
336
427
|
// triggered the cut and the hidden content is shorter than `minHiddenChars`,
|
|
337
428
|
// include the remaining content blocks instead. `moreBreak` is handled above
|
|
338
|
-
// and never reaches this path.
|
|
429
|
+
// and never reaches this path; a heading cut is structural and stands.
|
|
339
430
|
if (
|
|
340
431
|
hasMore &&
|
|
432
|
+
!cutAtHeading &&
|
|
341
433
|
minHiddenChars > 0 &&
|
|
342
434
|
totalContentChars - totalChars < minHiddenChars
|
|
343
435
|
) {
|
|
344
|
-
for (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
selected.push(node);
|
|
436
|
+
for (const i of contentText.keys()) {
|
|
437
|
+
if (i <= lastSelectedIdx) continue;
|
|
438
|
+
selected.push(i);
|
|
348
439
|
lastSelectedIdx = i;
|
|
349
440
|
}
|
|
441
|
+
cutIdx = nodes.length;
|
|
350
442
|
hasMore = false;
|
|
351
443
|
}
|
|
352
444
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
445
|
+
let breakAtIndex = lastSelectedIdx + 1;
|
|
446
|
+
if (includeImages) {
|
|
447
|
+
const imageIdx = nodes.findIndex(
|
|
448
|
+
(node, i) => i < cutIdx && node.type === "image",
|
|
449
|
+
);
|
|
450
|
+
if (imageIdx !== -1) {
|
|
451
|
+
selected.push(imageIdx);
|
|
452
|
+
breakAtIndex = Math.max(breakAtIndex, imageIdx + 1);
|
|
453
|
+
}
|
|
454
|
+
if (nodes.some((node, i) => node.type === "image" && i !== imageIdx)) {
|
|
455
|
+
hasMore = true;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (selected.length === 0) return null;
|
|
460
|
+
|
|
461
|
+
return { html: render(selected), hasMore, breakAtIndex };
|
|
365
462
|
}
|
|
366
463
|
|
|
367
464
|
/**
|
|
@@ -369,10 +466,10 @@ export function extractSummaryHtml(
|
|
|
369
466
|
* the timeline uses.
|
|
370
467
|
*
|
|
371
468
|
* Wraps {@link extractSummaryHtml} with the limits that decide where a card
|
|
372
|
-
* stops: a titled post is an article whose excerpt is
|
|
373
|
-
* is a note whose body is the content and
|
|
374
|
-
* that boundary — the feed renderer, the
|
|
375
|
-
* than repeating five numbers each.
|
|
469
|
+
* stops: a titled post is an article whose excerpt is its lead, cut ahead of
|
|
470
|
+
* the first heading, an untitled one is a note whose body is the content and
|
|
471
|
+
* only needs a cap. Callers that need that boundary — the feed renderer, the
|
|
472
|
+
* theme exporter — share this rather than repeating five numbers each.
|
|
376
473
|
*
|
|
377
474
|
* @param bodyJson - TipTap JSON body, or null/undefined for a post without one
|
|
378
475
|
* @param hasTitle - Whether the post has a title, which makes it an article
|
|
@@ -395,6 +492,7 @@ export function extractTimelineSummary(
|
|
|
395
492
|
hasTitle ? ARTICLE_SUMMARY_MAX_CHARS : NOTE_SUMMARY_MAX_CHARS,
|
|
396
493
|
hasTitle ? 0 : NOTE_SUMMARY_MIN_HIDDEN_CHARS,
|
|
397
494
|
renderOptions,
|
|
495
|
+
{ stopAtHeading: hasTitle },
|
|
398
496
|
);
|
|
399
497
|
return result ? { html: result.html, hasMore: result.hasMore } : null;
|
|
400
498
|
}
|
package/src/lib/thread-query.ts
CHANGED
|
@@ -38,7 +38,11 @@ export type ThreadSelectionParse =
|
|
|
38
38
|
| { kind: "empty" };
|
|
39
39
|
|
|
40
40
|
const READER_VISIBILITIES = ["public", "featured", "hidden", "any"] as const;
|
|
41
|
-
const AUTHOR_VISIBILITIES = [
|
|
41
|
+
const AUTHOR_VISIBILITIES = [
|
|
42
|
+
...READER_VISIBILITIES,
|
|
43
|
+
"unlisted",
|
|
44
|
+
"private",
|
|
45
|
+
] as const;
|
|
42
46
|
|
|
43
47
|
/** The `visibility` values an author's Thread list takes. */
|
|
44
48
|
export const THREAD_AUTHOR_VISIBILITIES = AUTHOR_VISIBILITIES;
|
|
@@ -88,7 +92,7 @@ export function queryReader(query: object): ParamReader {
|
|
|
88
92
|
* refused.
|
|
89
93
|
*
|
|
90
94
|
* @param read - Reads one parameter; `undefined` when absent
|
|
91
|
-
* @param options.audience - A reader may not name `private`
|
|
95
|
+
* @param options.audience - A reader may not name `unlisted` or `private`
|
|
92
96
|
* @param options.loadCollections - Loads the collection vocabulary, called only
|
|
93
97
|
* when a collection is named
|
|
94
98
|
* @returns The selection, or `empty` when a named collection doesn't exist
|
package/src/lib/timeline.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
TimelineItemView,
|
|
14
14
|
} from "../types.js";
|
|
15
15
|
import type { AppVariables } from "../types/app-context.js";
|
|
16
|
+
import { isListedForReader } from "../types/constants.js";
|
|
16
17
|
import { buildMediaMap } from "./media-helpers.js";
|
|
17
18
|
import { createMediaContext, resolveDraftTailId, toPostView } from "./view.js";
|
|
18
19
|
import { getViewLang } from "./view-language.js";
|
|
@@ -411,7 +412,7 @@ export async function assembleTimeline(
|
|
|
411
412
|
const page = Math.max(1, options?.page ?? 1);
|
|
412
413
|
const offset = (page - 1) * pageSize;
|
|
413
414
|
|
|
414
|
-
const
|
|
415
|
+
const listedForReader = !(options?.isAuthenticated ?? false);
|
|
415
416
|
|
|
416
417
|
// Count + list are independent — run in parallel
|
|
417
418
|
const lang = viewLangFilter(c);
|
|
@@ -421,14 +422,14 @@ export async function assembleTimeline(
|
|
|
421
422
|
status: "published",
|
|
422
423
|
excludeReplies: true,
|
|
423
424
|
excludeLatestHidden: true,
|
|
424
|
-
|
|
425
|
+
listedForReader,
|
|
425
426
|
lang,
|
|
426
427
|
}),
|
|
427
428
|
c.var.services.posts.list({
|
|
428
429
|
status: "published",
|
|
429
430
|
excludeReplies: true,
|
|
430
431
|
excludeLatestHidden: true,
|
|
431
|
-
|
|
432
|
+
listedForReader,
|
|
432
433
|
lang,
|
|
433
434
|
limit: pageSize,
|
|
434
435
|
offset,
|
|
@@ -461,7 +462,7 @@ export async function assembleTimelineItem(
|
|
|
461
462
|
threadRootId: string,
|
|
462
463
|
options?: { isAuthenticated?: boolean },
|
|
463
464
|
): Promise<TimelineItemView | null> {
|
|
464
|
-
const
|
|
465
|
+
const listedForReader = !(options?.isAuthenticated ?? false);
|
|
465
466
|
const post = await c.var.services.posts.getById(threadRootId);
|
|
466
467
|
|
|
467
468
|
if (
|
|
@@ -469,7 +470,7 @@ export async function assembleTimelineItem(
|
|
|
469
470
|
post.replyToId !== null ||
|
|
470
471
|
post.status !== "published" ||
|
|
471
472
|
post.visibility === "latest_hidden" ||
|
|
472
|
-
(
|
|
473
|
+
(listedForReader && !isListedForReader(post.visibility))
|
|
473
474
|
) {
|
|
474
475
|
return null;
|
|
475
476
|
}
|
|
@@ -492,19 +493,19 @@ export async function assembleFeaturedTimeline(
|
|
|
492
493
|
const pageSize = c.var.appConfig.pageSize;
|
|
493
494
|
const page = Math.max(1, options?.page ?? 1);
|
|
494
495
|
const offset = (page - 1) * pageSize;
|
|
495
|
-
const
|
|
496
|
+
const listedForReader = !(options?.isAuthenticated ?? false);
|
|
496
497
|
|
|
497
498
|
const lang = viewLangFilter(c);
|
|
498
499
|
|
|
499
500
|
const [totalCount, rootIds] = await Promise.all([
|
|
500
501
|
c.var.services.posts.countFeaturedThreadRoots({
|
|
501
502
|
status: "published",
|
|
502
|
-
|
|
503
|
+
listedForReader,
|
|
503
504
|
lang,
|
|
504
505
|
}),
|
|
505
506
|
c.var.services.posts.listFeaturedThreadRootIds({
|
|
506
507
|
status: "published",
|
|
507
|
-
|
|
508
|
+
listedForReader,
|
|
508
509
|
lang,
|
|
509
510
|
limit: pageSize,
|
|
510
511
|
offset,
|
|
@@ -562,7 +563,7 @@ export async function assembleCollectionTimeline(
|
|
|
562
563
|
const pageSize = c.var.appConfig.pageSize;
|
|
563
564
|
const page = Math.max(1, options.page ?? 1);
|
|
564
565
|
const offset = (page - 1) * pageSize;
|
|
565
|
-
const
|
|
566
|
+
const listedForReader = !(options.isAuthenticated ?? false);
|
|
566
567
|
const lang = viewLangFilter(c);
|
|
567
568
|
|
|
568
569
|
const [totalCount, rootIds] = await Promise.all([
|
|
@@ -570,7 +571,7 @@ export async function assembleCollectionTimeline(
|
|
|
570
571
|
options.collectionIds,
|
|
571
572
|
{
|
|
572
573
|
status: "published",
|
|
573
|
-
|
|
574
|
+
listedForReader,
|
|
574
575
|
lang,
|
|
575
576
|
},
|
|
576
577
|
),
|
|
@@ -578,7 +579,7 @@ export async function assembleCollectionTimeline(
|
|
|
578
579
|
options.collectionIds,
|
|
579
580
|
{
|
|
580
581
|
status: "published",
|
|
581
|
-
|
|
582
|
+
listedForReader,
|
|
582
583
|
lang,
|
|
583
584
|
sortOrder: options.sortOrder,
|
|
584
585
|
limit: pageSize,
|
package/src/lib/tiptap-render.ts
CHANGED
|
@@ -318,6 +318,7 @@ function renderDocumentContent(
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
const MARK_RENDERERS: Record<string, MarkRenderer> = {
|
|
321
|
+
highlight: (html) => `<mark>${html}</mark>`,
|
|
321
322
|
bold: (html) => `<strong>${html}</strong>`,
|
|
322
323
|
italic: (html) => `<em>${html}</em>`,
|
|
323
324
|
strike: (html) => `<s>${html}</s>`,
|
package/src/lib/upload.ts
CHANGED
|
@@ -684,12 +684,32 @@ export function generateSiteAssetStorageKey(
|
|
|
684
684
|
return { id, filename, storageKey };
|
|
685
685
|
}
|
|
686
686
|
|
|
687
|
+
/**
|
|
688
|
+
* Where a video's poster is stored.
|
|
689
|
+
*
|
|
690
|
+
* Posters are served `immutable`, so a replacement cannot reuse the key the
|
|
691
|
+
* poster it replaces had: caches would go on serving the old still. A
|
|
692
|
+
* replacement passes a `version`, which makes the key new.
|
|
693
|
+
*
|
|
694
|
+
* @param siteId - Owning site ID
|
|
695
|
+
* @param mediaId - The video's media ID
|
|
696
|
+
* @param ext - Poster file extension
|
|
697
|
+
* @param version - Distinguishes a replacement from the poster before it
|
|
698
|
+
* @returns The storage key
|
|
699
|
+
* @example
|
|
700
|
+
* ```ts
|
|
701
|
+
* getPosterStorageKey("sit_1", "med_1", "webp"); // "media/sit_1/posters/med_1.webp"
|
|
702
|
+
* getPosterStorageKey("sit_1", "med_1", "png", "k3x9"); // "media/sit_1/posters/med_1-k3x9.png"
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
687
705
|
export function getPosterStorageKey(
|
|
688
706
|
siteId: string,
|
|
689
707
|
mediaId: string,
|
|
690
708
|
ext = "webp",
|
|
709
|
+
version?: string,
|
|
691
710
|
): string {
|
|
692
|
-
|
|
711
|
+
const name = version ? `${mediaId}-${version}` : mediaId;
|
|
712
|
+
return `${MEDIA_ROOT_PREFIX}/${siteId}/${MEDIA_POSTERS_STORAGE_PREFIX}/${name}.${ext}`;
|
|
693
713
|
}
|
|
694
714
|
|
|
695
715
|
export function getTemporaryUploadStorageKey(
|