- oil-ui-pro 升到 0.22.2:references 13→28 份(新增 16、删 imagery.md)、assets 增 cards/(22 组)与 fonts/、SKILL.md 顶层五步结构未改名。 - 升级路径:官方 `npx github:oil-oil/oil-cli update` 稳定失败(error=replace、报「检查目录权限」)。 真身为 EXDEV —— 解压在 os.tmpdir()(C 盘)、技能目录在 E 盘,Windows 上 rename 不能跨盘; CLI 的 catch 把非 CliError 原生异常一律兜底成 replaceFailed,真错误一个字不吐。 做法=借其 prepare() 只做下载+校验,再 cp 到同盘 stage、rename 交换;官方命令复验 up_to_date。 - 回归:product-planning 按名引用的 visual-review.md/tools.md/design-direction.md/style-explorer.md 全部健在;命名闸门 2061|0|27。 - session-mechanism/references/pitfalls.md 新增 P0-98(含通则:更新器把原生错误兜底成指错方向的人话)。
32 lines
1.6 KiB
JavaScript
32 lines
1.6 KiB
JavaScript
// Content values are plain text. A line break is content, not injected markup.
|
|
export function contentValue(content, path) {
|
|
return path.split('.').reduce((value,key)=>value!=null && Object.hasOwn(value,key)?value[key]:undefined,content);
|
|
}
|
|
function url(value, image=false) {
|
|
if(typeof value!=='string' || !value.trim())return null;
|
|
try {
|
|
const protocol=new URL(value,document.baseURI).protocol;
|
|
if(['http:','https:','file:'].includes(protocol) || (!image && ['mailto:','tel:'].includes(protocol)) || (image && (protocol==='blob:' || /^data:image\/(png|jpeg|webp|gif|svg\+xml)[;,]/i.test(value))))return value;
|
|
} catch {}
|
|
return null;
|
|
}
|
|
export function applyContent(element, content={}) {
|
|
if(!content || typeof content!=='object')return;
|
|
for(const node of element.querySelectorAll('[data-text]')) {
|
|
const value=contentValue(content,node.dataset.text);
|
|
if(value!==undefined && value!==null)node.textContent=Array.isArray(value)?value.join('\n'):String(value);
|
|
}
|
|
for(const node of [element,...element.querySelectorAll('[data-href]')]) {
|
|
if(!node.hasAttribute('data-href'))continue;
|
|
const value=contentValue(content,node.dataset.href);
|
|
if(value===undefined)continue;
|
|
const href=url(value);if(href)node.setAttribute('href',href);else node.removeAttribute('href');
|
|
}
|
|
for(const node of element.querySelectorAll('[data-image]')) {
|
|
const value=contentValue(content,node.dataset.image);
|
|
if(!value)continue;
|
|
const src=url(typeof value==='string'?value:value.src,true);
|
|
if(src){node.src=src;if(typeof value==='object' && value.alt!==undefined)node.alt=String(value.alt);}
|
|
}
|
|
}
|