-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup some kind of static website #35
Comments
Pour ce que ça vaut, voila ce que j'ai sur mon propre site pour faire le rendu des fichiers markdown, exemple: https://docs.drlazor.be/python_ide.md
#!/usr/bin/env python3
"""HTTPD over UDS that render markdown files to HTML"""
from os import unlink, chmod
from http.server import SimpleHTTPRequestHandler
from signal import signal, SIGTERM, SIGINT
from socketserver import UnixStreamServer
from markdown import markdownFromFile
from threading import Thread
server_addr = "/var/run/markdown_renderer.sock"
base_dir = "/home/julien/Public"
html_pre = b"""<!DOCTYPE html5>
<head>
<meta charset=utf-8>
<style>
body { font-family: sans-serif; }
pre { background-color: #f5f5f5; }
</style>
</head>
<body>
<header>
<p>[<a href="/">index</a>]</p>
</header>
"""
html_post = b"""
</body>
</html>"""
class UnixStreamServer(UnixStreamServer):
def __enter__(self, *args):
return self
def __exit__(self, *args):
self.server_close()
class Handler(SimpleHTTPRequestHandler):
def address_string(self):
# UDS don't have addresses
return ""
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=UTF-8")
self.end_headers()
self.wfile.write(html_pre)
markdownFromFile(input="{}{}".format(base_dir, self.path),
output=self.wfile,
output_format="html5",
encoding="utf-8")
self.wfile.write(html_post)
if __name__ == "__main__":
with UnixStreamServer(server_addr, Handler) as httpd:
chmod(server_addr, 0o733)
signal(SIGTERM, lambda *_: Thread(target=httpd.shutdown).start())
print("Listening for connections on", server_addr)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
print("Exiting...")
unlink(server_addr) |
Merci pour l'issue, dès la création du dépôt notions, on y avait pensé. |
Il serait intéressant de setup un site statique permettant d'afficher les .md d'une manière un peu plus sexy ;D
Ou même de le réaliser à la main pour les plus téméraires ?
The text was updated successfully, but these errors were encountered: