Files
memind/mindspace-seo-geo-disk.mjs
john 357e26ab49
Memind CI / Test, build, and release guards (pull_request) Failing after 7m12s
Memind CI / Test, build, and release guards (push) Has been cancelled
feat(seo-geo): 落盘自动补齐与 143 全量回填支持
Finish/交付写盘前自动回填 mindspace-geo,扩展 storage publications 扫描与 geo meta 解析,并增加 143 生产回填脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 10:26:02 +08:00

45 lines
1.3 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { backfillMindspaceSeoGeoHtml } from './mindspace-geo-backfill.mjs';
function isPublicHtmlPath(value) {
const normalized = String(value ?? '').replace(/\\/g, '/');
return /(?:^|\/)public\/[^/]+\.html$/i.test(normalized);
}
export function prepareMindspacePublicHtmlForDisk(html, { htmlFilePath = '' } = {}) {
const source = String(html ?? '');
const filePath = String(htmlFilePath ?? '');
if (!source.trim()) return source;
if (filePath && !isPublicHtmlPath(filePath)) return source;
if (!filePath && !/<html[\s>]/i.test(source)) return source;
return backfillMindspaceSeoGeoHtml(source, {
htmlFilePath: filePath,
fixWarnings: true,
});
}
export function materializeMindspaceSeoGeoOnDisk(
absolutePath,
{
forceGeo = false,
fixWarnings = true,
} = {},
) {
const filePath = path.resolve(String(absolutePath ?? ''));
if (!filePath || !/\.html$/i.test(filePath)) {
return { changed: false, html: '' };
}
const before = fs.readFileSync(filePath, 'utf8');
const after = backfillMindspaceSeoGeoHtml(before, {
htmlFilePath: filePath,
forceGeo,
fixWarnings,
});
if (after === before) {
return { changed: false, html: before };
}
fs.writeFileSync(filePath, after, 'utf8');
return { changed: true, html: after };
}