memegen.routes.index   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get() 0 13 1
A _load_readme() 0 10 2
1
import random
2
from pathlib import Path
3
4
from flask import (Blueprint, Markup,
5
                   render_template, current_app, make_response)
6
from markdown import markdown
7
8
from ._utils import samples
9
10
11
blueprint = Blueprint('index-page', __name__)
12
13
14
@blueprint.route("/")
15
def get():
16
    template_images = list(samples(blank=True))
17
    html = render_template(
18
        "index.html",
19
        template_images=template_images,
20
        default_template=random.choice(template_images)['key'],
21
        readme=_load_readme(),
22
        config=current_app.config,
23
    )
24
    response = make_response(html)
25
    response.headers['Cache-Control'] = f'max-age={60*60*12}'
26
    return response
27
28
29
def _load_readme():
30
    path = Path(current_app.config['ROOT'], 'README.md')
31
    with path.open() as f:
32
        text = f.read()
33
        content = text.split('<!--content-->')[-1]
34
        html = markdown(content, extensions=[
35
            'markdown.extensions.tables',
36
            'pymdownx.magiclink',
37
        ])
38
        return Markup(html)
39