From e3be880866bd47b8b47b895cd1ec29fde1ef829f Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Thu, 5 May 2022 20:48:30 -0400 Subject: [PATCH] Basic structure of git-based wiki --- .gitignore | 1 + main.py | 26 +++++++++++ pages/demo.md | 33 ++++++++++++++ templates/page.html | 107 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 main.py create mode 100644 pages/demo.md create mode 100644 templates/page.html diff --git a/.gitignore b/.gitignore index a2a8dea..896cdee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .env/ +__pycache__/ diff --git a/main.py b/main.py new file mode 100644 index 0000000..189009c --- /dev/null +++ b/main.py @@ -0,0 +1,26 @@ +import commonmark +import flask + +app = flask.Flask(__name__) + +@app.route('/') +def index(): + return 'Hello, world' + +@app.route('/p/') +def page(name): + for ch in name: + if not ch in 'abcdefghijklmnopqrstuvwxyz_': + flask.abort(404) + + try: + with open('pages/{}.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) + + diff --git a/pages/demo.md b/pages/demo.md new file mode 100644 index 0000000..3740b66 --- /dev/null +++ b/pages/demo.md @@ -0,0 +1,33 @@ +*italic* + +**bold** + +# Heading 1 + +## Heading 2 + +### Heading 3 + +#### Heading 4 + +##### Heading 5 + +[Link](https://www.google.com) + +![Image](http://url/a.png) + +> Blockquote + +Horizontal rule: + +--- + +`Inline code` with backticks + +``` +#include +int main(int arc, char** argv) { + printf("Hello, world"); +} +``` + diff --git a/templates/page.html b/templates/page.html new file mode 100644 index 0000000..c028b5b --- /dev/null +++ b/templates/page.html @@ -0,0 +1,107 @@ + + + + + + + + {{ title }} + + + + + +
+

Wiki

+
+ +
+

{{ title }}

+
+ {{ content | safe }} +
+
+ + + + -- 2.20.1