Add search to docs

This commit is contained in:
ckcz123 2020-05-09 19:10:44 +08:00
parent ced1ac34d3
commit 1072a134da
2 changed files with 19 additions and 14 deletions

View File

@ -23,18 +23,16 @@
// basepath: '../docs/',
// Search Support
// search: {
// maxAge: 43200000, // 过期时间,单位毫秒,默认一天
// paths: 'auto',
// placeholder: {
// '/en/': 'Search',
// '/': '搜索',
// },
// noData: {
// '/en/': 'No Results',
// '/': '找不到结果',
// },
// },
search: {
maxAge: 43200000, // 过期时间,单位毫秒,默认一天
paths: 'auto',
placeholder: {
'/': '搜索文档...',
},
noData: {
'/': '找不到结果',
},
},
// load sidebar from _sidebar.md
loadSidebar: '_sidebar',
@ -46,5 +44,6 @@
}
</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>
</html>

View File

@ -24,7 +24,7 @@ except:
p("需要flask才可使用本服务。\n安装方式:%s install flask" % ("pip3" if isPy3 else "pip"))
exit(1)
app = Flask(__name__, static_folder='')
app = Flask(__name__, static_folder='__static__')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
@app.after_request
@ -45,7 +45,7 @@ def get_mimetype(path):
return mimetypes.guess_type(path)[0] or 'application/octet-stream'
def get_file(path):
if not os.path.exists(path):
if not os.path.isfile(path):
abort(404)
return None
if not is_sub(path):
@ -61,6 +61,12 @@ def root():
@app.route('/<path:path>', methods=['GET'])
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))
def process_request():