mindspace: close authority boundaries

This commit is contained in:
john
2026-07-27 15:34:35 +08:00
parent dfab78c75a
commit e94052ff24
78 changed files with 11962 additions and 2162 deletions
+13 -3
View File
@@ -19,13 +19,19 @@ export function buildPublishedHtmlViewContext({
origin = '',
requestPath = '',
filePath = '',
servedName = '',
fallbackImageName = '',
thumbnailPngPathForSvg = (value) => value,
fileExists = fs.existsSync,
} = {}) {
const cleanPath = String(requestPath ?? '').split('?')[0].split('#')[0];
const servedName = path.basename(String(filePath ?? ''));
const resolvedServedName =
String(servedName ?? '').trim() ||
path.basename(String(filePath ?? ''));
const urlLast = decodeURIComponent(cleanPath.split('/').filter(Boolean).pop() ?? '');
const isImplicitIndex = urlLast.toLowerCase() !== servedName.toLowerCase();
const isImplicitIndex =
urlLast.toLowerCase() !==
resolvedServedName.toLowerCase();
const pageUrl = !origin
? ''
: `${origin}${isImplicitIndex && !cleanPath.endsWith('/') ? `${cleanPath}/` : cleanPath}`;
@@ -36,8 +42,12 @@ export function buildPublishedHtmlViewContext({
: `${origin}${cleanPath.slice(0, cleanPath.lastIndexOf('/') + 1)}`;
let fallbackImageUrl = '';
const logicalFallbackName =
String(fallbackImageName ?? '').trim();
const svgSibling = String(filePath ?? '').replace(/\.[^./]+$/, '.thumbnail.svg');
if (pageDirUrl && fileExists(svgSibling)) {
if (pageDirUrl && logicalFallbackName) {
fallbackImageUrl = `${pageDirUrl}${encodeURIComponent(logicalFallbackName)}`;
} else if (pageDirUrl && fileExists(svgSibling)) {
const pngName = path.basename(thumbnailPngPathForSvg(svgSibling));
fallbackImageUrl = `${pageDirUrl}${pngName}`;
}