diff --git a/lib/docsify.js b/lib/docsify.js index b6cac80..87ad602 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -114,6 +114,35 @@ function isMobile () { return document.body.clientWidth <= 600 } +function slugify (string) { + var re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g; + var maintainCase = false; + var replacement = '-'; + slugify.occurrences = slugify.occurrences || {}; + + if (typeof string !== 'string') { return '' } + if (!maintainCase) { string = string.toLowerCase(); } + + var slug = string.trim() + .replace(re, '') + .replace(/\s/g, replacement); + var occurrences = slugify.occurrences[slug]; + + if (slugify.occurrences.hasOwnProperty(slug)) { + occurrences++; + } else { + occurrences = 0; + } + + slugify.occurrences[slug] = occurrences; + + if (occurrences) { + slug = slug + '-' + occurrences; + } + + return slug +} + /** * Active sidebar when scroll * @link https://buble.surge.sh/ @@ -2400,9 +2429,7 @@ var renderer = new marked.Renderer(); * @link https://github.com/chjj/marked#overriding-renderer-methods */ renderer.heading = function (text, level) { - var slug = text.toLowerCase() - .replace(/<(?:.|\n)*?>/gm, '') - .replace(/[^\w|\u4e00-\u9fa5]+/g, '-'); + var slug = slugify(text); var route = ''; if (OPTIONS$1.router) { diff --git a/lib/docsify.min.js b/lib/docsify.min.js index e98b326..6937f66 100644 --- a/lib/docsify.min.js +++ b/lib/docsify.min.js @@ -1,2 +1,2 @@ -var Docsify=function(){"use strict";function e(e,t,n){void 0===t&&(t="GET");var r=new XMLHttpRequest;return r.open(t,e),r.send(),{then:function(e,t){if(void 0===t&&(t=function(){}),n){var a=setInterval(function(e){return n({step:Math.floor(5*Math.random()+1)})},500);r.addEventListener("progress",n),r.addEventListener("loadend",function(e){n(e),clearInterval(a)})}r.addEventListener("error",t),r.addEventListener("load",function(n){var r=n.target;r.status>=400?t(r):e(r.response)})},abort:function(){return 4!==r.readyState&&r.abort()}}}function t(e,t){var n=[],r={};return e.forEach(function(e){var a=e.level||1,i=a-1;a>t||(r[i]?(r[i].children=r[i].children||[],r[i].children.push(e)):n.push(e),r[a]=e)}),n}function n(e){return e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()})}function r(e){return null===e||void 0===e}function a(){var e=window.location;if($===e.hash&&!r(A))return A;var t=e.hash.match(/^#\/([^#]+)/);return t=t&&2===t.length?t[1]:/^#\//.test(e.hash)?"":e.pathname,A=t,$=e.hash,t}function i(){return document.body.clientWidth<=600}function s(){function e(){for(var e=0,r=t.length;e10){var o=n[i.getAttribute("data-id")];if(!o||o===a)return;return a&&a.setAttribute("class",""),o.setAttribute("class","active"),void(a=o)}}}if(!i()){for(var t=document.querySelectorAll(".anchor"),n={},r=document.querySelectorAll(".sidebar li"),a=null,s=0,o=r.length;s=t||e.classList.contains("hidden")?document.body.classList.add("sticky"):document.body.classList.remove("sticky")}()}function d(e,t){return t={exports:{}},e(t,t.exports),t.exports}function g(e){return e?(/\/\//.test(e)||(e="https://github.com/"+e),e=e.replace(/^git\+/,""),'\n \n \n '):""}function h(e){return"
\n "+e+'\n \n
\n
\n
\n
'}function f(){var e=", 100%, 85%",t="linear-gradient(to left bottom, hsl("+(Math.floor(255*Math.random())+e)+") 0%, hsl("+(Math.floor(255*Math.random())+e)+") 100%)";return'
\n
\n
\n
'}function m(){return''}function b(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='
  • '+e.title+"
  • ",e.children&&(t+='
    • '+b(e.children)+"
    ")}),t):""}function y(e,t){var n=document.querySelector("nav")||document.createElement("nav");T.repo||n.classList.add("no-badge"),e[t?"outerHTML":"innerHTML"]=g(T.repo)+(T.coverpage?f():"")+h(T.sidebarToggle?m():""),document.body.insertBefore(n,document.body.children[0]),u("button.sidebar-toggle"),T.coverpage?!i()&&window.addEventListener("scroll",p):document.body.classList.add("sticky")}function v(e){if(N("article",e?q(e):"not found"),T.sidebar||T.loadSidebar||x(),e&&"undefined"!=typeof Vue&&"undefined"!=typeof Vuep){var t=new Vue({el:"main"});t.$nextTick(function(e){return s()})}T.auto2top&&c()}function k(e){M.navbar&&M.navbar===e||(M.navbar=e,e&&N("nav",q(e)),l("nav"))}function x(e){var n;n=e?q(e):T.sidebar?b(T.sidebar,"