Ejemplo n.º 1
0
def handle(app_config):
    slug = request.args.get(':')
    if not slug:
        return '<meta http-equiv="refresh" content="2; url=?:=home"> redirect'
    if not is_valid_slug(slug):
        return 'Invalid page ID'

    with DbTree(app_config['db_uri']) as db:
        page_info = db.get_page_info(slug)

    tree_html = compile_tree(page_info.tree)
    parser = Parser(slug)
    ast_list = [parser.parse_string(string, content_id)
                for string, content_id in page_info.content_pair_iter()]
    with DbTitle(app_config['db_uri']) as db:
        db.put_titles_in(parser.acc)
    notes_html_list = (compile_notes(cons, parser.acc) for cons in ast_list)

    # use the "directory" part only
    page_info.path.pop()

    return render_template(
        'view.html',
        title=page_info.title,
        nav_edit=url_for('edit') + slug_to_link(slug),
        unlisted=page_info.unlisted,
        directory_of_page=page_info.path,
        prev_article=page_info.prev,
        next_article=page_info.next,
        mtime_str=page_info.mtime_str,
        sidebar_html=tree_html,
        notes_html_list=notes_html_list
    )