Esempio n. 1
0
def post_route(file_name=None):
    if file_name is None or not os.path.exists(
            "./document/{0}.md".format(file_name)):
        abort(404)
    page_url = "/post/{0}/".format(file_name)
    global last_build_year
    localtime = time.localtime(time.time())
    if last_build_year != localtime[0]:
        console.log("Info", "Found a year change, cache cleanup.")
        last_build_year = localtime[0]
        cache_index.clear()
        cache_post.clear()
    if page_url in cache_post:
        console.log("Success", "Get cache Success: {0}".format(page_url))
        return cache_post[page_url]
    page_info = None
    if file_name in page_name_list:
        this_page_index = page_name_list.index(file_name)
        page_info = page_list[this_page_index]
    result = page.build_page(file_name, system_config, page_info, menu_list,
                             template_config, i18n)
    console.log("Info", "Writing to cache: {0}".format(page_url))
    if len(cache_post) >= 50:
        page_keys = sorted(cache_post.keys())
        console.log("Info", "Delete cache: {0}".format(page_keys[0]))
        del cache_post[page_keys[0]]
    cache_post[page_url] = result
    console.log("Success", "Get success: {0}".format(page_url))

    return result
Esempio n. 2
0
def post_route(file_name=None):
    if file_name is None or not os.path.exists(
            "./document/{0}.md".format(file_name)):
        abort(404)
    page_url = "/post/{0}/".format(file_name)
    result = get_post_cache(page_url)
    if result is None:
        page_info = None
        if file_name in page_name_list:
            this_page_index = page_name_list.index(file_name)
            page_info = page_list[this_page_index]
        result = page.build_page(file_name, system_config, page_info,
                                 menu_list, template_config, i18n,
                                 static_file_dict)
        write_post_cache(page_url, result)
    console.log("Success", "Get success: {0}".format(page_url))
    return result
Esempio n. 3
0
def async_build_page(file_name, system_config, page_info, menu_list,
                     template_config, i18n):
    return page.build_page(file_name, system_config, page_info, menu_list,
                           template_config, i18n)
Esempio n. 4
0
def async_build_page(file_name, config, page_info, menu, template, i18n_config, static_file):
    return page.build_page(file_name, config, page_info, menu, template, i18n_config, static_file)