markdown support
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 5m35s
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 5m35s
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
# Imports
|
||||
from flask import Blueprint, render_template, abort
|
||||
from os import getenv as env
|
||||
import logging, os, re, markdown
|
||||
import logging, os, markdown
|
||||
|
||||
# Create blueprint
|
||||
bp = Blueprint(
|
||||
'dynamic_routes',
|
||||
__name__,
|
||||
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
|
||||
template_folder=env('TEMPLATE_FOLDER', default='templates'),
|
||||
static_folder=env('STATIC_FOLDER', default='../static')
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
# Get all files in folder
|
||||
def ListFiles(path):
|
||||
path = os.path.join(bp.template_folder, 'pages', path)[3:]
|
||||
path = os.path.join(bp.template_folder, 'pages', path)
|
||||
files = []
|
||||
for root, dirs, files_in_dir in os.walk(path):
|
||||
for file in files_in_dir:
|
||||
@@ -28,27 +28,26 @@ def ListFiles(path):
|
||||
# Catch-all route for generic pages
|
||||
@bp.route('/<path:filename>')
|
||||
def catch_all(filename):
|
||||
if os.path.exists(os.path.join(bp.template_folder, 'pages', filename)[3:]):
|
||||
return render_template(f'pages/{filename}')
|
||||
|
||||
elif os.path.exists(os.path.join(bp.template_folder, 'pages', filename + '.html')[3:]):
|
||||
return render_template(f'pages/{filename}.html')
|
||||
|
||||
elif os.path.exists(os.path.join(bp.template_folder, 'pages', filename + '.md')[3:]):
|
||||
print("yay")
|
||||
print(markdown.markdownFromFile("../templates/pages/test.md"))
|
||||
return render_template(
|
||||
f'bases/md.html',
|
||||
title = filename.split("/")[-1],
|
||||
markdown = markdown.markdownFromFile(os.path.join(bp.template_folder, 'pages', filename + '.md'))
|
||||
)
|
||||
|
||||
elif os.path.isdir(os.path.join(bp.template_folder, 'pages', filename)[3:]):
|
||||
if os.path.exists(os.path.join(bp.template_folder, 'pages', filename)):
|
||||
if os.path.isdir(os.path.join(bp.template_folder, 'pages', filename)):
|
||||
return render_template(
|
||||
'bases/directory.html',
|
||||
directory=filename + "/" if not filename.endswith('/') else filename,
|
||||
pages=ListFiles(filename)
|
||||
)
|
||||
|
||||
return render_template(f'pages/{filename}')
|
||||
|
||||
elif os.path.exists(os.path.join(bp.template_folder, 'pages', filename + '.html')):
|
||||
return render_template(f'pages/{filename}.html')
|
||||
|
||||
elif os.path.exists(os.path.join(bp.template_folder, 'pages', filename + '.md')):
|
||||
output = markdown.markdown(open(os.path.join(bp.template_folder, 'pages', filename + '.md'), "r").read())
|
||||
return render_template(
|
||||
f'bases/md.html',
|
||||
title = filename.split("/")[-1],
|
||||
markdown = output
|
||||
)
|
||||
|
||||
else:
|
||||
abort(404, f"'{filename}' not found")
|
||||
@@ -34,9 +34,9 @@ def bad_request(error:HTTPException=None):
|
||||
return render_template('errors/400.html', error=error), 400
|
||||
|
||||
# Route for all other errors
|
||||
@bp.route('/error')
|
||||
@bp.route('/idk')
|
||||
@bp.app_errorhandler(Exception)
|
||||
def unauthorized(error:HTTPException=None):
|
||||
def nah(error:HTTPException=None):
|
||||
if isinstance(error, HTTPException):
|
||||
return render_template(
|
||||
'errors/error.html',
|
||||
@@ -47,6 +47,6 @@ def unauthorized(error:HTTPException=None):
|
||||
return render_template(
|
||||
'errors/error.html',
|
||||
code=418,
|
||||
description="meow :3",
|
||||
description="I honestly dont know",
|
||||
name="I'm a teapot"
|
||||
), 418
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
{% block content %}
|
||||
<section>
|
||||
{{ markdown }}
|
||||
{{ markdown|safe }}
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -1,2 +1,4 @@
|
||||
# hello
|
||||
this is a test
|
||||
## this is a test
|
||||
|
||||
this is actually a md file, try putting .md at the end of this path
|
||||
Reference in New Issue
Block a user