#! .venv/bin/python3
-from flask import Flask, Response, request
+from flask import Flask, Response, request, render_template, redirect
import markdown
from os import listdir
from markdown.extensions.toc import TocExtension
abstract: str = "...",
keywords: list = ["Undefined"],
date: str = "n.d.",
- content: str = ""
+ content: str = "",
+ template: str = "page.html"
):
self.title = title
self.content = content
def from_metadata(self, metadata):
- if "title" in metadata: self.title = metadata["title"]
+ if "title" in metadata: self.title = metadata["title"].title()
if "abstract" in metadata: self.abstract = metadata["abstract"]
if "keywords" in metadata: self.keywords = [x.strip().title() for x in metadata["keywords"].split(",")]
if "date" in metadata: self.date = metadata["date"]
def make(self):
format_keywords = " - ".join([f"<a href='/categories?name={key.lower()}'>{key}</a>" for key in self.keywords])
- page = f"""
-<!DOCTYPE html>
-<html>
- <head>
- <title>{self.title}</title>
- <link rel="stylesheet" href="style.css">
- <script src="script.js"></script>
- </head>
- <body>
- <h1 class='mainTitle'>{self.title}</h1>
- <h2>{self.date}</h2>
- <p>Abstract: <em>{self.abstract}</em></p>
- <p>Keywords: <em>{format_keywords}</em></p>
- <hr>
- <div>
- {self.content}
- </div>
- <p>
- © William Greenwood 2024
- </p>
- </body>
-</html>
- """
+ page = render_template(
+ "page.html",
+ title = self.title,
+ date = self.date,
+ abstract = self.abstract,
+ keywords = format_keywords,
+ content = self.content
+ )
return Response(page, mimetype="text/html")
@app.route("/")
def homepage():
- return "Hello, World!"
-
-@app.route("/<string:title>.<string:extension>")
-def get_static(title, extension):
- title = title.replace("/", "")
-
- match extension:
- case "css": path, mime = "/", "text/css"
- case "js": path, mime = "/", "text/javascript"
- case "png": path, mime = "/media/", "image/png"
- case _: path = mime = ""
-
- try:
- with open(f"{path}/{title}.{extension}", "r") as f:
- return Response(f.read, minetype=mime)
-
- except FileNotFoundError:
- return ""
+ page = Page(
+ title = "Home",
+ abstract = "",
+ content = "",
+ template = "home.html"
+ )
+ return page.make()
@app.route("/categories")
def get_categories():
name = request.args.get('name')
index = {}
+ if name == "all":
+ return redirect("/categories")
+
for file_name in listdir("./pages"):
keywords = ["Undefined"]
title = "Untitled post"
title = value.strip().title()
case "abstract":
abstract = value.strip()
- case "categories":
+ case "keywords":
keywords = [x.strip() for x in value.split(",")]
else:
break
page = Page(
title = "Keywords",
- keywords = [c.title() for c in index],
+ keywords = [c.title() for c in index] + ["All"],
content = content
)
return page.make()
--- /dev/null
+/**
+* Literata ExtraLight
+* Literata ExtraLightItalic
+* Literata Light
+* Literata LightItalic
+* Literata Regular
+* Literata Italic
+* Literata Medium
+* Literata MediumItalic
+* Literata SemiBold
+* Literata SemiBoldItalic
+* Literata Bold
+* Literata BoldItalic
+* Literata ExtraBold
+* Literata ExtraBoldItalic
+* Literata Black
+* Literata BlackItalic
+* Literata Variable (Variable font)
+* Literata VariableItalic (Variable font)
+*/
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-ExtraLight.woff2') format('woff2'),
+ url('/static/fonts/Literata-ExtraLight.woff') format('woff'),
+ url('/static/fonts/Literata-ExtraLight.ttf') format('truetype');
+ font-weight: 200;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-ExtraLightItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-ExtraLightItalic.woff') format('woff'),
+ url('/static/fonts/Literata-ExtraLightItalic.ttf') format('truetype');
+ font-weight: 200;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Light.woff2') format('woff2'),
+ url('/static/fonts/Literata-Light.woff') format('woff'),
+ url('/static/fonts/Literata-Light.ttf') format('truetype');
+ font-weight: 300;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-LightItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-LightItalic.woff') format('woff'),
+ url('/static/fonts/Literata-LightItalic.ttf') format('truetype');
+ font-weight: 300;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Regular.woff2') format('woff2'),
+ url('/static/fonts/Literata-Regular.woff') format('woff'),
+ url('/static/fonts/Literata-Regular.ttf') format('truetype');
+ font-weight: 400;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Italic.woff2') format('woff2'),
+ url('/static/fonts/Literata-Italic.woff') format('woff'),
+ url('/static/fonts/Literata-Italic.ttf') format('truetype');
+ font-weight: 400;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Medium.woff2') format('woff2'),
+ url('/static/fonts/Literata-Medium.woff') format('woff'),
+ url('/static/fonts/Literata-Medium.ttf') format('truetype');
+ font-weight: 550;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-MediumItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-MediumItalic.woff') format('woff'),
+ url('/static/fonts/Literata-MediumItalic.ttf') format('truetype');
+ font-weight: 550;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-SemiBold.woff2') format('woff2'),
+ url('/static/fonts/Literata-SemiBold.woff') format('woff'),
+ url('/static/fonts/Literata-SemiBold.ttf') format('truetype');
+ font-weight: 700;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-SemiBoldItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-SemiBoldItalic.woff') format('woff'),
+ url('/static/fonts/Literata-SemiBoldItalic.ttf') format('truetype');
+ font-weight: 700;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Bold.woff2') format('woff2'),
+ url('/static/fonts/Literata-Bold.woff') format('woff'),
+ url('/static/fonts/Literata-Bold.ttf') format('truetype');
+ font-weight: 800;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-BoldItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-BoldItalic.woff') format('woff'),
+ url('/static/fonts/Literata-BoldItalic.ttf') format('truetype');
+ font-weight: 800;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-ExtraBold.woff2') format('woff2'),
+ url('/static/fonts/Literata-ExtraBold.woff') format('woff'),
+ url('/static/fonts/Literata-ExtraBold.ttf') format('truetype');
+ font-weight: 850;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-ExtraBoldItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-ExtraBoldItalic.woff') format('woff'),
+ url('/static/fonts/Literata-ExtraBoldItalic.ttf') format('truetype');
+ font-weight: 850;
+ font-display: swap;
+ font-style: italic;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-Black.woff2') format('woff2'),
+ url('/static/fonts/Literata-Black.woff') format('woff'),
+ url('/static/fonts/Literata-Black.ttf') format('truetype');
+ font-weight: 900;
+ font-display: swap;
+ font-style: normal;
+}
+@font-face {
+ font-family: 'Literata';
+ src: url('/static/fonts/Literata-BlackItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-BlackItalic.woff') format('woff'),
+ url('/static/fonts/Literata-BlackItalic.ttf') format('truetype');
+ font-weight: 900;
+ font-display: swap;
+ font-style: italic;
+}
+/**
+* This is a variable font
+* You can control variable axes as shown below:
+* font-variation-settings: wght 900.0opsz 7.0;
+*
+* available axes:
+'wght' (range from 200.0 to 900.0'opsz' (range from 7.0 to 72.0
+*/
+@font-face {
+ font-family: 'Literata-Variable';
+ src: url('/static/fonts/Literata-Variable.woff2') format('woff2'),
+ url('/static/fonts/Literata-Variable.woff') format('woff'),
+ url('/static/fonts/Literata-Variable.ttf') format('truetype');
+ font-weight: 200 900;
+ font-display: swap;
+ font-style: normal;
+}
+/**
+* This is a variable font
+* You can control variable axes as shown below:
+* font-variation-settings: wght 900.0opsz 7.0;
+*
+* available axes:
+'wght' (range from 200.0 to 900.0'opsz' (range from 7.0 to 72.0
+*/
+@font-face {
+ font-family: 'Literata-VariableItalic';
+ src: url('/static/fonts/Literata-VariableItalic.woff2') format('woff2'),
+ url('/static/fonts/Literata-VariableItalic.woff') format('woff'),
+ url('/static/fonts/Literata-VariableItalic.ttf') format('truetype');
+ font-weight: 200 900;
+ font-display: swap;
+ font-style: italic;
+}
+