diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fc778..af38890 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ + Updated Markdown extensions to work under latest version. + Like it or not, now gzip library is required. + Added CSS variables in the site style. ++ Templates are now with `.jinja2` extension. ## 0.6 diff --git a/app.py b/app.py index cb89d2f..26375bb 100644 --- a/app.py +++ b/app.py @@ -75,7 +75,7 @@ else: markdown_katex = None try: if _getconf('appearance', 'math') != 'off': - import markdown_katex + import markdown_katex #pragma: no cover except ImportError: pass @@ -497,7 +497,7 @@ def linebreaks(text): @app.route('/') def homepage(): page_limit = _getconf("appearance","items_per_page",20,cast=int) - return render_template('home.html', new_notes=Page.select() + return render_template('home.jinja2', new_notes=Page.select() .order_by(Page.touched.desc()).limit(page_limit)) @app.route('/robots.txt') @@ -512,19 +512,19 @@ def favicon(): @app.errorhandler(404) def error_404(body): - return render_template('notfound.html'), 404 + return render_template('notfound.jinja2'), 404 @app.errorhandler(403) def error_403(body): - return render_template('forbidden.html'), 403 + return render_template('forbidden.jinja2'), 403 @app.errorhandler(400) def error_400(body): - return render_template('badrequest.html'), 400 + return render_template('badrequest.jinja2'), 400 @app.errorhandler(500) def error_500(body): - return render_template('internalservererror.html'), 500 + return render_template('internalservererror.jinja2'), 500 # Middle point during page editing. def savepoint(form, is_preview=False, pageobj=None): @@ -539,7 +539,7 @@ def savepoint(form, is_preview=False, pageobj=None): page_id = pageobj.id if pageobj else None ) return render_template( - 'edit.html', + 'edit.jinja2', pl_url=form['url'], pl_title=form['title'], pl_text=form['text'], @@ -714,7 +714,7 @@ def view_unnamed(id): return redirect(p.get_url()) else: flash('The URL of this page is a reserved URL. Please change it.') - return render_template('view.html', p=p, rev=p.latest) + return render_template('view.jinja2', p=p, rev=p.latest) @app.route('/embed//') def embed_view(id): @@ -730,7 +730,7 @@ def embed_view(id): @app.route('/p/most_recent//') def view_most_recent(page=1): general_query = Page.select().order_by(Page.touched.desc()) - return render_template('listrecent.html', notes=general_query.paginate(page), + return render_template('listrecent.jinja2', notes=general_query.paginate(page), page_n=page, total_count=general_query.count(), min=min) @app.route('/p/random/') @@ -758,7 +758,7 @@ def page_leaderboard(): pages.append((p, score, p.back_links.count(), p.forward_links.count(), p.latest.length)) pages.sort(key = lambda x: (x[1], x[2], x[4], x[3]), reverse = True) - return render_template('leaderboard.html', pages=pages), headers + return render_template('leaderboard.jinja2', pages=pages), headers @app.route('//') def view_named(name): @@ -766,7 +766,7 @@ def view_named(name): p = Page.get(Page.url == name) except Page.DoesNotExist: abort(404) - return render_template('view.html', p=p, rev=p.latest) + return render_template('view.jinja2', p=p, rev=p.latest) @app.route('/init-config/tables/') def init_config_tables(): @@ -780,7 +780,7 @@ def history(id): p = Page[id] except Page.DoesNotExist: abort(404) - return render_template('history.html', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc())) + return render_template('history.jinja2', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc())) @app.route('/u//') def contributions(username): @@ -788,11 +788,11 @@ def contributions(username): user = User.get(User.username == username) except User.DoesNotExist: abort(404) - return render_template('contributions.html', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc())) + return render_template('contributions.jinja2', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc())) @app.route('/calendar/') def calendar_view(): - return render_template('calendar.html') + return render_template('calendar.jinja2') @app.route('/calendar//') def calendar_month(y, m): @@ -801,7 +801,7 @@ def calendar_month(y, m): (Page.calendar < datetime.date(y+1 if m==12 else y, 1 if m==12 else m+1, 1)) ).order_by(Page.calendar) - return render_template('month.html', d=datetime.date(y, m, 1), notes=notes) + return render_template('month.jinja2', d=datetime.date(y, m, 1), notes=notes) @app.route('/history/revision//') def view_old(revisionid): @@ -810,7 +810,7 @@ def view_old(revisionid): except PageRevision.DoesNotExist: abort(404) p = rev.page - return render_template('viewold.html', p=p, rev=rev) + return render_template('viewold.jinja2', p=p, rev=rev) @app.route('/backlinks//') def backlinks(id): @@ -818,7 +818,7 @@ def backlinks(id): p = Page[id] except Page.DoesNotExist: abort(404) - return render_template('backlinks.html', p=p, backlinks=Page.select().join(PageLink, on=PageLink.to_page).where(PageLink.from_page == p)) + return render_template('backlinks.jinja2', p=p, backlinks=Page.select().join(PageLink, on=PageLink.to_page).where(PageLink.from_page == p)) @app.route('/search/', methods=['GET', 'POST']) def search(): @@ -830,27 +830,27 @@ def search(): query |= Page.select().join(PageTag, on=PageTag.page ).where(PageTag.name ** ('%' + q + '%')) query = query.order_by(Page.touched.desc()) - return render_template('search.html', q=q, pl_include_tags=include_tags, + return render_template('search.jinja2', q=q, pl_include_tags=include_tags, results=query.paginate(1)) - return render_template('search.html', pl_include_tags=True) + return render_template('search.jinja2', pl_include_tags=True) @app.route('/tags//') @app.route('/tags///') def listtag(tag, page=1): general_query = Page.select().join(PageTag, on=PageTag.page).where(PageTag.name == tag).order_by(Page.touched.desc()) page_query = general_query.paginate(page) - return render_template('listtag.html', tagname=tag, tagged_notes=page_query, + return render_template('listtag.jinja2', tagname=tag, tagged_notes=page_query, page_n=page, total_count=general_query.count(), min=min) # symbolic route as of v0.5 @app.route('/upload/', methods=['GET']) def upload(): - return render_template('upload.html') + return render_template('upload.jinja2') @app.route('/stats/') def stats(): - return render_template('stats.html', + return render_template('stats.jinja2', notes_count=Page.select().count(), notes_with_url=Page.select().where(Page.url != None).count(), revision_count=PageRevision.select().count(), @@ -876,7 +876,7 @@ def accounts_login(): user = User.get(User.username == username) if not check_password_hash(user.password, request.form['password']): flash('Invalid username or password.') - return render_template('login.html') + return render_template('login.jinja2') except User.DoesNotExist: flash('Invalid username or password.') else: @@ -887,7 +887,7 @@ def accounts_login(): else: login_user(user) return redirect(request.args.get('next', '/')) - return render_template('login.html') + return render_template('login.jinja2') @app.route('/accounts/register/', methods=['GET','POST']) def accounts_register(): @@ -896,10 +896,10 @@ def accounts_register(): password = request.form['password'] if not is_username(username): flash('Invalid username: usernames can contain only letters, numbers, underscores and hyphens.') - return render_template('register.html') + return render_template('register.jinja2') if request.form['password'] != request.form['confirm_password']: flash('Passwords do not match.') - return render_template('register.html') + return render_template('register.jinja2') if not request.form['legal']: flash('You must accept Terms in order to register.') try: @@ -915,7 +915,7 @@ def accounts_register(): return redirect(request.args.get('next', '/')) except IntegrityError: flash('Username taken') - return render_template('register.html') + return render_template('register.jinja2') @app.route('/accounts/logout/') def accounts_logout(): @@ -963,10 +963,10 @@ def easter_y(y=None): if y: if y > 2499: flash('Years above 2500 A.D. are currently not supported.') - return render_template('easter.html') - return render_template('easter.html', y=y, easter_dates=stash_easter(y)) + return render_template('easter.jinja2') + return render_template('easter.jinja2', y=y, easter_dates=stash_easter(y)) else: - return render_template('easter.html') + return render_template('easter.jinja2') ## import / export ## @@ -1075,7 +1075,7 @@ def exportpages(): q_list.append(Page.select().where(Page.title == item)) if not q_list: flash('Failed to export pages: The list is empty!') - return render_template('exportpages.html') + return render_template('exportpages.jinja2') query = q_list.pop(0) while q_list: query |= q_list.pop(0) @@ -1083,7 +1083,7 @@ def exportpages(): e.add_page_list(query, include_history='history' in request.form) return e.export(), {'Content-Type': 'application/json', 'Content-Disposition': 'attachment; ' + 'filename=export-{}.json'.format(datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))} - return render_template('exportpages.html') + return render_template('exportpages.jinja2') @app.route('/manage/import/', methods=['GET', 'POST']) @login_required @@ -1098,7 +1098,7 @@ def importpages(): flash('Imported successfully {} pages and {} revisions'.format(*res)) else: flash('Pages can be imported by Administrators only!') - return render_template('importpages.html') + return render_template('importpages.jinja2') #### EXTENSIONS #### diff --git a/templates/backlinks.html b/templates/backlinks.jinja2 similarity index 100% rename from templates/backlinks.html rename to templates/backlinks.jinja2 diff --git a/templates/badrequest.html b/templates/badrequest.jinja2 similarity index 100% rename from templates/badrequest.html rename to templates/badrequest.jinja2 diff --git a/templates/base.html b/templates/base.jinja2 similarity index 100% rename from templates/base.html rename to templates/base.jinja2 diff --git a/templates/calendar.html b/templates/calendar.jinja2 similarity index 100% rename from templates/calendar.html rename to templates/calendar.jinja2 diff --git a/templates/circles/add.html b/templates/circles/add.jinja2 similarity index 100% rename from templates/circles/add.html rename to templates/circles/add.jinja2 diff --git a/templates/circles/csv.html b/templates/circles/csv.jinja2 similarity index 100% rename from templates/circles/csv.html rename to templates/circles/csv.jinja2 diff --git a/templates/circles/list.html b/templates/circles/list.jinja2 similarity index 100% rename from templates/circles/list.html rename to templates/circles/list.jinja2 diff --git a/templates/circles/stats.html b/templates/circles/stats.jinja2 similarity index 100% rename from templates/circles/stats.html rename to templates/circles/stats.jinja2 diff --git a/templates/contactnova/list.html b/templates/contactnova/list.jinja2 similarity index 100% rename from templates/contactnova/list.html rename to templates/contactnova/list.jinja2 diff --git a/templates/contactnova/new.html b/templates/contactnova/new.jinja2 similarity index 100% rename from templates/contactnova/new.html rename to templates/contactnova/new.jinja2 diff --git a/templates/contactnova/single.html b/templates/contactnova/single.jinja2 similarity index 100% rename from templates/contactnova/single.html rename to templates/contactnova/single.jinja2 diff --git a/templates/contributions.html b/templates/contributions.jinja2 similarity index 100% rename from templates/contributions.html rename to templates/contributions.jinja2 diff --git a/templates/easter.html b/templates/easter.jinja2 similarity index 100% rename from templates/easter.html rename to templates/easter.jinja2 diff --git a/templates/edit.html b/templates/edit.jinja2 similarity index 100% rename from templates/edit.html rename to templates/edit.jinja2 diff --git a/templates/exportpages.html b/templates/exportpages.jinja2 similarity index 100% rename from templates/exportpages.html rename to templates/exportpages.jinja2 diff --git a/templates/forbidden.html b/templates/forbidden.jinja2 similarity index 100% rename from templates/forbidden.html rename to templates/forbidden.jinja2 diff --git a/templates/history.html b/templates/history.jinja2 similarity index 100% rename from templates/history.html rename to templates/history.jinja2 diff --git a/templates/home.html b/templates/home.jinja2 similarity index 100% rename from templates/home.html rename to templates/home.jinja2 diff --git a/templates/importpages.html b/templates/importpages.jinja2 similarity index 100% rename from templates/importpages.html rename to templates/importpages.jinja2 diff --git a/templates/includes/nl_item.html b/templates/includes/nl_item.jinja2 similarity index 100% rename from templates/includes/nl_item.html rename to templates/includes/nl_item.jinja2 diff --git a/templates/internalservererror.html b/templates/internalservererror.jinja2 similarity index 100% rename from templates/internalservererror.html rename to templates/internalservererror.jinja2 diff --git a/templates/leaderboard.html b/templates/leaderboard.jinja2 similarity index 100% rename from templates/leaderboard.html rename to templates/leaderboard.jinja2 diff --git a/templates/listrecent.html b/templates/listrecent.jinja2 similarity index 100% rename from templates/listrecent.html rename to templates/listrecent.jinja2 diff --git a/templates/listtag.html b/templates/listtag.jinja2 similarity index 100% rename from templates/listtag.html rename to templates/listtag.jinja2 diff --git a/templates/login.html b/templates/login.jinja2 similarity index 100% rename from templates/login.html rename to templates/login.jinja2 diff --git a/templates/month.html b/templates/month.jinja2 similarity index 100% rename from templates/month.html rename to templates/month.jinja2 diff --git a/templates/notfound.html b/templates/notfound.jinja2 similarity index 100% rename from templates/notfound.html rename to templates/notfound.jinja2 diff --git a/templates/register.html b/templates/register.jinja2 similarity index 100% rename from templates/register.html rename to templates/register.jinja2 diff --git a/templates/search.html b/templates/search.jinja2 similarity index 100% rename from templates/search.html rename to templates/search.jinja2 diff --git a/templates/stats.html b/templates/stats.jinja2 similarity index 100% rename from templates/stats.html rename to templates/stats.jinja2 diff --git a/templates/upload.html b/templates/upload.jinja2 similarity index 100% rename from templates/upload.html rename to templates/upload.jinja2 diff --git a/templates/uploadinfo.html b/templates/uploadinfo.jinja2 similarity index 100% rename from templates/uploadinfo.html rename to templates/uploadinfo.jinja2 diff --git a/templates/view.html b/templates/view.jinja2 similarity index 100% rename from templates/view.html rename to templates/view.jinja2 diff --git a/templates/viewold.html b/templates/viewold.jinja2 similarity index 100% rename from templates/viewold.html rename to templates/viewold.jinja2