@gobing-ai/knowledge-kit 0.1.22 → 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 +282 -147
- 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 +56 -16
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/image-gen/dist/index.js +9 -9
- package/plugins/generations/music-gen/README.md +2 -2
- package/plugins/generations/music-gen/dist/index.js +62 -26
- package/plugins/generations/music-gen/presets/formats/song.yaml +6 -1
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +6 -1
- package/plugins/generations/music-gen/src/adapter/instance.ts +34 -11
- package/plugins/generations/music-gen/src/presets.ts +36 -3
- package/plugins/generations/news-report-gen/dist/index.js +12 -12
- package/plugins/generations/omni-voice-gen/uv.toml +5 -0
- package/plugins/generations/vibe-voice-tts/README.md +64 -0
- package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
- package/plugins/generations/vibe-voice-tts/package.json +16 -0
- package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
- package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
- package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
- package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
- package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
- package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
- package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
- package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
- package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
- package/plugins/generations/voice-gen/dist/index.js +40 -10
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +90 -18
- package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
- package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
- package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
- package/plugins/generations/voxcpm-tts/uv.toml +5 -0
- 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/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +12 -1
- package/plugins/kk/scripts/cover-compositor.ts +104 -26
- package/plugins/kk/scripts/daily-stages.ts +481 -63
- package/plugins/kk/scripts/kk-workflow-stages.ts +218 -17
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- 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-daily-ai-voice.yaml +4 -3
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -5
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +20 -16
- package/plugins/kk/workflows/kk-news-generate.yaml +26 -3
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- 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 +133 -33
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +27 -22
- package/plugins/publishings/linkedin-pub/src/index.ts +192 -18
- 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 +207 -95
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +101 -76
- package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
- package/plugins/publishings/surfdash-pub/src/patch.ts +49 -26
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
- package/plugins/publishings/threads-pub/dist/index.js +83 -27
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -23
- package/plugins/publishings/threads-pub/src/post-rail.ts +121 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +274 -98
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +117 -13
- package/plugins/publishings/wechatmp-pub/src/flow.ts +183 -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 +113 -32
- package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/src/post-rail.ts +155 -20
- 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
|
@@ -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];
|
|
@@ -4874,7 +4874,7 @@ function echoError(message, target = defaultStderrTarget ?? processStream("stder
|
|
|
4874
4874
|
}
|
|
4875
4875
|
var defaultStdoutTarget, defaultStderrTarget;
|
|
4876
4876
|
|
|
4877
|
-
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.
|
|
4877
|
+
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/index.js
|
|
4878
4878
|
var init_dist = __esm(() => {
|
|
4879
4879
|
init_api_response();
|
|
4880
4880
|
init_cursor();
|
|
@@ -11872,7 +11872,7 @@ var init_dist2 = __esm(() => {
|
|
|
11872
11872
|
$visitAsync = visit.visitAsync;
|
|
11873
11873
|
});
|
|
11874
11874
|
|
|
11875
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
11875
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/config.js
|
|
11876
11876
|
var configSchema;
|
|
11877
11877
|
var init_config = __esm(() => {
|
|
11878
11878
|
init_dist2();
|
|
@@ -11896,7 +11896,7 @@ var init_config = __esm(() => {
|
|
|
11896
11896
|
});
|
|
11897
11897
|
});
|
|
11898
11898
|
|
|
11899
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
11899
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
|
|
11900
11900
|
import { appendFileSync, cpSync, createReadStream, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
11901
11901
|
import { dirname, resolve as resolvePath } from "path";
|
|
11902
11902
|
function createNodeFileSystem(root, paths) {
|
|
@@ -12254,14 +12254,14 @@ var PluginManifestSchema = PluginManifestSchemaBase.superRefine((manifest, ctx)
|
|
|
12254
12254
|
});
|
|
12255
12255
|
}
|
|
12256
12256
|
});
|
|
12257
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
12257
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/index.js
|
|
12258
12258
|
init_file_system_node();
|
|
12259
12259
|
init_config();
|
|
12260
12260
|
|
|
12261
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
12261
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/fs.js
|
|
12262
12262
|
init_file_system_node();
|
|
12263
12263
|
|
|
12264
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
12264
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/path.js
|
|
12265
12265
|
function normalizeSeparators(path) {
|
|
12266
12266
|
return path.replaceAll("\\", "/");
|
|
12267
12267
|
}
|
|
@@ -12295,7 +12295,7 @@ function dirnamePath(path) {
|
|
|
12295
12295
|
return normalized.slice(0, index);
|
|
12296
12296
|
}
|
|
12297
12297
|
|
|
12298
|
-
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.
|
|
12298
|
+
// ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/fs.js
|
|
12299
12299
|
async function ensureDirForFile(path, fs = createNodeFileSystem()) {
|
|
12300
12300
|
await fs.ensureDir(dirnamePath(path));
|
|
12301
12301
|
}
|
|
@@ -13120,10 +13120,23 @@ function buildSeoDescription(input) {
|
|
|
13120
13120
|
}
|
|
13121
13121
|
};
|
|
13122
13122
|
pushWhile(input.clauses);
|
|
13123
|
+
if (picked.length === 0 && input.clauses.length > 0) {
|
|
13124
|
+
const first = cleanClause(input.clauses[0] ?? "");
|
|
13125
|
+
const room = input.config.descriptionMax - codePointLength(`${head}\u3002`);
|
|
13126
|
+
if (first.length > 0 && room > 0) {
|
|
13127
|
+
const cut = cutAtBoundary(first, room);
|
|
13128
|
+
if (cut.length > 0)
|
|
13129
|
+
picked.push(cut);
|
|
13130
|
+
}
|
|
13131
|
+
}
|
|
13123
13132
|
if (codePointLength(render(picked)) < input.config.descriptionMin)
|
|
13124
13133
|
pushWhile(input.extraSentences);
|
|
13125
13134
|
const description = render(picked);
|
|
13126
|
-
return {
|
|
13135
|
+
return {
|
|
13136
|
+
description,
|
|
13137
|
+
short: codePointLength(description) < input.config.descriptionMin,
|
|
13138
|
+
empty: picked.length === 0
|
|
13139
|
+
};
|
|
13127
13140
|
}
|
|
13128
13141
|
function descriptionInputs(metadata, config, date, minutes) {
|
|
13129
13142
|
const podcast = podcastOf(metadata);
|
|
@@ -13271,10 +13284,15 @@ function prepareEpisodeFields(episode, metadata, config) {
|
|
|
13271
13284
|
if (!seoTitle.ok)
|
|
13272
13285
|
return seoTitle;
|
|
13273
13286
|
const described = descriptionInputs(metadata, config, date, minutes);
|
|
13274
|
-
if (described.
|
|
13275
|
-
warnings.push(`${WARN_PREFIX} seo.description
|
|
13287
|
+
if (described.empty) {
|
|
13288
|
+
warnings.push(`${WARN_PREFIX} seo.description skipped: no summary clauses available`);
|
|
13289
|
+
seo = { title: seoTitle.value };
|
|
13290
|
+
} else {
|
|
13291
|
+
if (described.short) {
|
|
13292
|
+
warnings.push(`${WARN_PREFIX} seo.description is ${codePointLength(described.description)} code points, under the ${config.descriptionMin} minimum; left unpadded`);
|
|
13293
|
+
}
|
|
13294
|
+
seo = { title: seoTitle.value, description: described.description };
|
|
13276
13295
|
}
|
|
13277
|
-
seo = { title: seoTitle.value, description: described.description };
|
|
13278
13296
|
}
|
|
13279
13297
|
let slug;
|
|
13280
13298
|
if (config.slugMode === "pattern") {
|
|
@@ -14035,11 +14053,11 @@ import { extname } from "path";
|
|
|
14035
14053
|
// ../../plugins/publishings/podcast-pub/src/show-notes-brief.ts
|
|
14036
14054
|
var ARTICLE_PLACEHOLDER = '<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A\u5F85\u6587\u7AE0\u53D1\u5E03\u56DE\u6267</p>';
|
|
14037
14055
|
var CARDS_STYLE = `<style>
|
|
14038
|
-
.kk-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:
|
|
14039
|
-
.kk-card{margin:0;border:1px solid rgba(128,128,128,.25);border-radius:10px;overflow:hidden}
|
|
14056
|
+
.kk-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:1.25em 0 0}
|
|
14057
|
+
.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)}
|
|
14040
14058
|
.kk-card img{display:block;width:100%;height:auto}
|
|
14041
|
-
.kk-card figcaption{padding:8px 10px;font-size:.9em;color
|
|
14042
|
-
.kk-card-n{font-weight:700;color
|
|
14059
|
+
.kk-card figcaption{padding:8px 10px;font-size:.9em;color:var(--mf-muted,#444)}
|
|
14060
|
+
.kk-card-n{font-weight:700;color:var(--mf-accent,#0969da);margin-right:6px}
|
|
14043
14061
|
@media (max-width:420px){.kk-cards{grid-template-columns:1fr}}
|
|
14044
14062
|
</style>`;
|
|
14045
14063
|
var isHttpUrl = (value) => typeof value === "string" && /^https?:\/\//i.test(value.trim());
|
|
@@ -14072,7 +14090,15 @@ function planCards(raw) {
|
|
|
14072
14090
|
const copy = textOf(card.copy);
|
|
14073
14091
|
const sourcePoint = textOf(card.sourcePoint);
|
|
14074
14092
|
const alt = textOf(card.alt) || copy || sourcePoint || `\u672C\u671F\u5361\u7247 ${index}`;
|
|
14075
|
-
|
|
14093
|
+
const rawImagePath = textOf(card.imagePath);
|
|
14094
|
+
const imagePath = textOf(card.status) === "rendered" && rawImagePath !== "" ? rawImagePath : undefined;
|
|
14095
|
+
cards.push({
|
|
14096
|
+
index,
|
|
14097
|
+
alt,
|
|
14098
|
+
imageUrl: uploadStatus === "failed" ? "" : url,
|
|
14099
|
+
...imagePath !== undefined ? { imagePath } : {},
|
|
14100
|
+
text: copy || sourcePoint || alt
|
|
14101
|
+
});
|
|
14076
14102
|
});
|
|
14077
14103
|
return { cards, diagnostics };
|
|
14078
14104
|
}
|
|
@@ -14110,6 +14136,7 @@ function renderBriefShowNotes(input) {
|
|
|
14110
14136
|
lines.push(`<!--kk:timeline-->
|
|
14111
14137
|
<div class="kk-tl">${rows}
|
|
14112
14138
|
</div>
|
|
14139
|
+
${TIMELINE_STYLE}
|
|
14113
14140
|
${articleEntry}
|
|
14114
14141
|
<!--/kk:timeline-->`, "");
|
|
14115
14142
|
}
|
|
@@ -14119,7 +14146,19 @@ ${articleEntry}
|
|
|
14119
14146
|
return { markdown: lines.join(`
|
|
14120
14147
|
`), diagnostics };
|
|
14121
14148
|
}
|
|
14122
|
-
function
|
|
14149
|
+
function articleUrlFromPostPath(postPath, articleBaseUrl = "https://surfing.salty.vip") {
|
|
14150
|
+
const trimmed = postPath.trim();
|
|
14151
|
+
if (trimmed === "")
|
|
14152
|
+
return "";
|
|
14153
|
+
const segments = trimmed.split(/[\\/]/).filter((s) => s.length > 0);
|
|
14154
|
+
const slug = segments.length >= 2 ? segments[segments.length - 2] ?? "" : "";
|
|
14155
|
+
if (slug === "" || slug === "posts")
|
|
14156
|
+
return "";
|
|
14157
|
+
const locale = segments.find((s) => ["zh", "en", "ja"].includes(s)) ?? "zh";
|
|
14158
|
+
const prefix = locale === "en" ? "" : `/${locale}`;
|
|
14159
|
+
return `${articleBaseUrl.replace(/\/+$/, "")}${prefix}/posts/${slug}`;
|
|
14160
|
+
}
|
|
14161
|
+
function receiptArticleUrl(receipt, articleBaseUrl = "https://surfing.salty.vip") {
|
|
14123
14162
|
const entries = Array.isArray(receipt) ? receipt : receipt !== null && typeof receipt === "object" && Array.isArray(receipt.targets) ? receipt.targets : receipt !== null && typeof receipt === "object" ? [receipt] : [];
|
|
14124
14163
|
for (const entry of entries) {
|
|
14125
14164
|
if (entry === null || typeof entry !== "object")
|
|
@@ -14131,22 +14170,64 @@ function receiptSlug(receipt) {
|
|
|
14131
14170
|
const postPath = textOf(metadata.postPath);
|
|
14132
14171
|
if (postPath === "")
|
|
14133
14172
|
continue;
|
|
14134
|
-
const
|
|
14135
|
-
|
|
14136
|
-
|
|
14137
|
-
return `${slug}\x00${segments.find((s) => ["zh", "en", "ja"].includes(s)) ?? "zh"}`;
|
|
14173
|
+
const url = articleUrlFromPostPath(postPath, articleBaseUrl);
|
|
14174
|
+
if (url !== "")
|
|
14175
|
+
return url;
|
|
14138
14176
|
}
|
|
14139
14177
|
return "";
|
|
14140
14178
|
}
|
|
14179
|
+
function renderArticleLinkParagraph(articleUrl) {
|
|
14180
|
+
return `<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A<a href="${escapeHtml(articleUrl.trim())}" target="_blank" rel="noopener">\u672C\u671F\u5B8C\u6574\u6587\u7AE0</a></p>`;
|
|
14181
|
+
}
|
|
14182
|
+
function stripArticlePlaceholderHtml(html) {
|
|
14183
|
+
if (!html.includes(ARTICLE_PLACEHOLDER))
|
|
14184
|
+
return html;
|
|
14185
|
+
return html.replace(ARTICLE_PLACEHOLDER, "").replace(/\n{3,}/g, `
|
|
14186
|
+
|
|
14187
|
+
`).trim();
|
|
14188
|
+
}
|
|
14189
|
+
function upsertArticleLinkHtml(html, articleUrl) {
|
|
14190
|
+
if (!isHttpUrl(articleUrl))
|
|
14191
|
+
return { html, changed: false };
|
|
14192
|
+
const cleanUrl = articleUrl.trim();
|
|
14193
|
+
const linkParagraph = renderArticleLinkParagraph(cleanUrl);
|
|
14194
|
+
if (html.includes(escapeHtml(cleanUrl)) && /\u5B8C\u6574\u56FE\u6587\u7248/.test(html)) {
|
|
14195
|
+
return { html, changed: false };
|
|
14196
|
+
}
|
|
14197
|
+
if (html.includes(ARTICLE_PLACEHOLDER)) {
|
|
14198
|
+
return { html: html.replace(ARTICLE_PLACEHOLDER, linkParagraph), changed: true };
|
|
14199
|
+
}
|
|
14200
|
+
const existingPattern = /<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A[\s\S]*?<\/p>/;
|
|
14201
|
+
if (existingPattern.test(html)) {
|
|
14202
|
+
return { html: html.replace(existingPattern, linkParagraph), changed: true };
|
|
14203
|
+
}
|
|
14204
|
+
const cardsStyleIdx = html.indexOf(CARDS_STYLE);
|
|
14205
|
+
const cardsDivIdx = html.indexOf('<div class="kk-cards">');
|
|
14206
|
+
const anchor = cardsStyleIdx >= 0 ? cardsStyleIdx : cardsDivIdx;
|
|
14207
|
+
if (anchor >= 0) {
|
|
14208
|
+
const before = html.slice(0, anchor).replace(/\s*$/, "");
|
|
14209
|
+
const after = html.slice(anchor).replace(/^\s*/, "");
|
|
14210
|
+
return {
|
|
14211
|
+
html: before === "" ? `${linkParagraph}
|
|
14212
|
+
${after}` : `${before}
|
|
14213
|
+
${linkParagraph}
|
|
14214
|
+
${after}`,
|
|
14215
|
+
changed: true
|
|
14216
|
+
};
|
|
14217
|
+
}
|
|
14218
|
+
const trimmed = html.trim();
|
|
14219
|
+
return {
|
|
14220
|
+
html: trimmed === "" ? linkParagraph : `${trimmed}
|
|
14221
|
+
${linkParagraph}`,
|
|
14222
|
+
changed: true
|
|
14223
|
+
};
|
|
14224
|
+
}
|
|
14141
14225
|
function applyArticleReceipt(markdown, receipt, articleBaseUrl = "https://surfing.salty.vip") {
|
|
14142
|
-
const
|
|
14143
|
-
if (
|
|
14226
|
+
const url = receiptArticleUrl(receipt, articleBaseUrl);
|
|
14227
|
+
if (url === "" || !markdown.includes(ARTICLE_PLACEHOLDER))
|
|
14144
14228
|
return { markdown, enriched: false };
|
|
14145
|
-
const [slug = "", locale = "zh"] = proven.split("\x00");
|
|
14146
|
-
const prefix = locale === "en" ? "" : `/${locale}`;
|
|
14147
|
-
const url = `${articleBaseUrl.replace(/\/+$/, "")}${prefix}/posts/${slug}`;
|
|
14148
14229
|
return {
|
|
14149
|
-
markdown: markdown.replace(ARTICLE_PLACEHOLDER,
|
|
14230
|
+
markdown: markdown.replace(ARTICLE_PLACEHOLDER, renderArticleLinkParagraph(url)),
|
|
14150
14231
|
enriched: true
|
|
14151
14232
|
};
|
|
14152
14233
|
}
|
|
@@ -14215,7 +14296,7 @@ function computeAudioOffsets(docs, segments) {
|
|
|
14215
14296
|
return starts;
|
|
14216
14297
|
}
|
|
14217
14298
|
var isHttpUrl2 = (u) => /^https?:\/\//i.test(u.trim());
|
|
14218
|
-
var
|
|
14299
|
+
var LEGACY_TIMELINE_STYLE = `<style>
|
|
14219
14300
|
.kk-tl{margin:1em 0}
|
|
14220
14301
|
.kk-tl-row{display:flex;gap:12px;padding:10px 0;border-bottom:1px solid rgba(128,128,128,.25)}
|
|
14221
14302
|
.kk-tl-t{flex:0 0 56px;font-variant-numeric:tabular-nums;font-weight:700;color:#0969da}
|
|
@@ -14223,9 +14304,22 @@ var TIMELINE_STYLE = `<style>
|
|
|
14223
14304
|
.kk-tl-title{font-weight:600}
|
|
14224
14305
|
.kk-tl-brief{margin:4px 0 0;color:#666;font-size:.95em}
|
|
14225
14306
|
</style>`;
|
|
14226
|
-
var
|
|
14307
|
+
var TIMELINE_STYLE = `<style>
|
|
14308
|
+
.kk-tl{margin:1.25em 0;padding:0}
|
|
14309
|
+
.kk-tl-row{display:flex;align-items:stretch;gap:0}
|
|
14310
|
+
.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)}
|
|
14311
|
+
.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))}
|
|
14312
|
+
.kk-tl-row:last-child .kk-tl-body{border-left-color:transparent;padding-bottom:4px}
|
|
14313
|
+
.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)}
|
|
14314
|
+
.kk-tl-title{font-weight:600;line-height:1.5}
|
|
14315
|
+
.kk-tl-title a,.kk-tl-src{font-weight:400;font-size:.86em;margin-left:6px;color:var(--mf-muted,#666)}
|
|
14316
|
+
.kk-tl-brief{margin:5px 0 0;color:var(--mf-muted,#666);font-size:.94em;line-height:1.65}
|
|
14317
|
+
.kk-tl-more{margin:1.1em 0 0;font-size:.95em}
|
|
14318
|
+
@media (max-width:480px){.kk-tl-t{flex:0 0 46px;padding-right:10px;font-size:.86em}.kk-tl-body{padding-left:14px}}
|
|
14319
|
+
</style>`;
|
|
14320
|
+
var TIMELINE_TAG = /^<\/?(?:div|p|a|span)(?:\s+(?:class="kk-tl(?:-[a-z]+)?"|href="https?:\/\/[^"<>\s]*"|target="_blank"|rel="noopener"))*\s*>$/;
|
|
14227
14321
|
function isGeneratedTimeline(block) {
|
|
14228
|
-
const rest = block.replace(TIMELINE_STYLE, "");
|
|
14322
|
+
const rest = block.replace(TIMELINE_STYLE, "").replace(LEGACY_TIMELINE_STYLE, "");
|
|
14229
14323
|
if (rest.includes("<style") || rest.includes("<!--"))
|
|
14230
14324
|
return false;
|
|
14231
14325
|
return (rest.match(/<[^>]*>/g) ?? []).every((tag) => TIMELINE_TAG.test(tag)) && !/<(?![^>]*>)/.test(rest);
|
|
@@ -14657,7 +14751,17 @@ function publicItemUrl(item, itemId, client) {
|
|
|
14657
14751
|
return feedUrl !== "" ? feedUrl : client.itemUrl(itemId);
|
|
14658
14752
|
}
|
|
14659
14753
|
var TARGET2 = "podcast-pub";
|
|
14660
|
-
var OPERATIONS = [
|
|
14754
|
+
var OPERATIONS = [
|
|
14755
|
+
"publish",
|
|
14756
|
+
"show-notes",
|
|
14757
|
+
"list",
|
|
14758
|
+
"get",
|
|
14759
|
+
"update",
|
|
14760
|
+
"delete",
|
|
14761
|
+
"validate",
|
|
14762
|
+
"backfill-seo",
|
|
14763
|
+
"patch-article-link"
|
|
14764
|
+
];
|
|
14661
14765
|
function resolveClient() {
|
|
14662
14766
|
const baseUrl = process.env.MICROFEED_BASE_URL;
|
|
14663
14767
|
const apiKey = process.env.MICROFEED_API_KEY;
|
|
@@ -15145,12 +15249,104 @@ async function recordCorrectionDelivery(options, episodeStatus, delivery, warnin
|
|
|
15145
15249
|
delivered: planned.filter((entry) => entry.state === "delivered").map((entry) => entry.target)
|
|
15146
15250
|
};
|
|
15147
15251
|
}
|
|
15252
|
+
async function hydrateShowNotesCards(client, content, warnings) {
|
|
15253
|
+
const metadata = content.metadata ?? {};
|
|
15254
|
+
const podcastMeta = metadata.podcast !== null && typeof metadata.podcast === "object" && !Array.isArray(metadata.podcast) ? metadata.podcast : undefined;
|
|
15255
|
+
const rawCards = podcastMeta?.cards ?? metadata.cards;
|
|
15256
|
+
if (rawCards === undefined)
|
|
15257
|
+
return content;
|
|
15258
|
+
const showNotes = typeof metadata.showNotes === "string" ? metadata.showNotes : "";
|
|
15259
|
+
const usesShowNotes = showNotes.includes("<!--kk:cards-->");
|
|
15260
|
+
const sourceMarkdown = usesShowNotes ? showNotes : content.body;
|
|
15261
|
+
if (!sourceMarkdown.includes("<!--kk:cards-->"))
|
|
15262
|
+
return content;
|
|
15263
|
+
const { cards } = planCards(rawCards);
|
|
15264
|
+
if (cards.length === 0)
|
|
15265
|
+
return content;
|
|
15266
|
+
let uploadedAny = false;
|
|
15267
|
+
const hydrated = await Promise.all(cards.map(async (card) => {
|
|
15268
|
+
if (card.imageUrl !== "" || !card.imagePath)
|
|
15269
|
+
return card;
|
|
15270
|
+
const ext = extname2(card.imagePath).toLowerCase();
|
|
15271
|
+
const mime = COVER_MIME[ext];
|
|
15272
|
+
if (!mime) {
|
|
15273
|
+
warn(`card ${card.index} upload skipped: unsupported extension "${ext}"`, warnings);
|
|
15274
|
+
return card;
|
|
15275
|
+
}
|
|
15276
|
+
try {
|
|
15277
|
+
const bytes = new Uint8Array(await readFile(card.imagePath));
|
|
15278
|
+
const prepared = await client.prepareUpload({
|
|
15279
|
+
category: "image",
|
|
15280
|
+
full_local_file_path: basename(card.imagePath),
|
|
15281
|
+
size: bytes.byteLength,
|
|
15282
|
+
type: mime
|
|
15283
|
+
});
|
|
15284
|
+
await client.uploadBytes(prepared.presignedUrl, bytes, mime);
|
|
15285
|
+
uploadedAny = true;
|
|
15286
|
+
return { ...card, imageUrl: prepared.mediaUrl };
|
|
15287
|
+
} catch (error) {
|
|
15288
|
+
warn(`card ${card.index} upload failed (${error instanceof Error ? error.message : String(error)}); keeping text caption`, warnings);
|
|
15289
|
+
return card;
|
|
15290
|
+
}
|
|
15291
|
+
}));
|
|
15292
|
+
if (!uploadedAny)
|
|
15293
|
+
return content;
|
|
15294
|
+
const region = renderCardsRegion(hydrated);
|
|
15295
|
+
const updatedMarkdown = sourceMarkdown.replace(/<!--kk:cards-->[\s\S]*?<!--\/kk:cards-->/, () => region);
|
|
15296
|
+
if (usesShowNotes) {
|
|
15297
|
+
return {
|
|
15298
|
+
...content,
|
|
15299
|
+
metadata: {
|
|
15300
|
+
...metadata,
|
|
15301
|
+
showNotes: updatedMarkdown
|
|
15302
|
+
}
|
|
15303
|
+
};
|
|
15304
|
+
}
|
|
15305
|
+
return {
|
|
15306
|
+
...content,
|
|
15307
|
+
body: updatedMarkdown
|
|
15308
|
+
};
|
|
15309
|
+
}
|
|
15310
|
+
async function patchArticleLink(client, options) {
|
|
15311
|
+
const itemId = resolveItemId(options);
|
|
15312
|
+
if ("error" in itemId)
|
|
15313
|
+
return fail2(itemId.error);
|
|
15314
|
+
const baseUrl = typeof options.articleBaseUrl === "string" && options.articleBaseUrl.trim() !== "" ? options.articleBaseUrl.trim() : "https://surfing.salty.vip";
|
|
15315
|
+
const explicitUrl = typeof options.articleUrl === "string" ? options.articleUrl.trim() : "";
|
|
15316
|
+
const postPath = typeof options.articlePostPath === "string" && options.articlePostPath.trim() !== "" ? options.articlePostPath.trim() : typeof options.postPath === "string" ? options.postPath.trim() : "";
|
|
15317
|
+
const articleUrl = /^https?:\/\//i.test(explicitUrl) ? explicitUrl : postPath !== "" ? articleUrlFromPostPath(postPath, baseUrl) : "";
|
|
15318
|
+
if (!/^https?:\/\//i.test(articleUrl)) {
|
|
15319
|
+
return fail2('options.articleUrl or options.postPath is required for the "patch-article-link" operation');
|
|
15320
|
+
}
|
|
15321
|
+
const feed = await client.getItem(itemId.itemId);
|
|
15322
|
+
const item = feed.items?.[0];
|
|
15323
|
+
if (!item)
|
|
15324
|
+
return fail2(`microfeed item "${itemId.itemId}" not found in the feed response`);
|
|
15325
|
+
const currentHtml = typeof item.content_html === "string" ? item.content_html : "";
|
|
15326
|
+
const patched = upsertArticleLinkHtml(currentHtml, articleUrl);
|
|
15327
|
+
let updatedItem = item;
|
|
15328
|
+
if (patched.changed) {
|
|
15329
|
+
updatedItem = await client.updateItem(itemId.itemId, { content_html: patched.html });
|
|
15330
|
+
}
|
|
15331
|
+
const itemUrl = publicItemUrl(updatedItem, itemId.itemId, client);
|
|
15332
|
+
return ResultSchema.parse({
|
|
15333
|
+
ok: true,
|
|
15334
|
+
target: TARGET2,
|
|
15335
|
+
id: itemId.itemId,
|
|
15336
|
+
url: itemUrl,
|
|
15337
|
+
message: patched.changed ? `Patched article link into microfeed item ${itemId.itemId}` : `Article link already present on microfeed item ${itemId.itemId}`,
|
|
15338
|
+
metadata: {
|
|
15339
|
+
changed: patched.changed,
|
|
15340
|
+
articleUrl
|
|
15341
|
+
}
|
|
15342
|
+
});
|
|
15343
|
+
}
|
|
15148
15344
|
async function publishEpisode(client, payload, options) {
|
|
15149
15345
|
const assembly = resolveAssemblyOptions(options);
|
|
15150
15346
|
if ("error" in assembly)
|
|
15151
15347
|
return fail2(assembly.error);
|
|
15152
15348
|
const { audioFile, coverPath, durationSec } = assembly.assembly;
|
|
15153
|
-
const
|
|
15349
|
+
const rawContent = audioFile !== undefined || coverPath !== undefined || durationSec !== undefined ? {
|
|
15154
15350
|
...payload.content,
|
|
15155
15351
|
metadata: {
|
|
15156
15352
|
...payload.content.metadata,
|
|
@@ -15159,6 +15355,8 @@ async function publishEpisode(client, payload, options) {
|
|
|
15159
15355
|
...durationSec !== undefined ? { durationSeconds: durationSec } : {}
|
|
15160
15356
|
}
|
|
15161
15357
|
} : payload.content;
|
|
15358
|
+
const cardWarnings = [];
|
|
15359
|
+
const content = await hydrateShowNotesCards(client, rawContent, cardWarnings);
|
|
15162
15360
|
let episode;
|
|
15163
15361
|
try {
|
|
15164
15362
|
episode = mapContentToEpisode(content);
|
|
@@ -15172,6 +15370,8 @@ async function publishEpisode(client, payload, options) {
|
|
|
15172
15370
|
if (!policy.ok)
|
|
15173
15371
|
return fail2(policy.error);
|
|
15174
15372
|
const fields = policy.fields;
|
|
15373
|
+
if (cardWarnings.length > 0)
|
|
15374
|
+
fields.warnings.push(...cardWarnings);
|
|
15175
15375
|
try {
|
|
15176
15376
|
episode.transcripts = prepareTranscript(content.metadata, fields.warnings);
|
|
15177
15377
|
} catch (error) {
|
|
@@ -15185,6 +15385,7 @@ async function publishEpisode(client, payload, options) {
|
|
|
15185
15385
|
}
|
|
15186
15386
|
const seo = mergeSocial(fields.seo, social);
|
|
15187
15387
|
episode = shapedEpisode(episode, fields);
|
|
15388
|
+
episode.contentHtml = stripArticlePlaceholderHtml(episode.contentHtml);
|
|
15188
15389
|
let localAudioBytes;
|
|
15189
15390
|
let mediaIdentity;
|
|
15190
15391
|
if (episode.audio.kind === "url") {
|
|
@@ -15368,6 +15569,8 @@ class PodcastPubTransport {
|
|
|
15368
15569
|
return fail2(config.error);
|
|
15369
15570
|
return await runBackfill(client, options, config.config);
|
|
15370
15571
|
}
|
|
15572
|
+
case "patch-article-link":
|
|
15573
|
+
return await patchArticleLink(client, options);
|
|
15371
15574
|
case "validate": {
|
|
15372
15575
|
const input = options.item !== undefined && typeof options.item === "object" && options.item !== null ? options.item : mappedValidateInput(payload.content);
|
|
15373
15576
|
await client.validateItem(input);
|
|
@@ -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).
|