80 lines
2 KiB
Python
80 lines
2 KiB
Python
# AGPL 3 or any later version
|
|
# (C) J.Y.Amihud ( Blender Dumbass )
|
|
|
|
from modules import Set
|
|
|
|
def guess_type(path):
|
|
|
|
if "/json/" in path or ".json" in path:
|
|
return "application/json"
|
|
if "/css" in path or ".css" in path:
|
|
return "text/css"
|
|
if "/icon" in path or path.endswith(".png"):
|
|
return "image/png"
|
|
if path.endswith("jpg"):
|
|
return "image/jpg"
|
|
|
|
return "text/html"
|
|
|
|
def headers(server, code):
|
|
|
|
server.send_response(code)
|
|
server.send_header("Content-type", guess_type(server.path))
|
|
server.end_headers()
|
|
|
|
def head(title="", description="", image="", config={}):
|
|
|
|
if image.startswith("/"): image = config.get("url","")+image
|
|
|
|
html = """
|
|
<!DOCTYPE html>
|
|
|
|
<!-- The head. Part of the HTML code where metadata about the page is storred.
|
|
Including the metadata readable by social media websites, when generating link
|
|
previwews, which are called mata-tags in HTML. -->
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>"""+title+"""</title> <!-- Title in the browser tab -->
|
|
<link media="all" href="/css" type="text/css" rel="stylesheet" /> <!-- CSS theme link -->
|
|
<link rel="icon" href="/pictures/favicon.png"> <!-- Tiny image in the tab -->
|
|
|
|
<!-- Now meta tags for social media -->
|
|
|
|
<meta property="og:site_name" content=\""""+config.get("title", "My Website")+"""">
|
|
<meta property="og:title" content=\""""+title+"""">
|
|
<meta property="og:description" content=\""""+description+"""">
|
|
<meta property="og:image" content=\""""+image+"""">
|
|
|
|
</head>
|
|
<body>
|
|
|
|
"""
|
|
|
|
return html
|
|
|
|
def send(server, html, code):
|
|
|
|
# Add headers
|
|
headers(server, code)
|
|
server.wfile.write(html.encode("utf-8"))
|
|
|
|
|
|
def MainPage(server):
|
|
|
|
# Reading config
|
|
config = Set.Load()
|
|
|
|
# Generating <head>
|
|
html = head(title = config.get("title", "Website"),
|
|
description = config.get("description", "Description"),
|
|
config = config
|
|
)
|
|
|
|
|
|
html = html + "hello world"
|
|
|
|
send(server, html, 200)
|
|
|
|
|
|
|