1
0
mirror of https://gitee.com/tawords/tawords-docs synced 2025-09-03 00:13:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

CSS JS文件本地化提高加载速度

This commit is contained in:
2021-08-07 01:44:15 +08:00
parent 6776edbd16
commit 6793ff7a27
12 changed files with 4184 additions and 10 deletions

View File

@@ -0,0 +1,60 @@
//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)

View File

@@ -0,0 +1 @@
var defaultOptions={countable:!0,position:"top",margin:"10px",float:"right",fontsize:"0.9em",color:"rgb(90,90,90)",language:"english",isExpected:!0};function plugin(t,n){if(!defaultOptions.countable)return;let o;t.beforeEach(function(t){return o=t.match(/([\u4e00-\u9fa5]+?|[a-zA-Z0-9]+)/g).length,t}),t.afterEach(function(t,n){let i=o+" words",e=Math.ceil(o/400)+" min";"chinese"===defaultOptions.language&&(i=o+" 字",e=Math.ceil(o/400)+" 分钟"),n(`\n ${"bottom"===defaultOptions.position?t:""}\n <div style="margin-${defaultOptions.position?"bottom":"top"}: ${defaultOptions.margin};">\n <span style="\n float: ${"right"===defaultOptions.float?"right":"left"};\n font-size: ${defaultOptions.fontsize};\n color:${defaultOptions.color};">\n ${i}\n ${defaultOptions.isExpected?`&nbsp; | &nbsp;${e}`:""}\n </span>\n <div style="clear: both"></div>\n </div>\n ${"bottom"!==defaultOptions.position?t:""}\n `)})}window.$docsify.count=Object.assign(defaultOptions,window.$docsify.count),window.$docsify.plugins=[].concat(plugin,window.$docsify.plugins);