- 工作台大版本升级:hash 路由 + 6 数据功能页(周榜/热门账号/账号详情/视频详情/AI写脚本/AI写作复盘),只读复用 dsh 库副本 + 抖音榜单 JSON - 数据库隔离:复制 dsh 库到 mcn-work-shop/,与 dsh 原库各访问各的(已 gitignore) - 图标全面扁平化:Lucide 线性 SVG,功能图标亮色区分,文字标题去图标 - 首页重构:功能入口卡 + AI写剧本快捷卡片(2列/8个/5行预览) + 独立帮助页 + header 精简 - 新增设计技能 impeccable + taste-skill(生成网页时参考) - 修复:fmtTime 跨 script 全局冲突(P0)、弹窗关闭、外链新标签打开等
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
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(/^-/, '');
|
|
}
|