mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-11 06:16:10 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f38810774 | ||
|
|
3db4841da3 | ||
|
|
b764b6e32c | ||
|
|
46261572e3 |
+2
-2
@@ -13,6 +13,7 @@ module.exports = {
|
||||
mergeNavbar: true,
|
||||
maxLevel: 4,
|
||||
subMaxLevel: 2,
|
||||
basePath: '/docs/',
|
||||
name: 'docsify',
|
||||
search: {
|
||||
noData: {
|
||||
@@ -28,6 +29,5 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
},
|
||||
context: './docs',
|
||||
template: './ssr.html'
|
||||
template: './docs/ssr.html'
|
||||
}
|
||||
|
||||
+8
-8
@@ -8,9 +8,9 @@
|
||||
<meta name="description" content="A magical documentation generator.">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/vue.css" title="vue">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/dark.css" title="dark" disabled>
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/buble.css" title="buble" disabled>
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/pure.css" title="pure" disabled>
|
||||
<!-- <link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/dark.css" title="dark" disabled> -->
|
||||
<!-- <link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/buble.css" title="buble" disabled> -->
|
||||
<!-- <link rel="stylesheet" href="//unpkg.com/docsify@next/lib/themes/pure.css" title="pure" disabled> -->
|
||||
<style>
|
||||
nav.app-nav li ul {
|
||||
min-width: 100px;
|
||||
@@ -21,9 +21,9 @@
|
||||
<!--inject-app-->
|
||||
<!--inject-config-->
|
||||
</body>
|
||||
<script src="//unpkg.com/docsify@next/lib/docsify.min.js"></script>
|
||||
<script src="//unpkg.com/docsify@next/lib/plugins/search.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script>
|
||||
<script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script>
|
||||
<script src="/lib/docsify.js"></script>
|
||||
<script src="/lib/plugins/search.js"></script>
|
||||
<!-- <script src="//unpkg.com/prismjs/components/prism-bash.min.js"></script> -->
|
||||
<!-- <script src="//unpkg.com/prismjs/components/prism-markdown.min.js"></script> -->
|
||||
<!-- <script src="//unpkg.com/prismjs/components/prism-nginx.min.js"></script> -->
|
||||
</html>
|
||||
|
||||
+17
-15
@@ -2732,17 +2732,6 @@ function stringifyQuery (obj) {
|
||||
return qs.length ? ("?" + (qs.join('&'))) : ''
|
||||
}
|
||||
|
||||
var getBasePath = cached(function (base) {
|
||||
if ( base === void 0 ) base = '';
|
||||
|
||||
// TODO
|
||||
var path = inBrowser ? window.location.pathname : '';
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
});
|
||||
|
||||
function getPath () {
|
||||
var args = [], len = arguments.length;
|
||||
while ( len-- ) args[ len ] = arguments[ len ];
|
||||
@@ -2774,7 +2763,7 @@ var Compiler = function Compiler (config, router) {
|
||||
this.cacheTree = {};
|
||||
this.toc = [];
|
||||
this.linkTarget = config.externalLinkTarget || '_blank';
|
||||
this.contentBase = getBasePath(config.basePath);
|
||||
this.contentBase = router.getBasePath();
|
||||
|
||||
var renderer = this._initRenderer();
|
||||
var compile;
|
||||
@@ -3233,7 +3222,7 @@ function renderMixin (proto) {
|
||||
|
||||
toggleClass(el, 'add', 'has-mask');
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(getBasePath(this.config.basePath), m[1]);
|
||||
path = getPath(this.router.getBasePath(), m[1]);
|
||||
}
|
||||
el.style.backgroundImage = "url(" + path + ")";
|
||||
el.style.backgroundSize = 'cover';
|
||||
@@ -3317,10 +3306,14 @@ var History = function History (config) {
|
||||
this.config = config;
|
||||
};
|
||||
|
||||
History.prototype.getBasePath = function getBasePath () {
|
||||
return this.config.basePath
|
||||
};
|
||||
|
||||
History.prototype.getFile = function getFile (path) {
|
||||
var ref = this;
|
||||
var config = ref.config;
|
||||
var base = getBasePath(config.basePath);
|
||||
var base = this.getBasePath();
|
||||
|
||||
path = config.alias ? getAlias(path, config.alias) : path;
|
||||
path = getFileName(path);
|
||||
@@ -3365,6 +3358,15 @@ var HashHistory = (function (History$$1) {
|
||||
HashHistory.prototype = Object.create( History$$1 && History$$1.prototype );
|
||||
HashHistory.prototype.constructor = HashHistory;
|
||||
|
||||
HashHistory.prototype.getBasePath = function getBasePath () {
|
||||
var path = window.location.pathname || '';
|
||||
var base = this.config.basePath;
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
};
|
||||
|
||||
HashHistory.prototype.getCurrentPath = function getCurrentPath () {
|
||||
// We can't use location.hash here because it's not
|
||||
// consistent across browsers - Firefox will pre-decode it!
|
||||
@@ -3628,6 +3630,7 @@ function fetchMixin (proto) {
|
||||
var root = getParentPath(this.route.path);
|
||||
var path = this.router.getFile(root + coverpage);
|
||||
|
||||
console.log(this.route.path, root, path);
|
||||
if (this.route.path !== '/' || !coverpage) {
|
||||
this._renderCover();
|
||||
return
|
||||
@@ -3705,7 +3708,6 @@ var util = Object.freeze({
|
||||
supportsPushState: supportsPushState,
|
||||
parseQuery: parseQuery,
|
||||
stringifyQuery: stringifyQuery,
|
||||
getBasePath: getBasePath,
|
||||
getPath: getPath,
|
||||
isAbsolutePath: isAbsolutePath,
|
||||
getParentPath: getParentPath,
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
+15
-17
@@ -47,13 +47,12 @@ function genIndex (path, content, router) {
|
||||
|
||||
var tokens = window.marked.lexer(content);
|
||||
var slugify = window.Docsify.slugify;
|
||||
var toURL = router.toURL;
|
||||
var index = {};
|
||||
var slug;
|
||||
|
||||
tokens.forEach(function (token) {
|
||||
if (token.type === 'heading' && token.depth <= 2) {
|
||||
slug = toURL(path, { id: slugify(token.text) });
|
||||
slug = router.toURL(path, { id: slugify(token.text) });
|
||||
index[slug] = { slug: slug, title: token.text, body: '' };
|
||||
} else {
|
||||
if (!slug) { return }
|
||||
@@ -169,13 +168,12 @@ function init$1 (config, vm) {
|
||||
});
|
||||
}
|
||||
|
||||
var dom;
|
||||
var NO_DATA_TEXT = '';
|
||||
|
||||
function style () {
|
||||
var code = "\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}";
|
||||
var style = dom.create('style', code);
|
||||
dom.appendTo(dom.head, style);
|
||||
var style = Docsify.dom.create('style', code);
|
||||
Docsify.dom.appendTo(Docsify.dom.head, style);
|
||||
}
|
||||
|
||||
function tpl (opts, defaultValue) {
|
||||
@@ -185,16 +183,16 @@ function tpl (opts, defaultValue) {
|
||||
"<input type=\"search\" value=\"" + defaultValue + "\" />" +
|
||||
'<div class="results-panel"></div>' +
|
||||
'</div>';
|
||||
var el = dom.create('div', html);
|
||||
var aside = dom.find('aside');
|
||||
var el = Docsify.dom.create('div', html);
|
||||
var aside = Docsify.dom.find('aside');
|
||||
|
||||
dom.toggleClass(el, 'search');
|
||||
dom.before(aside, el);
|
||||
Docsify.dom.toggleClass(el, 'search');
|
||||
Docsify.dom.before(aside, el);
|
||||
}
|
||||
|
||||
function doSearch (value) {
|
||||
var $search = dom.find('div.search');
|
||||
var $panel = dom.find($search, '.results-panel');
|
||||
var $search = Docsify.dom.find('div.search');
|
||||
var $panel = Docsify.dom.find($search, '.results-panel');
|
||||
|
||||
if (!value) {
|
||||
$panel.classList.remove('show');
|
||||
@@ -213,22 +211,23 @@ function doSearch (value) {
|
||||
}
|
||||
|
||||
function bindEvents () {
|
||||
var $search = dom.find('div.search');
|
||||
var $input = dom.find($search, 'input');
|
||||
var $search = Docsify.dom.find('div.search');
|
||||
var $input = Docsify.dom.find($search, 'input');
|
||||
|
||||
var timeId;
|
||||
// Prevent to Fold sidebar
|
||||
dom.on($search, 'click',
|
||||
Docsify.dom.on($search, 'click',
|
||||
function (e) { return e.target.tagName !== 'A' && e.stopPropagation(); });
|
||||
dom.on($input, 'input', function (e) {
|
||||
Docsify.dom.on($input, 'input', function (e) {
|
||||
clearTimeout(timeId);
|
||||
timeId = setTimeout(function (_) { return doSearch(e.target.value.trim()); }, 100);
|
||||
});
|
||||
}
|
||||
|
||||
function updatePlaceholder (text, path) {
|
||||
var $input = dom.getNode('.search input[type="search"]');
|
||||
var $input = Docsify.dom.getNode('.search input[type="search"]');
|
||||
|
||||
if (!$input) { return }
|
||||
if (typeof text === 'string') {
|
||||
$input.placeholder = text;
|
||||
} else {
|
||||
@@ -247,7 +246,6 @@ function updateNoData (text, path) {
|
||||
}
|
||||
|
||||
function init$$1 (opts, vm) {
|
||||
dom = Docsify.dom;
|
||||
var keywords = vm.router.parse().query.s;
|
||||
|
||||
style();
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(e){var n=[];return d.dom.findAll("a:not([data-nosearch])").map(function(t){var r=t.href,a=t.getAttribute("href"),o=e.parse(r).path;o&&-1===n.indexOf(o)&&!Docsify.util.isAbsolutePath(a)&&n.push(o)}),n}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(v))}function r(e,n,t){void 0===n&&(n="");var r,a=window.marked.lexer(n),o=window.Docsify.slugify,i=t.toURL,s={};return a.forEach(function(n){if("heading"===n.type&&n.depth<=2)r=i(e,{id:o(n.text)}),s[r]={slug:r,title:n.text,body:""};else{if(!r)return;s[r]?s[r].body?s[r].body+="\n"+(n.text||""):s[r].body=n.text:s[r]={slug:r,title:"",body:""}}}),o.clear(),s}function a(n){var t=[],r=[];Object.keys(v).forEach(function(e){r=r.concat(Object.keys(v[e]).map(function(n){return v[e][n]}))}),n=[].concat(n,n.trim().split(/[\s\-\,\\\/]+/));for(var a=0;a<r.length;a++)!function(a){var o=r[a],i=!1,s="",c=o.title&&o.title.trim(),l=o.body&&o.body.trim(),u=o.slug||"";if(c&&l&&(n.forEach(function(n,t){var r=new RegExp(n,"gi"),a=-1,o=-1;if(a=c&&c.search(r),o=l&&l.search(r),a<0&&o<0)i=!1;else{i=!0,o<0&&(o=0);var u=0,p=0;u=o<11?0:o-10,p=0===u?70:o+n.length+60,p>l.length&&(p=l.length);var f="..."+e(l).substring(u,p).replace(r,'<em class="search-keyword">'+n+"</em>")+"...";s+=f}}),i)){var p={title:e(c),content:s,url:u};t.push(p)}}(a);return t}function o(e,a){d=Docsify;var o="auto"===e.paths,i=localStorage.getItem("docsify.search.expires")<Date.now();if(v=JSON.parse(localStorage.getItem("docsify.search.index")),i)v={};else if(!o)return;var s=o?n(a.router):e.paths,c=s.length,l=0;s.forEach(function(n){if(v[n])return l++;d.get(a.router.getFile(n)).then(function(o){v[n]=r(n,o,a.router),c===++l&&t(e.maxAge)})})}function i(){var e=g.create("style","\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}");g.appendTo(g.head,e)}function s(e,n){void 0===n&&(n="");var t='<input type="search" value="'+n+'" /><div class="results-panel"></div></div>',r=g.create("div",t),a=g.find("aside");g.toggleClass(r,"search"),g.before(a,r)}function c(e){var n=g.find("div.search"),t=g.find(n,".results-panel");if(!e)return t.classList.remove("show"),void(t.innerHTML="");var r=a(e),o="";r.forEach(function(e){o+='<div class="matching-post">\n<h2><a href="'+e.url+'">'+e.title+"</a></h2>\n<p>"+e.content+"</p>\n</div>"}),t.classList.add("show"),t.innerHTML=o||'<p class="empty">'+y+"</p>"}function l(){var e,n=g.find("div.search"),t=g.find(n,"input");g.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),g.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return c(n.target.value.trim())},100)})}function u(e,n){var t=g.getNode('.search input[type="search"]');if("string"==typeof e)t.placeholder=e;else{var r=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];t.placeholder=e[r]}}function p(e,n){if("string"==typeof e)y=e;else{var t=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];y=e[t]}}function f(e,n){g=Docsify.dom;var t=n.router.parse().query.s;i(),s(e,t),l(),t&&setTimeout(function(e){return c(t)},500)}function h(e,n){u(e.placeholder,n.route.path),p(e.noData,n.route.path)}var d,g,v={},y="",m={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},x=function(e,n){var t=Docsify.util,r=n.config.search||m;Array.isArray(r)?m.paths=r:"object"==typeof r&&(m.paths=Array.isArray(r.paths)?r.paths:"auto",m.maxAge=t.isPrimitive(r.maxAge)?r.maxAge:m.maxAge,m.placeholder=r.placeholder||m.placeholder,m.noData=r.noData||m.noData);var a="auto"===m.paths;e.mounted(function(e){f(m,n),!a&&o(m,n)}),e.doneEach(function(e){h(m,n),a&&o(m,n)})};$docsify.plugins=[].concat(x,$docsify.plugins)}();
|
||||
this.D=this.D||{},function(){"use strict";function e(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return String(e).replace(/[&<>"'\/]/g,function(e){return n[e]})}function n(e){var n=[];return h.dom.findAll("a:not([data-nosearch])").map(function(t){var o=t.href,i=t.getAttribute("href"),r=e.parse(o).path;r&&-1===n.indexOf(r)&&!Docsify.util.isAbsolutePath(i)&&n.push(r)}),n}function t(e){localStorage.setItem("docsify.search.expires",Date.now()+e),localStorage.setItem("docsify.search.index",JSON.stringify(y))}function o(e,n,t){void 0===n&&(n="");var o,i=window.marked.lexer(n),r=window.Docsify.slugify,a={};return i.forEach(function(n){if("heading"===n.type&&n.depth<=2)o=t.toURL(e,{id:r(n.text)}),a[o]={slug:o,title:n.text,body:""};else{if(!o)return;a[o]?a[o].body?a[o].body+="\n"+(n.text||""):a[o].body=n.text:a[o]={slug:o,title:"",body:""}}}),r.clear(),a}function i(n){var t=[],o=[];Object.keys(y).forEach(function(e){o=o.concat(Object.keys(y[e]).map(function(n){return y[e][n]}))}),n=[].concat(n,n.trim().split(/[\s\-\,\\\/]+/));for(var i=0;i<o.length;i++)!function(i){var r=o[i],a=!1,s="",c=r.title&&r.title.trim(),f=r.body&&r.body.trim(),l=r.slug||"";if(c&&f&&(n.forEach(function(n,t){var o=new RegExp(n,"gi"),i=-1,r=-1;if(i=c&&c.search(o),r=f&&f.search(o),i<0&&r<0)a=!1;else{a=!0,r<0&&(r=0);var l=0,d=0;l=r<11?0:r-10,d=0===l?70:r+n.length+60,d>f.length&&(d=f.length);var u="..."+e(f).substring(l,d).replace(o,'<em class="search-keyword">'+n+"</em>")+"...";s+=u}}),a)){var d={title:e(c),content:s,url:l};t.push(d)}}(i);return t}function r(e,i){h=Docsify;var r="auto"===e.paths,a=localStorage.getItem("docsify.search.expires")<Date.now();if(y=JSON.parse(localStorage.getItem("docsify.search.index")),a)y={};else if(!r)return;var s=r?n(i.router):e.paths,c=s.length,f=0;s.forEach(function(n){if(y[n])return f++;h.get(i.router.getFile(n)).then(function(r){y[n]=o(n,r,i.router),c===++f&&t(e.maxAge)})})}function a(){var e=Docsify.dom.create("style","\n.sidebar {\n padding-top: 0;\n}\n\n.search {\n margin-bottom: 20px;\n padding: 6px;\n border-bottom: 1px solid #eee;\n}\n\n.search .results-panel {\n display: none;\n}\n\n.search .results-panel.show {\n display: block;\n}\n\n.search input {\n outline: none;\n border: none;\n width: 100%;\n padding: 7px;\n line-height: 22px;\n font-size: 14px;\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n}\n\n.search h2 {\n font-size: 17px;\n margin: 10px 0;\n}\n\n.search a {\n text-decoration: none;\n color: inherit;\n}\n\n.search .matching-post {\n border-bottom: 1px solid #eee;\n}\n\n.search .matching-post:last-child {\n border-bottom: 0;\n}\n\n.search p {\n font-size: 14px;\n overflow: hidden;\n text-overflow: ellipsis;\n display: -webkit-box;\n -webkit-line-clamp: 2;\n -webkit-box-orient: vertical;\n}\n\n.search p.empty {\n text-align: center;\n}");Docsify.dom.appendTo(Docsify.dom.head,e)}function s(e,n){void 0===n&&(n="");var t='<input type="search" value="'+n+'" /><div class="results-panel"></div></div>',o=Docsify.dom.create("div",t),i=Docsify.dom.find("aside");Docsify.dom.toggleClass(o,"search"),Docsify.dom.before(i,o)}function c(e){var n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,".results-panel");if(!e)return t.classList.remove("show"),void(t.innerHTML="");var o=i(e),r="";o.forEach(function(e){r+='<div class="matching-post">\n<h2><a href="'+e.url+'">'+e.title+"</a></h2>\n<p>"+e.content+"</p>\n</div>"}),t.classList.add("show"),t.innerHTML=r||'<p class="empty">'+m+"</p>"}function f(){var e,n=Docsify.dom.find("div.search"),t=Docsify.dom.find(n,"input");Docsify.dom.on(n,"click",function(e){return"A"!==e.target.tagName&&e.stopPropagation()}),Docsify.dom.on(t,"input",function(n){clearTimeout(e),e=setTimeout(function(e){return c(n.target.value.trim())},100)})}function l(e,n){var t=Docsify.dom.getNode('.search input[type="search"]');if(t)if("string"==typeof e)t.placeholder=e;else{var o=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];t.placeholder=e[o]}}function d(e,n){if("string"==typeof e)m=e;else{var t=Object.keys(e).filter(function(e){return n.indexOf(e)>-1})[0];m=e[t]}}function u(e,n){var t=n.router.parse().query.s;a(),s(e,t),f(),t&&setTimeout(function(e){return c(t)},500)}function p(e,n){l(e.placeholder,n.route.path),d(e.noData,n.route.path)}var h,y={},m="",g={placeholder:"Type to search",noData:"No Results!",paths:"auto",maxAge:864e5},v=function(e,n){var t=Docsify.util,o=n.config.search||g;Array.isArray(o)?g.paths=o:"object"==typeof o&&(g.paths=Array.isArray(o.paths)?o.paths:"auto",g.maxAge=t.isPrimitive(o.maxAge)?o.maxAge:g.maxAge,g.placeholder=o.placeholder||g.placeholder,g.noData=o.noData||g.noData);var i="auto"===g.paths;e.mounted(function(e){u(g,n),!i&&r(g,n)}),e.doneEach(function(e){p(g,n),i&&r(g,n)})};$docsify.plugins=[].concat(v,$docsify.plugins)}();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docsify",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.1",
|
||||
"description": "A magical documentation generator.",
|
||||
"author": {
|
||||
"name": "qingwei-li",
|
||||
|
||||
@@ -15,7 +15,6 @@ var readFileSync = require('fs').readFileSync
|
||||
// init
|
||||
var renderer = new Renderer({
|
||||
template: readFileSync('./docs/index.template.html', 'utf-8').,
|
||||
context: './docs',
|
||||
config: {
|
||||
name: 'docsify',
|
||||
repo: 'qingwei-li/docsify'
|
||||
|
||||
@@ -11,7 +11,7 @@ function cwd (...args) {
|
||||
}
|
||||
|
||||
function mainTpl (config) {
|
||||
let html = `<nav class="app-nav${config.repo ? '' : 'no-badge'}"><!--navbar--></nav>`
|
||||
let html = `<nav class="app-nav${config.repo ? '' : ' no-badge'}"><!--navbar--></nav>`
|
||||
|
||||
if (config.repo) {
|
||||
html += tpl.corner(config.repo)
|
||||
@@ -28,12 +28,10 @@ function mainTpl (config) {
|
||||
export default class Renderer {
|
||||
constructor ({
|
||||
template,
|
||||
context,
|
||||
config,
|
||||
cache
|
||||
}) {
|
||||
this.html = template
|
||||
this.context = cwd(context || './')
|
||||
this.config = config = Object.assign({}, config, {
|
||||
routerMode: 'history'
|
||||
})
|
||||
@@ -54,7 +52,7 @@ export default class Renderer {
|
||||
|
||||
return isAbsolutePath(file)
|
||||
? file
|
||||
: cwd(this.context, `./${file}`)
|
||||
: cwd(`./${file}`)
|
||||
}
|
||||
|
||||
async renderToString (url) {
|
||||
@@ -113,26 +111,25 @@ export default class Renderer {
|
||||
}
|
||||
|
||||
async _loadFile (filePath) {
|
||||
let content
|
||||
try {
|
||||
if (isAbsolutePath(filePath)) {
|
||||
const res = await fetch(filePath)
|
||||
content = await res.text()
|
||||
this.lock = 0
|
||||
} else {
|
||||
content = await readFileSync(filePath, 'utf8')
|
||||
this.lock = 0
|
||||
}
|
||||
return content
|
||||
} catch (e) {
|
||||
this.lock = this.lock || 0
|
||||
if (++this.lock > 10) {
|
||||
this.lock = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (isAbsolutePath(filePath)) {
|
||||
const res = await fetch(filePath)
|
||||
return await res.text()
|
||||
} else {
|
||||
return readFileSync(filePath, 'utf8')
|
||||
}
|
||||
} catch (e) {
|
||||
const fileName = basename(filePath)
|
||||
const parentPath = cwd(filePath, '../..')
|
||||
|
||||
if (this.context.length < parentPath.length) {
|
||||
throw Error(`Not found file ${fileName}`)
|
||||
}
|
||||
|
||||
await this._loadFile(cwd(filePath, '../..', fileName))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docsify-server-renderer",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.1",
|
||||
"description": "docsify server renderer",
|
||||
"author": {
|
||||
"name": "qingwei-li",
|
||||
|
||||
@@ -50,6 +50,7 @@ export function fetchMixin (proto) {
|
||||
const root = getParentPath(this.route.path)
|
||||
const path = this.router.getFile(root + coverpage)
|
||||
|
||||
console.log(this.route.path, root, path)
|
||||
if (this.route.path !== '/' || !coverpage) {
|
||||
this._renderCover()
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import { helper as helperTpl, tree as treeTpl } from './tpl'
|
||||
import { genTree } from './gen-tree'
|
||||
import { slugify } from './slugify'
|
||||
import { emojify } from './emojify'
|
||||
import { getBasePath, isAbsolutePath, getPath } from '../router/util'
|
||||
import { isAbsolutePath, getPath } from '../router/util'
|
||||
import { isFn, merge, cached } from '../util/core'
|
||||
|
||||
export class Compiler {
|
||||
@@ -14,7 +14,7 @@ export class Compiler {
|
||||
this.cacheTree = {}
|
||||
this.toc = []
|
||||
this.linkTarget = config.externalLinkTarget || '_blank'
|
||||
this.contentBase = getBasePath(config.basePath)
|
||||
this.contentBase = router.getBasePath()
|
||||
|
||||
const renderer = this._initRenderer()
|
||||
let compile
|
||||
|
||||
@@ -5,7 +5,7 @@ import tinydate from 'tinydate'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { Compiler } from './compiler'
|
||||
import { getAndActive, sticky } from '../event/sidebar'
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../router/util'
|
||||
import { getPath, isAbsolutePath } from '../router/util'
|
||||
import { isMobile } from '../util/env'
|
||||
import { isPrimitive } from '../util/core'
|
||||
import { scrollActiveSidebar, scroll2Top } from '../event/scroll'
|
||||
@@ -143,7 +143,7 @@ export function renderMixin (proto) {
|
||||
|
||||
dom.toggleClass(el, 'add', 'has-mask')
|
||||
if (!isAbsolutePath(m[1])) {
|
||||
path = getPath(getBasePath(this.config.basePath), m[1])
|
||||
path = getPath(this.router.getBasePath(), m[1])
|
||||
}
|
||||
el.style.backgroundImage = `url(${path})`
|
||||
el.style.backgroundSize = 'cover'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getBasePath, getPath, isAbsolutePath } from '../util'
|
||||
import { getPath, isAbsolutePath } from '../util'
|
||||
import { noop } from '../../util/core'
|
||||
|
||||
function getAlias (path, alias) {
|
||||
@@ -18,9 +18,13 @@ export class History {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
getBasePath () {
|
||||
return this.config.basePath
|
||||
}
|
||||
|
||||
getFile (path) {
|
||||
const { config } = this
|
||||
const base = getBasePath(config.basePath)
|
||||
const base = this.getBasePath()
|
||||
|
||||
path = config.alias ? getAlias(path, config.alias) : path
|
||||
path = getFileName(path)
|
||||
|
||||
@@ -20,6 +20,15 @@ export class HashHistory extends History {
|
||||
this.mode = 'hash'
|
||||
}
|
||||
|
||||
getBasePath () {
|
||||
const path = window.location.pathname || ''
|
||||
const base = this.config.basePath
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
}
|
||||
|
||||
getCurrentPath () {
|
||||
// We can't use location.hash here because it's not
|
||||
// consistent across browsers - Firefox will pre-decode it!
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { cached } from '../util/core'
|
||||
import { inBrowser } from '../util/env'
|
||||
|
||||
const decode = decodeURIComponent
|
||||
const encode = encodeURIComponent
|
||||
@@ -32,15 +31,6 @@ export function stringifyQuery (obj) {
|
||||
return qs.length ? `?${qs.join('&')}` : ''
|
||||
}
|
||||
|
||||
export const getBasePath = cached((base = '') => {
|
||||
// TODO
|
||||
const path = inBrowser ? window.location.pathname : ''
|
||||
|
||||
return /^(\/|https?:)/g.test(base)
|
||||
? base
|
||||
: cleanPath(path + '/' + base)
|
||||
})
|
||||
|
||||
export function getPath (...args) {
|
||||
return cleanPath(args.join('/'))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { search } from './search'
|
||||
|
||||
let dom
|
||||
let NO_DATA_TEXT = ''
|
||||
|
||||
function style () {
|
||||
@@ -65,8 +64,8 @@ function style () {
|
||||
.search p.empty {
|
||||
text-align: center;
|
||||
}`
|
||||
const style = dom.create('style', code)
|
||||
dom.appendTo(dom.head, style)
|
||||
const style = Docsify.dom.create('style', code)
|
||||
Docsify.dom.appendTo(Docsify.dom.head, style)
|
||||
}
|
||||
|
||||
function tpl (opts, defaultValue = '') {
|
||||
@@ -74,16 +73,16 @@ function tpl (opts, defaultValue = '') {
|
||||
`<input type="search" value="${defaultValue}" />` +
|
||||
'<div class="results-panel"></div>' +
|
||||
'</div>'
|
||||
const el = dom.create('div', html)
|
||||
const aside = dom.find('aside')
|
||||
const el = Docsify.dom.create('div', html)
|
||||
const aside = Docsify.dom.find('aside')
|
||||
|
||||
dom.toggleClass(el, 'search')
|
||||
dom.before(aside, el)
|
||||
Docsify.dom.toggleClass(el, 'search')
|
||||
Docsify.dom.before(aside, el)
|
||||
}
|
||||
|
||||
function doSearch (value) {
|
||||
const $search = dom.find('div.search')
|
||||
const $panel = dom.find($search, '.results-panel')
|
||||
const $search = Docsify.dom.find('div.search')
|
||||
const $panel = Docsify.dom.find($search, '.results-panel')
|
||||
|
||||
if (!value) {
|
||||
$panel.classList.remove('show')
|
||||
@@ -105,22 +104,23 @@ function doSearch (value) {
|
||||
}
|
||||
|
||||
function bindEvents () {
|
||||
const $search = dom.find('div.search')
|
||||
const $input = dom.find($search, 'input')
|
||||
const $search = Docsify.dom.find('div.search')
|
||||
const $input = Docsify.dom.find($search, 'input')
|
||||
|
||||
let timeId
|
||||
// Prevent to Fold sidebar
|
||||
dom.on($search, 'click',
|
||||
Docsify.dom.on($search, 'click',
|
||||
e => e.target.tagName !== 'A' && e.stopPropagation())
|
||||
dom.on($input, 'input', e => {
|
||||
Docsify.dom.on($input, 'input', e => {
|
||||
clearTimeout(timeId)
|
||||
timeId = setTimeout(_ => doSearch(e.target.value.trim()), 100)
|
||||
})
|
||||
}
|
||||
|
||||
function updatePlaceholder (text, path) {
|
||||
const $input = dom.getNode('.search input[type="search"]')
|
||||
const $input = Docsify.dom.getNode('.search input[type="search"]')
|
||||
|
||||
if (!$input) return
|
||||
if (typeof text === 'string') {
|
||||
$input.placeholder = text
|
||||
} else {
|
||||
@@ -139,7 +139,6 @@ function updateNoData (text, path) {
|
||||
}
|
||||
|
||||
export function init (opts, vm) {
|
||||
dom = Docsify.dom
|
||||
const keywords = vm.router.parse().query.s
|
||||
|
||||
style()
|
||||
|
||||
@@ -41,13 +41,12 @@ function saveData (maxAge) {
|
||||
export function genIndex (path, content = '', router) {
|
||||
const tokens = window.marked.lexer(content)
|
||||
const slugify = window.Docsify.slugify
|
||||
const toURL = router.toURL
|
||||
const index = {}
|
||||
let slug
|
||||
|
||||
tokens.forEach(token => {
|
||||
if (token.type === 'heading' && token.depth <= 2) {
|
||||
slug = toURL(path, { id: slugify(token.text) })
|
||||
slug = router.toURL(path, { id: slugify(token.text) })
|
||||
index[slug] = { slug, title: token.text, body: '' }
|
||||
} else {
|
||||
if (!slug) return
|
||||
|
||||
Reference in New Issue
Block a user