Esempio n. 1
0
def publish():
    load_config()

    if not os.path.isdir("./static_page"):
        os.mkdir("./static_page")
    os.system("cd ./static_page && rm -rf *")

    page_row = page.get_page_row(system_config["Paging"], len(page_list))

    console.log("Build", "Processing file: ./static_page/index.html")
    content = page.build_index(1, page_row, system_config, page_list, menu_list, template_config, i18n)
    file.write_file("./static_page/index.html", content)

    if page_row != 1:
        os.mkdir("./static_page/index/")
        file.write_file("./static_page/index/1.html", "<meta http-equiv='refresh' content='0.1; url=/'>")
        for page_id in range(2, page_row + 1):
            console.log("Build", "Processing file: ./static_page/index/{0}.html".format(str(page_id)))
            content = page.build_index(page_id, page_row, system_config, page_list, menu_list, template_config, i18n)
            file.write_file("./static_page/index/{0}.html".format(str(page_id)), content)

    os.mkdir("./static_page/post/")
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    tasks = [
        build_post_page(filename, page_name_list, page_list, system_config, menu_list, template_config, i18n)
        for filename in glob.glob("./document/*.md")]
    if len(tasks) != 0:
        loop.run_until_complete(asyncio.wait(tasks))
        loop.close()
    if os.path.exists("./document/rss.xml"):
        shutil.copyfile("./document/rss.xml", "./static_page/rss.xml")

    shutil.copytree("./templates/{0}/static".format(system_config["Theme"]),
                    "./static_page/static/{0}/".format(system_config["Theme"]))
    if os.path.exists("./templates/static/user_file"):
        shutil.copytree("./templates/static/user_file", "./static_page/static/user_file")
    console.log("Success", "Create Github Page Success!")

    if not os.path.exists("./static_page/.git"):
        return False
    import git
    localtime = time.asctime(time.localtime(time.time()))
    try:
        repo = git.Repo("./static_page")
        repo.git.add("--all")
        if not repo.is_dirty():
            console.log("Success", "Build complete,No changes found.")
            return True
        repo.git.commit("-m Release time:{0}".format(localtime))
    except git.exc.GitCommandError as e:
        console.log("Error", e.args[2].decode())
        return False
    console.log("Info", "Push to the remote.")
    remote = repo.remote()
    remote.push()
    console.log("Success", "Done.")
    return True
Esempio n. 2
0
def index_route(page_index=1):
    page_url = "/index/{0}/".format(page_index)
    localtime = time.localtime(time.time())
    global last_build_year
    if last_build_year != localtime[0]:
        last_build_year = localtime[0]
        cache_index.clear()
        cache_post.clear()
    if page_url in cache_index:
        console.log("Success", "Get cache Success: {0}".format(page_url))
        return cache_index[page_url]
    console.log("Info", "Trying to build: {0}".format(page_url))
    page_row = page.get_page_row(system_config["Paging"], len(page_list))
    if page_index == 0 or page_index > page_row:
        abort(404)
    result = page.build_index(page_index, page_row, system_config, page_list,
                              menu_list, template_config, i18n)
    if result is None:
        abort(404)
    console.log("Info", "Writing to cache: {0}".format(page_url))
    if len(cache_index) >= 50:
        page_keys = sorted(cache_index.keys())
        console.log("Info", "Delete cache: {0}".format(page_keys[0]))
        del cache_index[page_keys[0]]
    cache_index[page_url] = result
    console.log("Success", "Get success: {0}".format(page_url))
    return result
Esempio n. 3
0
def index_route(page_index=1):
    page_url = "/index/{0}/".format(page_index)
    result = get_index_cache(page_url)
    if result is None:
        page_row = page.get_page_row(system_config["Paging"], len(page_list))
        if page_index == 0 or page_index > page_row:
            abort(404)
        result = page.build_index(page_index, page_row, system_config,
                                  page_list, menu_list, template_config, i18n,
                                  static_file_dict)
    if result is None:
        abort(404)
    write_index_cache(page_url, result)
    console.log("Success", "Get success: {0}".format(page_url))
    return result