示例#1
0
def interiors():
    from db import pages
    page = pages.get('interiors')
    text = render_template('interiors.html', items=page['items'])
    return render_template(
        'base.html',
        page=page,
        text=text,
    )
示例#2
0
def interior(folder):
    from db import pages
    page = pages.get('interiors')
    text = render_template('interior.html',
                           folder=folder,
                           images=page['items'][folder])
    return render_template(
        'base.html',
        page=page,
        text=text,
    )
示例#3
0
def by_slug(slug):
    from db import pages
    page = pages.get(slug)
    if page:
        text = open('html/{}.html'.format(slug)).read().decode('utf-8')
    else:
        text = ''
    return render_template(
        'base.html',
        page=page,
        text=text,
    )
示例#4
0
def secret_edit(page_id):
    if request.method == 'GET':
        page = pages.get(page_id)
        tags_ = tags.get_list()
        for tag in tags_:
            if pages.TAGS not in page or tag['id'] not in page[pages.TAGS]:
                tag['exists'] = False
            else:
                tag['exists'] = True
        return render_template('secret/new_edit.html',
                               url=url_for('secret_edit', page_id=page_id),
                               id_=page[pages.ID],
                               title=page[pages.TITLE],
                               raw=(page[pages.TYPE] == pages.TYPE_RAW),
                               content=page[pages.CONTENT],
                               tags=tags_)
    else:
        page_title = request.form['title']
        page_type = request.form['type']
        page_id = request.form['id']
        page_content = request.form['content'].replace('\r\n', '\n')
        page_tags = request.form.getlist('tags')

        if page_type == pages.TYPE_MARKDOWN:
            html = markdown.markdown(page_content,
                                     extensions=['gfm'],
                                     extras=['fenced-code-blocks'])
        else:
            html = page_content
        links = analyze_html(html)
        if '/' + page_id in links:
            links.remove('/' + page_id)

        pages.update(id_=page_id,
                     title=page_title,
                     type_=page_type,
                     content=page_content,
                     tags=page_tags,
                     link_to=links)

        if settings.BACKUP_ENABLED:
            if settings.BACKUP_AS_HTML:
                backup_content = html
            else:
                backup_content = page_content
            path = settings.BACKUP_DIRECTORY_PATH + '/' + page_title + '-' + page_id
            if page_type == pages.TYPE_MARKDOWN:
                path += '.md'
            else:
                path += '.html'
            backup(backup_content, path)

        return redirect(url_for('secret_top'))
示例#5
0
def render_page(page_id: str):
    page = pages.get(page_id)
    if page is None:
        abort(404)

    page_content = page[pages.CONTENT]

    page_type = page[pages.TYPE]
    if page_type == pages.TYPE_MARKDOWN:
        page_content = markdown.markdown(page_content,
                                         extensions=['gfm'],
                                         extras=['fenced-code-blocks'])

    page_content = process_related(page_content,
                                   pages.get_by_link(['/' + page_id]))

    return render_template('content/page.html',
                           title=page[pages.TITLE] + settings.PAGE_NAME_SUFFIX,
                           content=page_content)