diff --git a/lib/docsify.js b/lib/docsify.js index cf8e092..998e2e1 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -2518,6 +2518,8 @@ var OPTIONS = { loadSidebar: null, loadNavbar: null, router: false, + homepage: 'README.md', + basePath: '', auto2top: false }; var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop(); @@ -2540,8 +2542,9 @@ var cacheRoute = null; var cacheXhr = null; var mainRender = function (cb) { - var route = getRoute(); + var route = OPTIONS.basePath + getRoute(); if (cacheRoute === route) { return cb() } + var wait; var basePath = cacheRoute = route; @@ -2551,13 +2554,18 @@ var mainRender = function (cb) { basePath = basePath.match(/(\S*\/)[^\/]+$/)[1]; } + var page; + if (!route) { + page = OPTIONS.homepage || 'README.md'; + } else if (/\/$/.test(route)) { + page = route + "README.md"; + } else { + page = route + ".md"; + } + cacheXhr && cacheXhr.abort && cacheXhr.abort(); // Render markdown file - cacheXhr = load( - (!route || /\/$/.test(route)) ? (route + "README.md") : (route + ".md"), - 'GET', - renderLoading); - + cacheXhr = load(page, 'GET', renderLoading); cacheXhr.then(function (result) { renderArticle(result); if (OPTIONS.loadSidebar) { diff --git a/lib/docsify.min.js b/lib/docsify.min.js index cbeffab..d1f0a89 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 i=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(i)})}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 i=e.level||1,a=i-1;i>t||(r[a]?(r[a].children=r[a].children||[],r[a].children.push(e)):n.push(e),r[i]=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 i(){var e=window.location;if(_===e.hash&&!r(S))return S;var t=e.hash.match(/^#\/([^#]+)/);return t=t&&2===t.length?t[1]:/^#\//.test(e.hash)?"":e.pathname,S=t,_=e.hash,t}function a(){return document.body.clientWidth<=600}function s(){function e(){for(var e=0,r=t.length;e10){var o=n[a.id];if(!o||o===i)return;return i&&i.setAttribute("class",""),o.setAttribute("class","active"),void(i=o)}}}if(!a()){for(var t=document.querySelectorAll(".anchor"),n={},r=document.querySelectorAll(".sidebar li"),i=null,s=0,o=r.length;s\n \n '):""}function g(){return'
\n \n
\n
\n
\n
'}function d(e){return e?'':""}function f(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='
  • '+e.title+"
  • ",e.children&&(t+='
    • '+f(e.children)+"
    ")}),t):""}function m(e,t){var n=document.querySelector("nav")||document.createElement("nav");e[t?"outerHTML":"innerHTML"]=d($.sidebarToggle)+h($.repo)+g(),document.body.insertBefore(n,document.body.children[0]),u("button.sidebar-toggle")}function b(e){q("article",e?C(e):"not found"),k.rendered||k(null,$),y.rendered||y(null,$),k.rendered=!1,y.rendered=!1,$.auto2top&&c()}function y(e){E.navbar&&E.navbar===e||(E.navbar=e,y.rendered=!0,e&&q("nav",C(e)),l("nav"))}function k(e){var n=!1;e?e=C(e):$.sidebar?e=f($.sidebar,"