1 Star 0 Fork 5

不死鸟玉山禾/dingflow-docsify

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
countable.js 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
jinqiming 提交于 2021-04-22 16:41 . 初始化项目
//default values
var defaultOptions = {
countable: true,
position: "top",
margin: "10px",
float: "right",
fontsize: "0.9em",
color: "rgb(90,90,90)",
language: "english",
isExpected: true,
}
// Docsify plugin functions
function plugin(hook, vm) {
if (!defaultOptions.countable) {
return
}
let wordsCount
hook.beforeEach(function (content) {
// Match regex every time you start parsing .md
wordsCount = content.match(/([\u4e00-\u9fa5]+?|[a-zA-Z0-9]+)/g).length
return content
})
hook.afterEach(function (html, next) {
let str = wordsCount + " words"
let readTime = Math.ceil(wordsCount / 400) + " min"
//Determine whether to use the Chinese style according to the attribute "language"
if (defaultOptions.language === "chinese") {
str = wordsCount + ""
readTime = Math.ceil(wordsCount / 400) + " 分钟"
}
//add html string
next(
`
${defaultOptions.position === "bottom" ? html : ""}
<div style="margin-${defaultOptions.position ? "bottom" : "top"}: ${
defaultOptions.margin
};">
<span style="
float: ${defaultOptions.float === "right" ? "right" : "left"};
font-size: ${defaultOptions.fontsize};
color:${defaultOptions.color};">
${str}
${defaultOptions.isExpected ? `&nbsp; | &nbsp;${readTime}` : ""}
</span>
<div style="clear: both"></div>
</div>
${defaultOptions.position !== "bottom" ? html : ""}
`
)
})
}
// Docsify plugin options
window.$docsify["count"] = Object.assign(
defaultOptions,
window.$docsify["count"]
)
window.$docsify.plugins = [].concat(plugin, window.$docsify.plugins)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yushanhe/dingflow-docsify.git
git@gitee.com:yushanhe/dingflow-docsify.git
yushanhe
dingflow-docsify
dingflow-docsify
master

搜索帮助