Basic structure of git-based wiki
authorDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 6 May 2022 00:48:30 +0000 (20:48 -0400)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 6 May 2022 00:48:30 +0000 (20:48 -0400)
.gitignore
main.py [new file with mode: 0644]
pages/demo.md [new file with mode: 0644]
templates/page.html [new file with mode: 0644]

index a2a8dea..896cdee 100644 (file)
@@ -1 +1,2 @@
 .env/
+__pycache__/
diff --git a/main.py b/main.py
new file mode 100644 (file)
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/<name>')
+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 (file)
index 0000000..3740b66
--- /dev/null
@@ -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 <stdlib.h>
+int main(int arc, char** argv) {
+  printf("Hello, world");
+}
+```
+
diff --git a/templates/page.html b/templates/page.html
new file mode 100644 (file)
index 0000000..c028b5b
--- /dev/null
@@ -0,0 +1,107 @@
+<!doctype html>
+
+<html lang='en'>
+  <head>
+    <meta charset='utf-8'>
+    <meta name='viewport' content='width=device-width, initial-scale=1'>
+
+    <title>{{ title }}</title>
+
+    <style>
+      html, body, h1, h2, h3, h4, h5, p {
+        margin: 0;
+        padding: 0;
+      }
+
+      html {
+        font-family: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
+        font-size: 18px;
+      }
+
+      h1, h2, h3, h4, h5 {
+        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+      }
+
+      body {
+        width: 100%;
+        margin: 0;
+        padding: 0;
+
+        display: flex;
+        flex-direction: column;
+        align-items: center;
+      }
+
+      body > header {
+        width: 100%;
+
+        display: flex;
+        flex-direction: row;
+        align-items: center;
+
+        border-bottom: 1px solid black;
+
+        margin-bottom: 1rem;
+      }
+
+      body > header > h1 {
+        margin: 1rem;
+      }
+
+      body > main {
+        max-width: 40rem;
+        width: calc(100% - 2rem);
+      }
+
+      body > main > section.content > blockquote,
+      body > main > section.content > hr,
+      body > main > section.content > p,
+      body > main > section.content > pre {
+        margin-bottom: 0.8rem;
+      }
+
+      body > main > section.content > :last-child {
+        margin-bottom: 0;
+      }
+
+      body > main > section.content code {
+        font-size: 14px;
+      }
+
+      body > footer {
+        margin-top: 1rem;
+        border-top: 1px solid black;
+
+        width: 100%;
+
+        display: flex;
+        flex-direction: row;
+        align-items: center;
+        justify-content: center;
+      }
+
+      body > footer section.copyright {
+        margin: 1rem;
+      }
+    </style>
+  </head>
+
+  <body>
+    <header>
+      <h1>Wiki</h1>
+    </header>
+
+    <main>
+      <h2>{{ title }}</h2>
+      <section class='content'>
+        {{ content | safe }}
+      </section>
+    </main>
+
+    <footer>
+      <section class='copyright'>
+        &copy; 2022 by David Kerkeslager
+      </section>
+    </footer>
+  </body>
+</html>