def get_article_by_category(category): """获取指定目录的索引信息 """ try: pager = int(request.args['pager']) except: pager = 0 try: aids = IndexData.get_index_data().get("category_index").get(category) except Exception as error: print("出错了,重新加载..."+str(error)) generate() aids = IndexData.get_index_data().get("category_index").get(category) # 这里是预防传入的pager大于存在的篇幅数 if aids is None: return jsonify(noDatas=True) if pager * 10 >= len(aids): articles = {i: IndexData.get_index_data().get("article_index")[i] for i in aids} return jsonify(nextPagerDatas=True) if len(aids) > (pager + 1) * 10: aids = aids[pager * 10:(pager + 1) * 10] has_pager = True else: aids = aids[pager * 10:len(aids)] has_pager = False articles = {i: IndexData.get_index_data().get("article_index")[i] for i in aids} return jsonify(articles=articles, hasPager=has_pager, nextPagerDatas=False)
def reload_index(): """重新加载索引 """ IndexData.reload_index_data() return jsonify({ "msg": "ok" })
def generate(): _reload_global() clean() load_md_files(INPUT_CONTENT) scan_md() dump_index() from utils.helper import IndexData IndexData.reload_index_data() pass
def get_all_article_index(): """获取所有文章索引信息 """ try: return jsonify(IndexData.get_index_data().get("article_index")) except Exception as error: print("出错了,重新加载..." + str(error)) generate() return jsonify(IndexData.get_index_data().get("article_index"))
def get_article_by_tag(tag): """获取指定标签的索引信息 """ aids = IndexData.get_index_data().get("tag_inverted_index").get(tag) articles = { i: IndexData.get_index_data().get("article_index")[i] for i in aids } return jsonify(articles)
def reload_index(): """重新加载索引 """ try: IndexData.reload_index_data() return jsonify({"msg": "ok"}) except Exception as e: current_app.logger.exception(e) return jsonify({"msg": "failed"})
def generate_index(): """生成索引信息 """ try: generate() IndexData.reload_index_data() return jsonify({"msg": "ok"}) except Exception as e: current_app.logger.exception(e) return jsonify({"msg": "failed"})
def upload_article(): """上传文件 1. 保存至本地 2. md转换为html 3. 重新加载索引信息 """ f = request.files["md_file"] f_name = secure_filename(f.filename) f.save(os.path.join(INPUT_CONTENT, f_name)) generate() IndexData.reload_index_data() return redirect(url_for("page_articles"))
def reload_index(): """重新加载索引 """ try: IndexData.reload_index_data() return jsonify({ "msg": "ok" }) except Exception as e: current_app.logger.exception(e) return jsonify({ "msg": "failed" })
def upload(): from generate import generate """ 更新文章索引 """ try: generate() IndexData.reload_index_data() except Exception as error: print(error) return jsonify({'status': '更新失败'}) return jsonify({'status': '更新成功'})
def generate_index(): """生成索引信息 """ try: generate() IndexData.reload_index_data() return jsonify({ "msg": "ok" }) except Exception as e: current_app.logger.exception(e) return jsonify({ "msg": "failed" })
def upload(): from generate import INPUT_CONTENT, generate """上传文件 1. 保存至本地 2. md转换为html 3. 重新加载索引信息 """ try: f = request.files["file_data"] f_name = secure_filename(f.filename) print('1' + os.path.abspath('.')) print('2' + INPUT_CONTENT + f_name) print('3' + os.path.abspath(__file__)) f.save(INPUT_CONTENT + f_name) generate() IndexData.reload_index_data() except Exception as error: print(error) return jsonify({'status': '上传失败'}) return jsonify({'status': '上传成功'})
def get_article_by_tag(tag): """获取指定标签的索引信息 """ try: pager = int(request.args['pager']) except: pager = 0 aids = IndexData.get_index_data().get("tag_inverted_index").get(tag) # 这里是预防传入的pager大于存在的篇幅数 if aids is None: return jsonify(noDatas=True) if pager * 10 >= len(aids): articles = {i: IndexData.get_index_data().get("article_index")[i] for i in aids} return jsonify(nextPagerDatas=True) if len(aids) > (pager + 1) * 10: aids = aids[pager * 10:(pager + 1) * 10] has_pager = True else: aids = aids[pager * 10:len(aids)] has_pager = False articles = {i: IndexData.get_index_data().get("article_index")[i] for i in aids} return jsonify(articles=articles, hasPager=has_pager, nextPagerDatas=False)
def get_tag_index(): """获取标签的倒排索引 """ return jsonify(IndexData.get_index_data().get("tag_inverted_index"))
def get_all_article_index(): """获取所有文章索引信息 """ return jsonify(IndexData.get_index_data().get("article_index"))
def get_article_by_tag(tag): """获取指定标签的索引信息 """ aids = IndexData.get_index_data().get("tag_inverted_index").get(tag) articles = {i: IndexData.get_index_data().get("article_index")[i] for i in aids} return jsonify(articles)
def get_author_index(): """获取作者的倒排索引 """ return jsonify(IndexData.get_index_data().get("author_inverted_index"))