@gobing-ai/knowledge-kit 0.1.23 → 0.1.24
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/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +117 -56
- package/package.json +5 -5
- package/plugins/generations/content-gen/dist/index.js +9 -9
- package/plugins/generations/core-facts-gen/dist/index.js +12 -12
- package/plugins/generations/daily-article-gen/dist/index.js +12 -12
- package/plugins/generations/dailynews-gen/dist/index.js +11 -11
- package/plugins/generations/dailynews-gen/src/script-plan.ts +2 -2
- package/plugins/generations/episode-plan-gen/dist/index.js +12 -12
- package/plugins/generations/gemini-tts/dist/index.js +9 -9
- package/plugins/generations/image-gen/dist/index.js +9 -9
- package/plugins/generations/music-gen/dist/index.js +16 -16
- package/plugins/generations/news-report-gen/dist/index.js +12 -12
- package/plugins/generations/vibe-voice-tts/dist/index.js +9 -9
- package/plugins/generations/voice-gen/dist/index.js +9 -9
- package/plugins/generations/voxcpm-tts/dist/index.js +9 -9
- package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
- package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
- package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
- package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
- package/plugins/ingestions/web-search/dist/index.js +10 -10
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
- package/plugins/kk/scripts/cover-compositor.ts +104 -26
- package/plugins/kk/scripts/daily-stages.ts +217 -33
- package/plugins/kk/scripts/kk-workflow-stages.ts +144 -6
- package/plugins/kk/scripts/series-names.ts +16 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +1 -1
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
- package/plugins/kk/workflows/kk-news-generate.yaml +3 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +22 -22
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/index.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/csdn-pub/dist/index.js +22 -22
- package/plugins/publishings/csdn-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/emdash-pub/dist/index.js +9 -9
- package/plugins/publishings/infoq-pub/dist/index.js +22 -22
- package/plugins/publishings/infoq-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/jike-pub/dist/index.js +22 -22
- package/plugins/publishings/jike-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/juejin-pub/dist/index.js +22 -22
- package/plugins/publishings/juejin-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/linkedin-pub/dist/index.js +82 -24
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/linkedin-pub/src/index.ts +93 -6
- package/plugins/publishings/medium-pub/dist/index.js +9 -9
- package/plugins/publishings/podcast-pub/dist/index.js +240 -37
- package/plugins/publishings/podcast-pub/src/index.ts +154 -3
- package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
- package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
- package/plugins/publishings/qiita-pub/dist/index.js +9 -9
- package/plugins/publishings/shipinhao-pub/dist/index.js +23 -23
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +23 -23
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +2 -1
- package/plugins/publishings/sspai-pub/dist/index.js +22 -22
- package/plugins/publishings/sspai-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/substack-pub/dist/index.js +22 -22
- package/plugins/publishings/substack-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/surfdash-pub/dist/index.js +200 -92
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +94 -75
- package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
- package/plugins/publishings/surfdash-pub/src/patch.ts +28 -23
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
- package/plugins/publishings/threads-pub/dist/index.js +36 -22
- package/plugins/publishings/threads-pub/dist/profile-check.js +27 -22
- package/plugins/publishings/threads-pub/src/post-rail.ts +20 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +180 -64
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +56 -10
- package/plugins/publishings/wechatmp-pub/src/flow.ts +155 -43
- package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
- package/plugins/publishings/weibo-pub/dist/index.js +22 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/dist/index.js +51 -45
- package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/src/post-rail.ts +40 -47
- package/plugins/publishings/xhs-pub/dist/index.js +22 -22
- package/plugins/publishings/xhs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/zenn-pub/dist/index.js +9 -9
|
@@ -36,7 +36,15 @@ import {
|
|
|
36
36
|
warn,
|
|
37
37
|
} from './seo';
|
|
38
38
|
import { renderShowNotesMarkdown, type ShowNotesRenderOptions } from './show-notes';
|
|
39
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
applyArticleReceipt,
|
|
41
|
+
articleUrlFromPostPath,
|
|
42
|
+
planCards,
|
|
43
|
+
renderBriefShowNotes,
|
|
44
|
+
renderCardsRegion,
|
|
45
|
+
stripArticlePlaceholderHtml,
|
|
46
|
+
upsertArticleLinkHtml,
|
|
47
|
+
} from './show-notes-brief';
|
|
40
48
|
import { buildTranscriptSegments, renderWebVtt, resolveTranscriptConfig, transcriptReferences } from './transcript';
|
|
41
49
|
|
|
42
50
|
/** Result target name for this plugin. */
|
|
@@ -56,7 +64,17 @@ export function publicItemUrl(item: MicrofeedItem | undefined, itemId: string, c
|
|
|
56
64
|
const TARGET = 'podcast-pub';
|
|
57
65
|
|
|
58
66
|
/** Management operations routed via `options.operation` (design D5). */
|
|
59
|
-
const OPERATIONS = [
|
|
67
|
+
const OPERATIONS = [
|
|
68
|
+
'publish',
|
|
69
|
+
'show-notes',
|
|
70
|
+
'list',
|
|
71
|
+
'get',
|
|
72
|
+
'update',
|
|
73
|
+
'delete',
|
|
74
|
+
'validate',
|
|
75
|
+
'backfill-seo',
|
|
76
|
+
'patch-article-link',
|
|
77
|
+
] as const;
|
|
60
78
|
type Operation = (typeof OPERATIONS)[number];
|
|
61
79
|
|
|
62
80
|
/** Target-specific options carried on the invoke payload. */
|
|
@@ -71,6 +89,10 @@ interface PodcastPubOptions {
|
|
|
71
89
|
title?: unknown;
|
|
72
90
|
runDate?: unknown;
|
|
73
91
|
articleBaseUrl?: unknown;
|
|
92
|
+
/** Explicit hosted article URL for `patch-article-link`. */
|
|
93
|
+
articleUrl?: unknown;
|
|
94
|
+
/** Surfdash publish result `metadata.postPath` (briefMode & `patch-article-link` URL source). */
|
|
95
|
+
postPath?: unknown;
|
|
74
96
|
/** Brief/timeline render flag (task 0118). */
|
|
75
97
|
briefMode?: unknown;
|
|
76
98
|
/** Surfdash publish result `metadata.postPath` (briefMode URL source). */
|
|
@@ -746,6 +768,127 @@ async function recordCorrectionDelivery(
|
|
|
746
768
|
};
|
|
747
769
|
}
|
|
748
770
|
|
|
771
|
+
/**
|
|
772
|
+
* Uploads rendered local card PNGs to microfeed R2 and rewrites `<!--kk:cards-->` with their
|
|
773
|
+
* hosted HTTPS URLs before show-notes HTML renders. Per-card failures degrade to text captions +
|
|
774
|
+
* a warning without aborting episode publish.
|
|
775
|
+
*/
|
|
776
|
+
async function hydrateShowNotesCards(client: MicrofeedClient, content: Content, warnings: string[]): Promise<Content> {
|
|
777
|
+
const metadata = content.metadata ?? {};
|
|
778
|
+
const podcastMeta =
|
|
779
|
+
metadata.podcast !== null && typeof metadata.podcast === 'object' && !Array.isArray(metadata.podcast)
|
|
780
|
+
? (metadata.podcast as Record<string, unknown>)
|
|
781
|
+
: undefined;
|
|
782
|
+
const rawCards = podcastMeta?.cards ?? metadata.cards;
|
|
783
|
+
if (rawCards === undefined) return content;
|
|
784
|
+
|
|
785
|
+
const showNotes = typeof metadata.showNotes === 'string' ? metadata.showNotes : '';
|
|
786
|
+
const usesShowNotes = showNotes.includes('<!--kk:cards-->');
|
|
787
|
+
const sourceMarkdown = usesShowNotes ? showNotes : content.body;
|
|
788
|
+
if (!sourceMarkdown.includes('<!--kk:cards-->')) return content;
|
|
789
|
+
|
|
790
|
+
const { cards } = planCards(rawCards);
|
|
791
|
+
if (cards.length === 0) return content;
|
|
792
|
+
|
|
793
|
+
let uploadedAny = false;
|
|
794
|
+
const hydrated = await Promise.all(
|
|
795
|
+
cards.map(async (card) => {
|
|
796
|
+
if (card.imageUrl !== '' || !card.imagePath) return card;
|
|
797
|
+
const ext = extname(card.imagePath).toLowerCase();
|
|
798
|
+
const mime = COVER_MIME[ext];
|
|
799
|
+
if (!mime) {
|
|
800
|
+
warn(`card ${card.index} upload skipped: unsupported extension "${ext}"`, warnings);
|
|
801
|
+
return card;
|
|
802
|
+
}
|
|
803
|
+
try {
|
|
804
|
+
const bytes = new Uint8Array(await readFile(card.imagePath));
|
|
805
|
+
const prepared = await client.prepareUpload({
|
|
806
|
+
category: 'image',
|
|
807
|
+
full_local_file_path: basename(card.imagePath),
|
|
808
|
+
size: bytes.byteLength,
|
|
809
|
+
type: mime,
|
|
810
|
+
});
|
|
811
|
+
await client.uploadBytes(prepared.presignedUrl, bytes, mime);
|
|
812
|
+
uploadedAny = true;
|
|
813
|
+
return { ...card, imageUrl: prepared.mediaUrl };
|
|
814
|
+
} catch (error: unknown) {
|
|
815
|
+
warn(
|
|
816
|
+
`card ${card.index} upload failed (${error instanceof Error ? error.message : String(error)}); keeping text caption`,
|
|
817
|
+
warnings,
|
|
818
|
+
);
|
|
819
|
+
return card;
|
|
820
|
+
}
|
|
821
|
+
}),
|
|
822
|
+
);
|
|
823
|
+
if (!uploadedAny) return content;
|
|
824
|
+
|
|
825
|
+
const region = renderCardsRegion(hydrated);
|
|
826
|
+
const updatedMarkdown = sourceMarkdown.replace(/<!--kk:cards-->[\s\S]*?<!--\/kk:cards-->/, () => region);
|
|
827
|
+
if (usesShowNotes) {
|
|
828
|
+
return {
|
|
829
|
+
...content,
|
|
830
|
+
metadata: {
|
|
831
|
+
...metadata,
|
|
832
|
+
showNotes: updatedMarkdown,
|
|
833
|
+
},
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
return {
|
|
837
|
+
...content,
|
|
838
|
+
body: updatedMarkdown,
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Patches the published `完整图文版` link onto an existing microfeed episode item idempotently.
|
|
844
|
+
*/
|
|
845
|
+
async function patchArticleLink(client: MicrofeedClient, options: PodcastPubOptions): Promise<Result> {
|
|
846
|
+
const itemId = resolveItemId(options);
|
|
847
|
+
if ('error' in itemId) return fail(itemId.error);
|
|
848
|
+
const baseUrl =
|
|
849
|
+
typeof options.articleBaseUrl === 'string' && options.articleBaseUrl.trim() !== ''
|
|
850
|
+
? options.articleBaseUrl.trim()
|
|
851
|
+
: 'https://surfing.salty.vip';
|
|
852
|
+
const explicitUrl = typeof options.articleUrl === 'string' ? options.articleUrl.trim() : '';
|
|
853
|
+
const postPath =
|
|
854
|
+
typeof options.articlePostPath === 'string' && options.articlePostPath.trim() !== ''
|
|
855
|
+
? options.articlePostPath.trim()
|
|
856
|
+
: typeof options.postPath === 'string'
|
|
857
|
+
? options.postPath.trim()
|
|
858
|
+
: '';
|
|
859
|
+
const articleUrl = /^https?:\/\//i.test(explicitUrl)
|
|
860
|
+
? explicitUrl
|
|
861
|
+
: postPath !== ''
|
|
862
|
+
? articleUrlFromPostPath(postPath, baseUrl)
|
|
863
|
+
: '';
|
|
864
|
+
if (!/^https?:\/\//i.test(articleUrl)) {
|
|
865
|
+
return fail('options.articleUrl or options.postPath is required for the "patch-article-link" operation');
|
|
866
|
+
}
|
|
867
|
+
const feed = await client.getItem(itemId.itemId);
|
|
868
|
+
const item = feed.items?.[0];
|
|
869
|
+
if (!item) return fail(`microfeed item "${itemId.itemId}" not found in the feed response`);
|
|
870
|
+
const currentHtml = typeof item.content_html === 'string' ? item.content_html : '';
|
|
871
|
+
const patched = upsertArticleLinkHtml(currentHtml, articleUrl);
|
|
872
|
+
let updatedItem = item;
|
|
873
|
+
if (patched.changed) {
|
|
874
|
+
updatedItem = await client.updateItem(itemId.itemId, { content_html: patched.html });
|
|
875
|
+
}
|
|
876
|
+
const itemUrl = publicItemUrl(updatedItem, itemId.itemId, client);
|
|
877
|
+
return ResultSchema.parse({
|
|
878
|
+
ok: true,
|
|
879
|
+
target: TARGET,
|
|
880
|
+
id: itemId.itemId,
|
|
881
|
+
url: itemUrl,
|
|
882
|
+
message: patched.changed
|
|
883
|
+
? `Patched article link into microfeed item ${itemId.itemId}`
|
|
884
|
+
: `Article link already present on microfeed item ${itemId.itemId}`,
|
|
885
|
+
metadata: {
|
|
886
|
+
changed: patched.changed,
|
|
887
|
+
articleUrl,
|
|
888
|
+
},
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
|
|
749
892
|
/**
|
|
750
893
|
* Two-phase publish (design D2, the only legal order): create a draft item →
|
|
751
894
|
* presign with `item_id` → PUT bytes → PUT item with attachment + target status.
|
|
@@ -765,7 +908,7 @@ async function publishEpisode(
|
|
|
765
908
|
// map.ts ambiguity guard is not tripped); absent keys leave the existing
|
|
766
909
|
// Content→episode mapping (map.ts) as the fallback, unchanged.
|
|
767
910
|
const { audioFile, coverPath, durationSec } = assembly.assembly;
|
|
768
|
-
const
|
|
911
|
+
const rawContent: Content =
|
|
769
912
|
audioFile !== undefined || coverPath !== undefined || durationSec !== undefined
|
|
770
913
|
? {
|
|
771
914
|
...payload.content,
|
|
@@ -778,6 +921,9 @@ async function publishEpisode(
|
|
|
778
921
|
}
|
|
779
922
|
: payload.content;
|
|
780
923
|
|
|
924
|
+
const cardWarnings: string[] = [];
|
|
925
|
+
const content = await hydrateShowNotesCards(client, rawContent, cardWarnings);
|
|
926
|
+
|
|
781
927
|
let episode: EpisodeMapping;
|
|
782
928
|
try {
|
|
783
929
|
episode = mapContentToEpisode(content);
|
|
@@ -790,6 +936,7 @@ async function publishEpisode(
|
|
|
790
936
|
const policy = prepareEpisodeFields(episode, content.metadata ?? {}, seoConfig.config);
|
|
791
937
|
if (!policy.ok) return fail(policy.error);
|
|
792
938
|
const fields = policy.fields;
|
|
939
|
+
if (cardWarnings.length > 0) fields.warnings.push(...cardWarnings);
|
|
793
940
|
// Transcript (PODCAST_PUB_TRANSCRIPT): built and written to disk before any create call so
|
|
794
941
|
// the `_microfeed` payload in both create branches carries the same field when it exists.
|
|
795
942
|
try {
|
|
@@ -806,6 +953,8 @@ async function publishEpisode(
|
|
|
806
953
|
}
|
|
807
954
|
const seo = mergeSocial(fields.seo, social);
|
|
808
955
|
episode = shapedEpisode(episode, fields);
|
|
956
|
+
// Never ship the pre-publish placeholder literal to public listeners on microfeed.
|
|
957
|
+
episode.contentHtml = stripArticlePlaceholderHtml(episode.contentHtml);
|
|
809
958
|
|
|
810
959
|
let localAudioBytes: Uint8Array | undefined;
|
|
811
960
|
let mediaIdentity: string;
|
|
@@ -1037,6 +1186,8 @@ export class PodcastPubTransport implements PublishTransport {
|
|
|
1037
1186
|
if ('error' in config) return fail(config.error);
|
|
1038
1187
|
return await runBackfill(client, options, config.config);
|
|
1039
1188
|
}
|
|
1189
|
+
case 'patch-article-link':
|
|
1190
|
+
return await patchArticleLink(client, options);
|
|
1040
1191
|
case 'validate': {
|
|
1041
1192
|
// Validate the caller-supplied item input, or the Content-mapped
|
|
1042
1193
|
// draft when no explicit input is given (server-side schema check).
|
|
@@ -671,7 +671,7 @@ export function buildSeoDescription(input: {
|
|
|
671
671
|
minutes?: number;
|
|
672
672
|
clauses: string[];
|
|
673
673
|
extraSentences: string[];
|
|
674
|
-
}): { description: string; short: boolean } {
|
|
674
|
+
}): { description: string; short: boolean; empty: boolean } {
|
|
675
675
|
const head = descriptionHead(input.config, input.date, input.minutes);
|
|
676
676
|
const render = (parts: string[]): string => (parts.length === 0 ? head : `${head}${parts.join(';')}。`);
|
|
677
677
|
const picked: string[] = [];
|
|
@@ -684,9 +684,21 @@ export function buildSeoDescription(input: {
|
|
|
684
684
|
}
|
|
685
685
|
};
|
|
686
686
|
pushWhile(input.clauses);
|
|
687
|
+
if (picked.length === 0 && input.clauses.length > 0) {
|
|
688
|
+
const first = cleanClause(input.clauses[0] ?? '');
|
|
689
|
+
const room = input.config.descriptionMax - codePointLength(`${head}。`);
|
|
690
|
+
if (first.length > 0 && room > 0) {
|
|
691
|
+
const cut = cutAtBoundary(first, room);
|
|
692
|
+
if (cut.length > 0) picked.push(cut);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
687
695
|
if (codePointLength(render(picked)) < input.config.descriptionMin) pushWhile(input.extraSentences);
|
|
688
696
|
const description = render(picked);
|
|
689
|
-
return {
|
|
697
|
+
return {
|
|
698
|
+
description,
|
|
699
|
+
short: codePointLength(description) < input.config.descriptionMin,
|
|
700
|
+
empty: picked.length === 0,
|
|
701
|
+
};
|
|
690
702
|
}
|
|
691
703
|
|
|
692
704
|
function descriptionInputs(
|
|
@@ -694,7 +706,7 @@ function descriptionInputs(
|
|
|
694
706
|
config: PodcastSeoConfig,
|
|
695
707
|
date: string | undefined,
|
|
696
708
|
minutes: number | undefined,
|
|
697
|
-
): { description: string; short: boolean } {
|
|
709
|
+
): { description: string; short: boolean; empty: boolean } {
|
|
698
710
|
const podcast = podcastOf(metadata);
|
|
699
711
|
const plan = planItemsFromMetadata(metadata);
|
|
700
712
|
const summary = stringList(podcast.summaryClauses);
|
|
@@ -882,12 +894,17 @@ export function prepareEpisodeFields(
|
|
|
882
894
|
const seoTitle = mustSanitize(fitted.seo, config.titleSanitize, 'seo.title');
|
|
883
895
|
if (!seoTitle.ok) return seoTitle;
|
|
884
896
|
const described = descriptionInputs(metadata, config, date, minutes);
|
|
885
|
-
if (described.
|
|
886
|
-
warnings.push(
|
|
887
|
-
|
|
888
|
-
|
|
897
|
+
if (described.empty) {
|
|
898
|
+
warnings.push(`${WARN_PREFIX} seo.description skipped: no summary clauses available`);
|
|
899
|
+
seo = { title: seoTitle.value };
|
|
900
|
+
} else {
|
|
901
|
+
if (described.short) {
|
|
902
|
+
warnings.push(
|
|
903
|
+
`${WARN_PREFIX} seo.description is ${codePointLength(described.description)} code points, under the ${config.descriptionMin} minimum; left unpadded`,
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
seo = { title: seoTitle.value, description: described.description };
|
|
889
907
|
}
|
|
890
|
-
seo = { title: seoTitle.value, description: described.description };
|
|
891
908
|
}
|
|
892
909
|
let slug: string | undefined;
|
|
893
910
|
if (config.slugMode === 'pattern') {
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import type { Doc } from '@gobing-ai/kk-core';
|
|
21
|
-
import { computeAudioOffsets, escapeHtml, formatOffset, itemBrief, sourceLabelFor } from './show-notes';
|
|
21
|
+
import { computeAudioOffsets, escapeHtml, formatOffset, itemBrief, sourceLabelFor, TIMELINE_STYLE } from './show-notes';
|
|
22
22
|
|
|
23
23
|
/** Placeholder paragraph {@link applyArticleReceipt} rewrites once the article receipt exists. */
|
|
24
|
-
const ARTICLE_PLACEHOLDER = '<p class="kk-tl-more">完整图文版:待文章发布回执</p>';
|
|
24
|
+
export const ARTICLE_PLACEHOLDER = '<p class="kk-tl-more">完整图文版:待文章发布回执</p>';
|
|
25
25
|
|
|
26
26
|
/** The exact `<style>` block {@link renderCardsRegion} emits (reused by the marker validator). */
|
|
27
27
|
export const CARDS_STYLE = `<style>
|
|
28
|
-
.kk-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:
|
|
29
|
-
.kk-card{margin:0;border:1px solid rgba(128,128,128,.25);border-radius:10px;overflow:hidden}
|
|
28
|
+
.kk-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:1.25em 0 0}
|
|
29
|
+
.kk-card{margin:0;border:1px solid var(--mf-border,rgba(128,128,128,.25));border-radius:10px;overflow:hidden;background:var(--mf-surface,transparent)}
|
|
30
30
|
.kk-card img{display:block;width:100%;height:auto}
|
|
31
|
-
.kk-card figcaption{padding:8px 10px;font-size:.9em;color
|
|
32
|
-
.kk-card-n{font-weight:700;color
|
|
31
|
+
.kk-card figcaption{padding:8px 10px;font-size:.9em;color:var(--mf-muted,#444)}
|
|
32
|
+
.kk-card-n{font-weight:700;color:var(--mf-accent,#0969da);margin-right:6px}
|
|
33
33
|
@media (max-width:420px){.kk-cards{grid-template-columns:1fr}}
|
|
34
34
|
</style>`;
|
|
35
35
|
|
|
@@ -41,6 +41,8 @@ export interface PlannedCard {
|
|
|
41
41
|
alt: string;
|
|
42
42
|
/** Hosted image URL from the upload receipt, or `''` when no asset is available. */
|
|
43
43
|
imageUrl: string;
|
|
44
|
+
/** Optional rendered local PNG/image path for upload during episode publish. */
|
|
45
|
+
imagePath?: string;
|
|
44
46
|
/** Plain-text degradation: the card's copy (or its source point). */
|
|
45
47
|
text: string;
|
|
46
48
|
}
|
|
@@ -101,7 +103,15 @@ export function planCards(raw: unknown): { cards: PlannedCard[]; diagnostics: Ca
|
|
|
101
103
|
const copy = textOf(card.copy);
|
|
102
104
|
const sourcePoint = textOf(card.sourcePoint);
|
|
103
105
|
const alt = textOf(card.alt) || copy || sourcePoint || `本期卡片 ${index}`;
|
|
104
|
-
|
|
106
|
+
const rawImagePath = textOf(card.imagePath);
|
|
107
|
+
const imagePath = textOf(card.status) === 'rendered' && rawImagePath !== '' ? rawImagePath : undefined;
|
|
108
|
+
cards.push({
|
|
109
|
+
index,
|
|
110
|
+
alt,
|
|
111
|
+
imageUrl: uploadStatus === 'failed' ? '' : url,
|
|
112
|
+
...(imagePath !== undefined ? { imagePath } : {}),
|
|
113
|
+
text: copy || sourcePoint || alt,
|
|
114
|
+
});
|
|
105
115
|
});
|
|
106
116
|
return { cards, diagnostics };
|
|
107
117
|
}
|
|
@@ -176,6 +186,7 @@ export function renderBriefShowNotes(input: BriefShowNotesInput): { markdown: st
|
|
|
176
186
|
`<!--kk:timeline-->
|
|
177
187
|
<div class="kk-tl">${rows}
|
|
178
188
|
</div>
|
|
189
|
+
${TIMELINE_STYLE}
|
|
179
190
|
${articleEntry}
|
|
180
191
|
<!--/kk:timeline-->`,
|
|
181
192
|
'',
|
|
@@ -186,8 +197,22 @@ ${articleEntry}
|
|
|
186
197
|
return { markdown: lines.join('\n'), diagnostics };
|
|
187
198
|
}
|
|
188
199
|
|
|
200
|
+
/** Formats `<base>/<locale>/posts/<slug>` from a published surfdash `postPath`. Returns `''` if invalid. */
|
|
201
|
+
export function articleUrlFromPostPath(postPath: string, articleBaseUrl = 'https://surfing.salty.vip'): string {
|
|
202
|
+
const trimmed = postPath.trim();
|
|
203
|
+
if (trimmed === '') return '';
|
|
204
|
+
const segments = trimmed.split(/[\\/]/).filter((s) => s.length > 0);
|
|
205
|
+
// `<…>/posts/<locale>/<slug>/index.md` — the slug is the path segment before the file.
|
|
206
|
+
const slug = segments.length >= 2 ? (segments[segments.length - 2] ?? '') : '';
|
|
207
|
+
if (slug === '' || slug === 'posts') return '';
|
|
208
|
+
const locale = segments.find((s) => ['zh', 'en', 'ja'].includes(s)) ?? 'zh';
|
|
209
|
+
// surfdash serves `en` at the root; zh/ja carry the locale prefix (surfdash/src/lib/seo.ts).
|
|
210
|
+
const prefix = locale === 'en' ? '' : `/${locale}`;
|
|
211
|
+
return `${articleBaseUrl.replace(/\/+$/, '')}${prefix}/posts/${slug}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
189
214
|
/** The hosted article slug a publish receipt proves, or `''` when the receipt proves nothing. */
|
|
190
|
-
function
|
|
215
|
+
function receiptArticleUrl(receipt: unknown, articleBaseUrl = 'https://surfing.salty.vip'): string {
|
|
191
216
|
const entries = Array.isArray(receipt)
|
|
192
217
|
? receipt
|
|
193
218
|
: receipt !== null && typeof receipt === 'object' && Array.isArray((receipt as { targets?: unknown }).targets)
|
|
@@ -205,15 +230,67 @@ function receiptSlug(receipt: unknown): string {
|
|
|
205
230
|
: record;
|
|
206
231
|
const postPath = textOf(metadata.postPath);
|
|
207
232
|
if (postPath === '') continue;
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const slug = segments.length >= 2 ? (segments[segments.length - 2] ?? '') : '';
|
|
211
|
-
if (slug !== '' && slug !== 'posts')
|
|
212
|
-
return `${slug}\u0000${segments.find((s) => ['zh', 'en', 'ja'].includes(s)) ?? 'zh'}`;
|
|
233
|
+
const url = articleUrlFromPostPath(postPath, articleBaseUrl);
|
|
234
|
+
if (url !== '') return url;
|
|
213
235
|
}
|
|
214
236
|
return '';
|
|
215
237
|
}
|
|
216
238
|
|
|
239
|
+
/** Renders the `<p class="kk-tl-more">` paragraph linking to the full illustrated article. */
|
|
240
|
+
export function renderArticleLinkParagraph(articleUrl: string): string {
|
|
241
|
+
return `<p class="kk-tl-more">完整图文版:<a href="${escapeHtml(articleUrl.trim())}" target="_blank" rel="noopener">本期完整文章</a></p>`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Strips unresolved {@link ARTICLE_PLACEHOLDER} before public microfeed publish so listeners do
|
|
246
|
+
* not see an internal placeholder string when article publish hasn't landed yet.
|
|
247
|
+
*/
|
|
248
|
+
export function stripArticlePlaceholderHtml(html: string): string {
|
|
249
|
+
if (!html.includes(ARTICLE_PLACEHOLDER)) return html;
|
|
250
|
+
return html
|
|
251
|
+
.replace(ARTICLE_PLACEHOLDER, '')
|
|
252
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
253
|
+
.trim();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Inserts or replaces the `完整图文版` link inside published microfeed `content_html`, placing it
|
|
258
|
+
* before the `.kk-cards` block (or at the end when there are no cards). Idempotent once linked.
|
|
259
|
+
*/
|
|
260
|
+
export function upsertArticleLinkHtml(html: string, articleUrl: string): { html: string; changed: boolean } {
|
|
261
|
+
if (!isHttpUrl(articleUrl)) return { html, changed: false };
|
|
262
|
+
const cleanUrl = articleUrl.trim();
|
|
263
|
+
const linkParagraph = renderArticleLinkParagraph(cleanUrl);
|
|
264
|
+
if (html.includes(escapeHtml(cleanUrl)) && /完整图文版/.test(html)) {
|
|
265
|
+
return { html, changed: false };
|
|
266
|
+
}
|
|
267
|
+
if (html.includes(ARTICLE_PLACEHOLDER)) {
|
|
268
|
+
return { html: html.replace(ARTICLE_PLACEHOLDER, linkParagraph), changed: true };
|
|
269
|
+
}
|
|
270
|
+
const existingPattern = /<p class="kk-tl-more">完整图文版:[\s\S]*?<\/p>/;
|
|
271
|
+
if (existingPattern.test(html)) {
|
|
272
|
+
return { html: html.replace(existingPattern, linkParagraph), changed: true };
|
|
273
|
+
}
|
|
274
|
+
// Insert right before the card block `<style>` (when present) or `<div class="kk-cards">` so
|
|
275
|
+
// it appears right under the timeline, matching renderBriefShowNotes.
|
|
276
|
+
const cardsStyleIdx = html.indexOf(CARDS_STYLE);
|
|
277
|
+
const cardsDivIdx = html.indexOf('<div class="kk-cards">');
|
|
278
|
+
const anchor = cardsStyleIdx >= 0 ? cardsStyleIdx : cardsDivIdx;
|
|
279
|
+
if (anchor >= 0) {
|
|
280
|
+
const before = html.slice(0, anchor).replace(/\s*$/, '');
|
|
281
|
+
const after = html.slice(anchor).replace(/^\s*/, '');
|
|
282
|
+
return {
|
|
283
|
+
html: before === '' ? `${linkParagraph}\n${after}` : `${before}\n${linkParagraph}\n${after}`,
|
|
284
|
+
changed: true,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const trimmed = html.trim();
|
|
288
|
+
return {
|
|
289
|
+
html: trimmed === '' ? linkParagraph : `${trimmed}\n${linkParagraph}`,
|
|
290
|
+
changed: true,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
217
294
|
/**
|
|
218
295
|
* Enriches already-rendered notes with the article link **once a real receipt exists**: the
|
|
219
296
|
* placeholder paragraph is replaced by the linked one derived from the receipt's `postPath`
|
|
@@ -224,17 +301,10 @@ export function applyArticleReceipt(
|
|
|
224
301
|
receipt: unknown,
|
|
225
302
|
articleBaseUrl = 'https://surfing.salty.vip',
|
|
226
303
|
): { markdown: string; enriched: boolean } {
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
const [slug = '', locale = 'zh'] = proven.split('\u0000');
|
|
230
|
-
// surfdash serves `en` at the root; zh/ja carry the locale prefix (surfdash/src/lib/seo.ts).
|
|
231
|
-
const prefix = locale === 'en' ? '' : `/${locale}`;
|
|
232
|
-
const url = `${articleBaseUrl.replace(/\/+$/, '')}${prefix}/posts/${slug}`;
|
|
304
|
+
const url = receiptArticleUrl(receipt, articleBaseUrl);
|
|
305
|
+
if (url === '' || !markdown.includes(ARTICLE_PLACEHOLDER)) return { markdown, enriched: false };
|
|
233
306
|
return {
|
|
234
|
-
markdown: markdown.replace(
|
|
235
|
-
ARTICLE_PLACEHOLDER,
|
|
236
|
-
`<p class="kk-tl-more">完整图文版:<a href="${escapeHtml(url)}" target="_blank" rel="noopener">本期完整文章</a></p>`,
|
|
237
|
-
),
|
|
307
|
+
markdown: markdown.replace(ARTICLE_PLACEHOLDER, renderArticleLinkParagraph(url)),
|
|
238
308
|
enriched: true,
|
|
239
309
|
};
|
|
240
310
|
}
|
|
@@ -106,8 +106,8 @@ export function computeAudioOffsets(
|
|
|
106
106
|
|
|
107
107
|
const isHttpUrl = (u: string): boolean => /^https?:\/\//i.test(u.trim());
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
const
|
|
109
|
+
/** Previous `<style>` block accepted for backward compatibility in {@link isGeneratedTimeline}. */
|
|
110
|
+
const LEGACY_TIMELINE_STYLE = `<style>
|
|
111
111
|
.kk-tl{margin:1em 0}
|
|
112
112
|
.kk-tl-row{display:flex;gap:12px;padding:10px 0;border-bottom:1px solid rgba(128,128,128,.25)}
|
|
113
113
|
.kk-tl-t{flex:0 0 56px;font-variant-numeric:tabular-nums;font-weight:700;color:#0969da}
|
|
@@ -117,11 +117,31 @@ const TIMELINE_STYLE = `<style>
|
|
|
117
117
|
</style>`;
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
120
|
+
* The exact vertical-axis `<style>` block emitted by {@link renderTimelineHtml} and
|
|
121
|
+
* {@link renderBriefShowNotes}; reused by the marker validator. Left column holds time offsets,
|
|
122
|
+
* the center border + node dot draws the vertical axis, and the right column holds story summary.
|
|
123
|
+
*/
|
|
124
|
+
export const TIMELINE_STYLE = `<style>
|
|
125
|
+
.kk-tl{margin:1.25em 0;padding:0}
|
|
126
|
+
.kk-tl-row{display:flex;align-items:stretch;gap:0}
|
|
127
|
+
.kk-tl-t{flex:0 0 58px;padding:2px 14px 18px 0;text-align:right;font-variant-numeric:tabular-nums;font-weight:700;font-size:.92em;line-height:1.5;color:var(--mf-accent,#e34b4b)}
|
|
128
|
+
.kk-tl-body{position:relative;flex:1;min-width:0;padding:0 0 18px 18px;border-left:2px solid var(--mf-border,rgba(128,128,128,.35))}
|
|
129
|
+
.kk-tl-row:last-child .kk-tl-body{border-left-color:transparent;padding-bottom:4px}
|
|
130
|
+
.kk-tl-body::before{content:"";position:absolute;left:-6px;top:.42em;width:10px;height:10px;border-radius:50%;background:var(--mf-accent,#e34b4b);box-shadow:0 0 0 3px var(--mf-background,#fff)}
|
|
131
|
+
.kk-tl-title{font-weight:600;line-height:1.5}
|
|
132
|
+
.kk-tl-title a,.kk-tl-src{font-weight:400;font-size:.86em;margin-left:6px;color:var(--mf-muted,#666)}
|
|
133
|
+
.kk-tl-brief{margin:5px 0 0;color:var(--mf-muted,#666);font-size:.94em;line-height:1.65}
|
|
134
|
+
.kk-tl-more{margin:1.1em 0 0;font-size:.95em}
|
|
135
|
+
@media (max-width:480px){.kk-tl-t{flex:0 0 46px;padding-right:10px;font-size:.86em}.kk-tl-body{padding-left:14px}}
|
|
136
|
+
</style>`;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Tags {@link renderTimelineHtml} / {@link renderBriefShowNotes} can emit: `div`/`p`/`a`/`span`
|
|
140
|
+
* carrying only the exact class, href, target, and rel attributes they produce. Anything else inside
|
|
141
|
+
* a marker block is attacker-supplied.
|
|
122
142
|
*/
|
|
123
143
|
const TIMELINE_TAG =
|
|
124
|
-
/^<\/?(?:div|p|a)(?:\s+(?:class="kk-tl(?:-[a-z]+)?"|href="https?:\/\/[^"<>\s]*"|target="_blank"|rel="noopener"))*\s*>$/;
|
|
144
|
+
/^<\/?(?:div|p|a|span)(?:\s+(?:class="kk-tl(?:-[a-z]+)?"|href="https?:\/\/[^"<>\s]*"|target="_blank"|rel="noopener"))*\s*>$/;
|
|
125
145
|
|
|
126
146
|
/**
|
|
127
147
|
* A marker block is trusted only if it is markup {@link renderTimelineHtml} could have produced.
|
|
@@ -130,7 +150,7 @@ const TIMELINE_TAG =
|
|
|
130
150
|
* and any leftover stray `<` means the block is not well-formed generator output.
|
|
131
151
|
*/
|
|
132
152
|
function isGeneratedTimeline(block: string): boolean {
|
|
133
|
-
const rest = block.replace(TIMELINE_STYLE, '');
|
|
153
|
+
const rest = block.replace(TIMELINE_STYLE, '').replace(LEGACY_TIMELINE_STYLE, '');
|
|
134
154
|
if (rest.includes('<style') || rest.includes('<!--')) return false;
|
|
135
155
|
return (rest.match(/<[^>]*>/g) ?? []).every((tag) => TIMELINE_TAG.test(tag)) && !/<(?![^>]*>)/.test(rest);
|
|
136
156
|
}
|
|
@@ -4813,7 +4813,7 @@ var init_zod = __esm(() => {
|
|
|
4813
4813
|
init_external();
|
|
4814
4814
|
});
|
|
4815
4815
|
|
|
4816
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4816
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/errors.js
|
|
4817
4817
|
var ErrorCode;
|
|
4818
4818
|
var init_errors3 = __esm(() => {
|
|
4819
4819
|
ErrorCode = {
|
|
@@ -4824,7 +4824,7 @@ var init_errors3 = __esm(() => {
|
|
|
4824
4824
|
};
|
|
4825
4825
|
});
|
|
4826
4826
|
|
|
4827
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4827
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/api-response.js
|
|
4828
4828
|
var API_ERROR_CODES, ERROR_CODE_TO_HTTP, CLIENT_SAFE_CODES;
|
|
4829
4829
|
var init_api_response = __esm(() => {
|
|
4830
4830
|
init_errors3();
|
|
@@ -4847,13 +4847,13 @@ var init_api_response = __esm(() => {
|
|
|
4847
4847
|
CLIENT_SAFE_CODES = new Set([ErrorCode.NotFound, ErrorCode.Validation, ErrorCode.Conflict]);
|
|
4848
4848
|
});
|
|
4849
4849
|
|
|
4850
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4850
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/cursor.js
|
|
4851
4851
|
var init_cursor = () => {};
|
|
4852
4852
|
|
|
4853
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4853
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
|
|
4854
4854
|
var init_event_severity = () => {};
|
|
4855
4855
|
|
|
4856
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4856
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/output.js
|
|
4857
4857
|
function processStream(name) {
|
|
4858
4858
|
const proc = globalThis.process;
|
|
4859
4859
|
const stream = proc?.[name];
|
|
@@ -4871,7 +4871,7 @@ function echoError(message, target = defaultStderrTarget ?? processStream("stder
|
|
|
4871
4871
|
}
|
|
4872
4872
|
var defaultStderrTarget;
|
|
4873
4873
|
|
|
4874
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4874
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/index.js
|
|
4875
4875
|
var init_dist = __esm(() => {
|
|
4876
4876
|
init_api_response();
|
|
4877
4877
|
init_cursor();
|
|
@@ -11869,7 +11869,7 @@ var init_dist2 = __esm(() => {
|
|
|
11869
11869
|
$visitAsync = visit.visitAsync;
|
|
11870
11870
|
});
|
|
11871
11871
|
|
|
11872
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
11872
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/config.js
|
|
11873
11873
|
var configSchema;
|
|
11874
11874
|
var init_config = __esm(() => {
|
|
11875
11875
|
init_dist2();
|
|
@@ -11893,7 +11893,7 @@ var init_config = __esm(() => {
|
|
|
11893
11893
|
});
|
|
11894
11894
|
});
|
|
11895
11895
|
|
|
11896
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
11896
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
|
|
11897
11897
|
import { appendFileSync, cpSync, createReadStream, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
11898
11898
|
import { dirname, resolve as resolvePath } from "path";
|
|
11899
11899
|
function createNodeFileSystem(root, paths) {
|
|
@@ -12248,7 +12248,7 @@ var PluginManifestSchema = PluginManifestSchemaBase.superRefine((manifest, ctx)
|
|
|
12248
12248
|
});
|
|
12249
12249
|
}
|
|
12250
12250
|
});
|
|
12251
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
12251
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/index.js
|
|
12252
12252
|
init_file_system_node();
|
|
12253
12253
|
init_config();
|
|
12254
12254
|
|