diff --git a/build/build.js b/build/build.js new file mode 100644 index 00000000..c46343e8 --- /dev/null +++ b/build/build.js @@ -0,0 +1,24 @@ +var rollup = require('rollup') +var buble = require('rollup-plugin-buble') + +var build = function (entry, moduleName) { + rollup + .rollup({ + entry: 'src/' + entry, + plugins: [buble()] + }) + .then(function (bundle) { + bundle.write({ + globals: { + marked: 'marked', + prismjs: 'Prism' + }, + format: 'umd', + moduleName: moduleName, + dest: 'lib/' + entry + }) + }) +} + +build('docsify.js', 'Docsify') +build('plugins/nav.js', 'Docsify.Nav') diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index b6ba9f29..00000000 --- a/docs/README.md +++ /dev/null @@ -1 +0,0 @@ -# ahhh \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/lib/docsify.js b/lib/docsify.js index a6360d98..2022c7d4 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -20,6 +20,49 @@ var ajax = function (url, options) { } }; +/** + * @link from https://github.com/killercup/grock/blob/5280ae63e16c5739e9233d9009bc235ed7d79a50/styles/solarized/assets/js/behavior.coffee#L54-L81 + */ +var tocToTree = function (toc) { + var headlines = []; + var last = {}; + + toc.forEach(function (headline) { + var level = headline.level || 1; + var len = level - 1; + + if (last[len]) { + last[len].children = last[len].children || []; + last[len].children.push(headline); + } else { + headlines.push(headline); + last[level] = headline; + } + }); + + return headlines +}; + +var buildHeadlinesTree = function (tree, tpl) { + if ( tpl === void 0 ) tpl = ''; + + if (!tree || !tree.length) { return '' } + + tree.forEach(function (node) { + tpl += "
  • " + (node.title) + "
  • "; + if (node.children) { + tpl += "
  • ' +}; + +var genToc = function (toc) { + return buildHeadlinesTree(tocToTree(toc), '