From: David Kerkeslager Date: Fri, 6 May 2022 00:48:30 +0000 (-0400) Subject: Basic structure of git-based wiki X-Git-Url: https://code.kerkeslager.com/?p=wiki;a=commitdiff_plain;h=e3be880866bd47b8b47b895cd1ec29fde1ef829f Basic structure of git-based wiki --- 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 }} +
+
+ + + +