Add search to docs
This commit is contained in:
parent
ced1ac34d3
commit
1072a134da
@ -23,18 +23,16 @@
|
|||||||
// basepath: '../docs/',
|
// basepath: '../docs/',
|
||||||
|
|
||||||
// Search Support
|
// Search Support
|
||||||
// search: {
|
search: {
|
||||||
// maxAge: 43200000, // 过期时间,单位毫秒,默认一天
|
maxAge: 43200000, // 过期时间,单位毫秒,默认一天
|
||||||
// paths: 'auto',
|
paths: 'auto',
|
||||||
// placeholder: {
|
placeholder: {
|
||||||
// '/en/': 'Search',
|
'/': '搜索文档...',
|
||||||
// '/': '搜索',
|
},
|
||||||
// },
|
noData: {
|
||||||
// noData: {
|
'/': '找不到结果',
|
||||||
// '/en/': 'No Results',
|
},
|
||||||
// '/': '找不到结果',
|
},
|
||||||
// },
|
|
||||||
// },
|
|
||||||
|
|
||||||
// load sidebar from _sidebar.md
|
// load sidebar from _sidebar.md
|
||||||
loadSidebar: '_sidebar',
|
loadSidebar: '_sidebar',
|
||||||
@ -46,5 +44,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js"></script>
|
<script src="https://cdn.bootcss.com/docsify/4.5.5/docsify.min.js"></script>
|
||||||
|
<script src="https://cdn.bootcss.com/docsify/4.5.5/plugins/search.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
10
server.py
10
server.py
@ -24,7 +24,7 @@ except:
|
|||||||
p("需要flask才可使用本服务。\n安装方式:%s install flask" % ("pip3" if isPy3 else "pip"))
|
p("需要flask才可使用本服务。\n安装方式:%s install flask" % ("pip3" if isPy3 else "pip"))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='')
|
app = Flask(__name__, static_folder='__static__')
|
||||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
@ -45,7 +45,7 @@ def get_mimetype(path):
|
|||||||
return mimetypes.guess_type(path)[0] or 'application/octet-stream'
|
return mimetypes.guess_type(path)[0] or 'application/octet-stream'
|
||||||
|
|
||||||
def get_file(path):
|
def get_file(path):
|
||||||
if not os.path.exists(path):
|
if not os.path.isfile(path):
|
||||||
abort(404)
|
abort(404)
|
||||||
return None
|
return None
|
||||||
if not is_sub(path):
|
if not is_sub(path):
|
||||||
@ -61,6 +61,12 @@ def root():
|
|||||||
|
|
||||||
@app.route('/<path:path>', methods=['GET'])
|
@app.route('/<path:path>', methods=['GET'])
|
||||||
def static_file(path):
|
def static_file(path):
|
||||||
|
if os.path.isdir(path):
|
||||||
|
if not path.endswith('/'): path += '/'
|
||||||
|
path += 'index.html'
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
abort(404)
|
||||||
|
return None
|
||||||
return Response(get_file(path), mimetype = get_mimetype(path))
|
return Response(get_file(path), mimetype = get_mimetype(path))
|
||||||
|
|
||||||
def process_request():
|
def process_request():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user