def edit_post(post_list, post_index, config, editor=None, is_menu=False): safe_name = get.filter_name(config["name"]) if post_list[post_index]["name"] is not config["name"]: shutil.move("./document/{}.md".format(post_list[post_index]["name"]), "./document/{}.md".format(safe_name)) if os.path.exists("./document/{}.json".format( post_list[post_index]["name"])): shutil.move( "./document/{}.json".format(post_list[post_index]["name"]), "./document/{}.json".format(safe_name)) config_file = json.loads( file.read_file("./document/{}.json".format(safe_name))) config_file["title"] = config["title"] if "time" in config: config_file = config["time"] file.write_file("./document/{}.json".format(safe_name), file.json_format_dump(config_file)) post_list[post_index]["name"] = safe_name if editor is not None: os.system("{0} ./document/{1}.md".format(editor, safe_name)) post_list[post_index]["title"] = config["title"] file_url = "./config/page.json" if is_menu: file_url = "./config/menu.json" file.write_file(file_url, file.json_format_dump(post_list)) console.log("Success", "Edit a new article successfully!")
def new_post_init(config, independent=False): title = config["title"] name = get.filter_name(config["name"]) if not os.path.exists("./document/{}.md".format(name)): editor = system_info["Editor"] os.system("{0} ./document/{1}.md".format(editor, name)) post_info = {"name": name, "title": title, "time": time.time()} if not os.path.exists("./document/{}.md".format(name)): console.log("Error", "Cannot find [./document/{}.md] file".format(name)) return if not independent: excerpt = get.get_excerpt("./document/{}.md".format(name)) post_info["excerpt"] = excerpt write_json = post_info page_config = "./document/{}.json".format(name) if not independent: write_json = json.loads(file.read_file("./config/page.json")) write_json.insert(0, post_info) page_config = "./config/page.json" file.write_file( page_config, json.dumps(write_json, indent=4, sort_keys=False, ensure_ascii=False)) console.log("Success", "Create a new article successfully!")
def new_post(config, independent=False): system_info = json.loads(file.read_file("./config/system.json")) title = config["title"] name = get.filter_name(config["name"]) post_uuid = str(uuid.uuid5(uuid.NAMESPACE_URL, name)) if "uuid" in config: post_uuid = config["uuid"] if not os.path.exists("./document/{}.md".format(name)): editor = system_info["Editor"] os.system("{0} ./document/{1}.md".format(editor, name)) post_info = { "uuid": post_uuid, "name": name, "title": title, "time": round(time.time()) } if not os.path.exists("./document/{}.md".format(name)): console.log("Error", "Cannot find [./document/{}.md]".format(name)) exit(1) if not independent: excerpt = get.get_excerpt("./document/{}.md".format(name)) post_info["excerpt"] = excerpt write_json = post_info page_config = "./document/{}.json".format(name) if not independent: write_json = json.loads(file.read_file("./config/page.json")) write_json.insert(0, post_info) page_config = "./config/page.json" file.write_file(page_config, file.json_format_dump(write_json)) console.log("Success", "Create a new article successfully!")
def use_text_mode(args): if args.command == "qrcode": system_config = json.loads(file.read_file("./config/system.json")) from common import install_module install_module.install_and_import("qrcode_terminal") import qrcode_terminal if len(system_config["API_Password"]) == 0 or len(system_config["Project_URL"]) == 0: console.log("Error", "Check the API_Password and Project_URL configuration items") exit(1) try: password_md5 = json.loads(system_config["API_Password"])["hash_password"] except (ValueError, KeyError, TypeError): exit(1) console.log("Info", "Please use the client to scan the following QR Code") config_json = json.dumps({"url": system_config["Project_URL"], "password": password_md5}) qrcode_terminal.draw(config_json) exit(0) if args.command == "upgrade": from manage import upgrade if upgrade.upgrade_check(): if not args.yes: start_to_pull = input('Find new version, do you want to upgrade? [y/N]') if start_to_pull.lower() == 'yes' or start_to_pull.lower() == 'y' or args.yes: upgrade.upgrade_pull() exit(0) console.log("Info", "No upgrade found") exit(0) if args.command == "build-page": from manage import build_static_page build_static_page.publish() exit(0) from manage import build_rss, post_manage if args.command == "new": config = None if args.config is not None: config = json.loads(file.read_file(args.config)) if config is None: print("Please enter the title of the article:") title = input().strip() if len(title) == 0: console.log("Error", "The title can not be blank.") exit(1) name = get.get_name(title) print("Please enter the slug [{}]:".format(name)) name2 = input().strip() if len(name2) != 0: name = get.filter_name(name2) if os.path.exists("./document/{}.md".format(name)): console.log("Error", "File [./document/{}.md] already exists".format(name)) exit(1) if len(name) != 0 and len(title) != 0: config = {"title": title, "name": name} post_manage.new_post(config, args.independent) build_rss.build_rss() exit(0) if args.command == "update": if post_manage.update_post(): build_rss.build_rss() exit(0)
def edit(page_list, post_index, config, editor=None, is_menu=False): if page_list[post_index]["name"] is not config["name"]: safe_name = get.filter_name(config["name"]) shutil.move("./document/{}.md".format(page_list[post_index]["name"]), "./document/{}.md".format(safe_name)) if os.path.exists("./document/{}.json".format(page_list[post_index]["name"])): shutil.move("./document/{}.json".format(page_list[post_index]["name"]), "./document/{}.json".format(safe_name)) config_file = json.loads(file.read_file("./document/{}.json".format(safe_name))) config_file["title"] = config["title"] file.write_file("./document/{}.json".format(safe_name), json.dumps(config_file, indent=4, sort_keys=False, ensure_ascii=False)) page_list[post_index]["name"] = safe_name if editor is not None: os.system("{0} ./document/{1}.md".format(editor, safe_name)) page_list[post_index]["title"] = config["title"] file_url = "./config/page.json" if is_menu: file_url = "./config/menu.json" file.write_file(file_url, json.dumps(page_list, indent=4, sort_keys=False, ensure_ascii=False)) console.log("Success", "Edit a new article successfully!")
def get_name(name_input): p = Pinyin() name = name_input.replace(" ", "-") name = get.filter_name(name) return p.get_pinyin(name)
config = None name = "" title = "" if args.config is not None: config = json.loads(file.read_file(args.config)) if config is None: print("Please enter the title of the article:") title = input().strip() if len(title) == 0: console.log("Error", "The title can not be blank.") exit(1) name = get.get_name(title, system_config["Pinyin"]) print("Please enter the slug [{}]:".format(name)) name2 = input().strip() if len(name2) != 0: name = get.filter_name(name2) if os.path.exists("./document/{}.md".format(name)): console.log( "Error", "File [./document/{}.md] already exists".format(name)) exit(1) if len(name) != 0 and len(title) != 0: config = {"title": title, "name": name} post_manage.new_post(config, args.independent) build_rss.build_rss() exit(0) if args.command == "update": if post_manage.update_post(): build_rss.build_rss() exit(0)