projects
/
wiki
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
38c78c0
)
Move markdown rendering into its own function
author
David Kerkeslager
<kerkeslager@gmail.com>
Sat, 25 Jun 2022 20:25:24 +0000
(16:25 -0400)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Sat, 25 Jun 2022 20:25:24 +0000
(16:25 -0400)
app.py
patch
|
blob
|
history
diff --git
a/app.py
b/app.py
index
8e1464a
..
285c134
100644
(file)
--- a/
app.py
+++ b/
app.py
@@
-9,9
+9,18
@@
with open(pathlib.Path(__file__).parent / 'config.json') as f:
app = flask.Flask(__name__)
app = flask.Flask(__name__)
+def render_markdown_file(name, title):
+ try:
+ with open(pathlib.Path(CONFIGURATION['directory']) / '{}.md'.format(name), 'r') as f:
+ content = commonmark.commonmark(f.read())
+ except FileNotFoundError as e:
+ flask.abort(404)
+
+ return flask.render_template('page.html', content=content, title=title)
+
@app.route('/')
def index():
@app.route('/')
def index():
- return
'Hello, world'
+ return
render_markdown_file('_index', 'Home')
@app.route('/p/<name>')
def page(name):
@app.route('/p/<name>')
def page(name):
@@
-19,14
+28,5
@@
def page(name):
if not ch in 'abcdefghijklmnopqrstuvwxyz-0123456789':
flask.abort(404)
if not ch in 'abcdefghijklmnopqrstuvwxyz-0123456789':
flask.abort(404)
- try:
- with open(pathlib.Path(CONFIGURATION['directory']) / '{}.md'.format(name), 'r') as f:
- content = commonmark.commonmark(f.read())
- except FileNotFoundError as e:
- flask.abort(404)
-
- title = name.replace('-', ' ').title()
-
- return flask.render_template('page.html', content=content, title=title)
-
+ return render_markdown_file(name, name.replace('-', ' ').title())