summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapp.py15
-rwxr-xr-xdatabase.py34
-rwxr-xr-xparser.py18
-rw-r--r--templates/about.html.j24
-rw-r--r--templates/index.html.j22
-rw-r--r--templates/template.html.j210
-rw-r--r--templates/thought.html.j215
-rw-r--r--templates/thoughts.html.j212
8 files changed, 81 insertions, 29 deletions
diff --git a/app.py b/app.py
index 33082fc..7122b06 100755
--- a/app.py
+++ b/app.py
@@ -33,7 +33,7 @@ def get_template_items(title, db):
@app.route("/~")
def index():
with database.Database() as db:
- with open(os.path.join("static", "index.md"), "r") as f:
+ with open("static/index.md", "r") as f:
return flask.render_template(
"index.html.j2",
**get_template_items("eva's site", db),
@@ -48,9 +48,17 @@ def robots():
def get_thoughts():
with database.Database() as db:
all_ = db.get_all_thoughts()
+ tree = {}
+ for id_, title, datetime, category in all_:
+ if category not in tree.keys():
+ tree[category] = [(id_, title, datetime)]
+ else:
+ tree[category].append((id_, title, str(datetime)))
+
return flask.render_template(
"thoughts.html.j2",
**get_template_items("thoughts", db),
+ tree = tree
)
@app.route("/thought")
@@ -58,7 +66,7 @@ def get_thought():
thought_id = flask.request.args.get("id", type=int)
with database.Database() as db:
try:
- title, datetime, parsed, headers, redirect = parser.get_thought_from_id(db. thought_id)
+ title, datetime, redirect, category_name, parsed, headers= parser.get_thought_from_id(db, thought_id)
except TypeError:
flask.abort(404)
return
@@ -71,7 +79,8 @@ def get_thought():
**get_template_items(title, db),
md_html = parsed,
contents_html = headers,
- datetime = "published: " + str(datetime)
+ datetime = "published: " + str(datetime),
+ category = category_name
)
if __name__ == "__main__":
diff --git a/database.py b/database.py
index aebd72e..a910a07 100755
--- a/database.py
+++ b/database.py
@@ -34,21 +34,41 @@ class Database:
cursor.execute("SELECT alt, url FROM images WHERE sidebar_img = 1;")
return cursor.fetchall()
+ def get_all_categories(self):
+ cursor = self.__connection.cursor()
+ cursor.execute("SELECT name FROM categories;")
+ return [i[0] for i in cursor.fetchall()]
+
+ def add_category(self, category):
+ if not category in self.get_all_categories():
+ cursor = self.__connection.cursor()
+ cursor.execute("INSERT INTO categories (name) VALUES (?);", (category, ))
+
+ return True
+ return False
+
def get_all_thoughts(self):
cursor = self.__connection.cursor()
- cursor.execute("SELECT id, title, datetime FROM thoughts")
+ cursor.execute("""
+ SELECT thoughts.id, title, datetime, categories.name
+ FROM thoughts INNER JOIN categories
+ ON thoughts.category_id = categories.id""")
return cursor.fetchall()
def get_thought(self, id_):
cursor = self.__connection.cursor()
cursor.execute("""
- SELECT title, datetime, markdown_text FROM thoughts
- WHERE id = ?;""", (id_, ))
- return cursor.fetchall()
+ SELECT title, datetime, markdown_text, redirect, name
+ FROM thoughts INNER JOIN categories
+ ON thoughts.category_id = categories.id
+ WHERE thoughts.id = ?;""", (id_, ))
+ return cursor.fetchone()
- def add_thought(self, title, markdown):
+ def add_thought(self, title, markdown, category):
cursor = self.__connection.cursor()
cursor.execute("""
- INSERT INTO thoughts (title, datetime, markdown_text)
- VALUES (?, datetime('now'), ?);""", (title, markdown))
+ INSERT INTO thoughts (category_id, title, markdown_text, datetime)
+ VALUES ((
+ SELECT id FROM categories WHERE name = ?
+ ), ?, ?, datetime('now'));""", (category, title, markdown))
diff --git a/parser.py b/parser.py
index 41ff65b..db363f3 100755
--- a/parser.py
+++ b/parser.py
@@ -45,9 +45,9 @@ class MyRenderer(mistune.HTMLRenderer):
)
def get_thought_from_id(db, id_):
- title, datetime, markdown, redirect = db.get_thought(id_)
+ title, datetime, markdown, redirect, category_name = db.get_thought(id_)
html, headers = parse_text(markdown)
- return title, datetime, html, headers, redirect
+ return title, datetime, redirect, category_name, html, headers
def parse_file(path):
with open(path, "r") as f:
@@ -114,6 +114,12 @@ def main():
type = str,
required = True
)
+ s.add_argument(
+ "-c", "--category",
+ help = "Article category",
+ type = str,
+ required = True
+ )
for s in [export_parser, update_parser]:
s.add_argument(
@@ -142,8 +148,10 @@ def main():
with database.Database() as db:
match verb:
case "save":
+ if db.add_category(args["category"]):
+ print("Added category.")
with open(args["markdown"], "r") as f:
- db.add_thought(args["title"], f.read())
+ db.add_thought(args["title"], f.read(), args["category"])
print("Added thought.")
case "export":
with open(args["out"], "w") as f:
@@ -154,8 +162,8 @@ def main():
db.update_thought_markdown(args["id"], f.read())
print("Updated thought.")
case "list":
- for id_, title, datetime in db.get_all_thoughts():
- print(f"{id_}, {title}, {datetime}")
+ for id_, title, datetime, category in db.get_all_thoughts():
+ print(f"{id_}, {title}, {datetime}, {category}")
case _:
print("Error! Unknown verb... Exiting...")
exit()
diff --git a/templates/about.html.j2 b/templates/about.html.j2
deleted file mode 100644
index 8ebc3d7..0000000
--- a/templates/about.html.j2
+++ /dev/null
@@ -1,4 +0,0 @@
-{% extends "template.html.j2" %}
-{% block content %}
- {{ content|safe }}
-{% endblock %} \ No newline at end of file
diff --git a/templates/index.html.j2 b/templates/index.html.j2
index fa4873e..bc21bcf 100644
--- a/templates/index.html.j2
+++ b/templates/index.html.j2
@@ -1,4 +1,4 @@
{% extends "template.html.j2" %}
{% block content %}
- {{ content|safe }}
+ {{markdown|safe}}
{% endblock %}
diff --git a/templates/template.html.j2 b/templates/template.html.j2
index 711cbc7..183ef55 100644
--- a/templates/template.html.j2
+++ b/templates/template.html.j2
@@ -1,9 +1,9 @@
<!doctype html>
<html lang="en">
<head>
- <link rel='stylesheet' href="{{ prefix }}styles/style.css">
- <link rel="icon" type="image/png" href="{{ prefix }}images/favicon-32x32.png" sizes="32x32" />
- <link rel="icon" type="image/png" href="{{ prefix }}images/favicon-16x16.png" sizes="16x16" />
+ <link rel='stylesheet' href="static/styles/style.css">
+ <link rel="icon" type="image/png" href="static/images/favicon-32x32.png" sizes="32x32" />
+ <link rel="icon" type="image/png" href="static/images/favicon-16x16.png" sizes="16x16" />
<title>cafebabe.gay :: {{ title }}</title>
<meta content="{{ title }}" property="og:title" />
@@ -37,12 +37,12 @@
<p>
<a href="https://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px"
- src="{{ prefix }}images/vcss-blue.gif"
+ src="static/images/vcss-blue.gif"
alt="Valid CSS!" />
</a>
</p>
<a href="https://www.debian.org/">
- <img src="{{ prefix }}images/powerdebian.gif" alt="Powered By Debian">
+ <img src="static/images/powerdebian.gif" alt="Powered By Debian">
</a>
</div>
</footer>
diff --git a/templates/thought.html.j2 b/templates/thought.html.j2
index fa4873e..a6953e2 100644
--- a/templates/thought.html.j2
+++ b/templates/thought.html.j2
@@ -1,4 +1,17 @@
{% extends "template.html.j2" %}
{% block content %}
- {{ content|safe }}
+ <aside>
+ <h4>{{datetime}}</h4>
+ {% if contents_html != "" %}
+ <h5>contents:</h5>
+ <div id="contents">
+ {{ contents_html|safe}}
+ </div>
+ {% endif %}
+ <h5>this category:<h5>
+ <ul>
+ <li><b><a href="{{'/thoughts#'+category.replace(' ', '_')}}">{{category}}</a></b></li>
+ </ul>
+ </aside>
+ {{md_html|safe}}
{% endblock %}
diff --git a/templates/thoughts.html.j2 b/templates/thoughts.html.j2
index 69734fa..fa950e7 100644
--- a/templates/thoughts.html.j2
+++ b/templates/thoughts.html.j2
@@ -1,6 +1,12 @@
{% extends "template.html.j2" %}
{% block content %}
- <div id="thoughts_list">
- {{ content|safe }}
- </div>
+ {% for category_name, thoughts in tree.items() %}
+ <h3 id="{{category_name.replace(' ', '_')}}">{{category_name}}</h3>
+ <dl>
+ {% for id_, title, datetime in thoughts %}
+ <dt><a href="{{'/thought?id=%i' % id_}}">{{title}}</a></dt>
+ <dd>{{datetime}}</dd>
+ {% endfor %}
+ </dl>
+ {% endfor %}
{% endblock %}