357e26ab49
Finish/交付写盘前自动回填 mindspace-geo,扩展 storage publications 扫描与 geo meta 解析,并增加 143 生产回填脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.3 KiB
JavaScript
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 };
|
|
}
|