Skip to content

Commit

Permalink
feat: add search, close #43
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 9, 2017
1 parent 12e2479 commit eb5ff3e
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
@@ -1,7 +1,9 @@
{
"extends": ["vue"],
"env": {
"browser": true
},
"globals": {
"XMLHttpRequest": true,
"__docsify__": true
"$docsify": true
}
}
3 changes: 2 additions & 1 deletion build/build-css.js
Expand Up @@ -2,6 +2,7 @@ var fs = require('fs')
var cssnano = require('cssnano').process
var resolve = require('path').resolve
var postcss = require('postcss')
var isProd = process.argv[process.argv.length - 1] !== '--dev'

var processor = postcss([require('postcss-salad')({
features: {
Expand Down Expand Up @@ -34,7 +35,7 @@ list.forEach(function (file) {
.then(function (result) {
save(file, result.css)
console.log('salad - ' + file)
cssnano(loadLib(file))
isProd && cssnano(loadLib(file))
.then(function (result) {
saveMin(file, result.css)
console.log('cssnao - ' + file)
Expand Down
16 changes: 14 additions & 2 deletions build/build.js
Expand Up @@ -3,6 +3,7 @@ var buble = require('rollup-plugin-buble')
var commonjs = require('rollup-plugin-commonjs')
var nodeResolve = require('rollup-plugin-node-resolve')
var uglify = require('rollup-plugin-uglify')
var isProd = process.argv[process.argv.length - 1] !== '--dev'

var build = function (opts) {
rollup
Expand All @@ -16,7 +17,7 @@ var build = function (opts) {
console.log(dest)
bundle.write({
format: 'iife',
moduleName: opts.moduleName || 'Docsify',
moduleName: opts.moduleName || 'D',
dest: dest
})
})
Expand All @@ -30,8 +31,19 @@ build({
output: 'docsify.js',
plugins: [commonjs(), nodeResolve()]
})
build({
isProd && build({
entry: 'index.js',
output: 'docsify.min.js',
plugins: [commonjs(), nodeResolve(), uglify()]
})
build({
entry: 'plugins/search.js',
output: 'plugins/search.js',
moduleName: 'D.Search'
})
isProd && build({
entry: 'plugins/search.js',
output: 'plugins/search.min.js',
moduleName: 'D.Search',
plugins: [uglify()]
})
19 changes: 18 additions & 1 deletion dev.html
Expand Up @@ -6,7 +6,24 @@
<link rel="stylesheet" href="/themes/vue.css">
</head>
<body>
<nav>
<a href="#/">En</a>
<a href="#/zh-cn">中文</a>
</nav>
<div id="app"></div>
</body>
<script src="/lib/docsify.js" data-repo="qingwei-li/docsify" data-name="docsify" data-auto2top></script>
<script>
window.$docsify = {
search: {
maxAge: 0
}
}
</script>
<script
src="/lib/docsify.js"
data-repo="qingwei-li/docsify"
data-name="docsify"
data-base-path="docs/"
data-auto2top></script>
<script src="/lib/plugins/search.js"></script>
</html>
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -10,7 +10,8 @@
],
"scripts": {
"build": "rm -rf lib themes && node build/build.js && mkdir lib/themes && mkdir themes && node build/build-css.js",
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run build'",
"dev:build": "rm -rf lib themes && mkdir themes && node build/build.js --dev && node build/build-css.js --dev",
"dev": "node app.js & nodemon -w src -e js,css --exec 'npm run dev:build'",
"test": "eslint src test"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -9,7 +9,7 @@ export function scrollActiveSidebar () {

let hoveredOverSidebar = false
const anchors = document.querySelectorAll('.anchor')
const sidebar = document.querySelector('.sidebar>div')
const sidebar = document.querySelector('.sidebar')
const sidebarHeight = sidebar.clientHeight

const nav = {}
Expand Down

0 comments on commit eb5ff3e

Please sign in to comment.