自定义底部模版
使用 extra-widget
插件,可以自定义底部模版,模版文件路径在配置文件中配置,模版文件中可以使用 {{METADATA.${key}}}
来获取元数据中的值。
示例: 改变原有时间格式
<div>
<hr />
<p>powered by <a href="https://github.com/enncy/easy-wiki"> easy-wiki </a></p>
<p>更新于:<span class="footer-time">{{METADATA.update_at}}</span></p>
<p>创建于:<span class="footer-time">{{METADATA.create_at}}</span></p>
<script>
window.addEventListener("load",()=>{
document.querySelectorAll(".footer-time").forEach((el)=>{
el.innerText = new Date(el.innerText).toLocaleString("zh-CN").replace(/\//g,'-')
})
})
</script>
</div>
自定义插件
示例:自定义插件,为表格添加 table-striped
类名,为代码块添加 custom
类名,为引用块添加 custom
类名。
// @ts-check
const container = require('markdown-it-container')
/** @type {import('../node_modules/ewiki/lib/interface.d.ts').Plugin} */
exports.default = {
// 当 markdown-it 对象初始化时触发
onMarkdownItInit(md) {
md.core.ruler.push('custom-rule', function (state) {
const tokens = state.tokens
function handle(tokens) {
for (const token of tokens) {
addClass(token, 'table', ['table-striped'])
addClass(token, 'pre', ['custom'])
addClass(token, 'blockquote', ['custom'])
if (token.children?.length) {
handle(token.children)
}
}
}
handle(tokens)
})
}
}
function addClass(token, tag_name, list) {
if (token.tag === tag_name) {
token.attrSet('class', list.join(' '))
}
}