Bug fixes

This commit is contained in:
2026-07-24 16:33:44 +02:00
parent 6b71a98a45
commit b6512a318d
156 changed files with 69800 additions and 51 deletions

View File

@@ -0,0 +1,33 @@
import path from 'node:path';
const SLUG_MAX = 50;
/** Derive one clone-stable slug from a concrete file path or URL. */
export function slugFromTarget(resolved, { cwd = process.cwd() } = {}) {
if (!resolved || typeof resolved !== 'string') return null;
const trimmed = resolved.trim();
if (!trimmed) return null;
if (/^https?:\/\//i.test(trimmed)) {
let url;
try { url = new URL(trimmed); } catch { return null; }
return kebab(`${url.hostname}${url.pathname}`);
}
const abs = path.isAbsolute(trimmed) ? trimmed : path.resolve(cwd, trimmed);
let rel = path.relative(cwd, abs);
if (rel.startsWith('..') || path.isAbsolute(rel)) rel = path.basename(abs);
if (!rel || rel === '.') return null;
return kebab(rel);
}
export function kebab(value) {
const slug = String(value || '')
.toLowerCase()
.replace(/[/\\.]+/g, '-')
.replace(/[^a-z0-9-]+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '');
if (!slug) return null;
return slug.length <= SLUG_MAX ? slug : slug.slice(slug.length - SLUG_MAX).replace(/^-/, '');
}