mirror of https://github.com/dirtbags/moth.git
devel-server: start to serve puzzles
This commit is contained in:
parent
dd606fc206
commit
e881ac6c89
|
@ -6,4 +6,4 @@
|
||||||
build/
|
build/
|
||||||
cache/
|
cache/
|
||||||
target/
|
target/
|
||||||
packages/forensics
|
puzzles
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import glob
|
||||||
import http.server
|
import http.server
|
||||||
import mistune
|
import mistune
|
||||||
import pathlib
|
import pathlib
|
||||||
|
@ -22,7 +23,12 @@ def page(title, body):
|
||||||
</html>""".format(title, body)
|
</html>""".format(title, body)
|
||||||
|
|
||||||
def mdpage(body):
|
def mdpage(body):
|
||||||
|
try:
|
||||||
title, _ = body.split('\n', 1)
|
title, _ = body.split('\n', 1)
|
||||||
|
except ValueError:
|
||||||
|
title = "Result"
|
||||||
|
title = title.lstrip("#")
|
||||||
|
title = title.strip()
|
||||||
return page(title, mistune.markdown(body))
|
return page(title, mistune.markdown(body))
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +39,9 @@ class MothHandler(http.server.CGIHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
if self.path == "/":
|
if self.path == "/":
|
||||||
self.serve_front()
|
self.serve_front()
|
||||||
elif self.path.startswith("/files/"):
|
elif self.path.startswith("/puzzles"):
|
||||||
|
self.serve_puzzles()
|
||||||
|
elif self.path.startswith("/files"):
|
||||||
self.serve_file()
|
self.serve_file()
|
||||||
else:
|
else:
|
||||||
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
||||||
|
@ -61,6 +69,18 @@ you are a fool.
|
||||||
"""
|
"""
|
||||||
self.serve_md(page)
|
self.serve_md(page)
|
||||||
|
|
||||||
|
def serve_puzzles(self):
|
||||||
|
body = []
|
||||||
|
parts = self.path.split("/")
|
||||||
|
if len(parts) < 3:
|
||||||
|
body.append("# Puzzle Categories")
|
||||||
|
# List all categories
|
||||||
|
for i in glob.glob("puzzles/*/"):
|
||||||
|
body.append("* [{}](/{})".format(i, i))
|
||||||
|
else:
|
||||||
|
body.append("# Not Implemented Yet")
|
||||||
|
self.serve_md('\n'.join(body))
|
||||||
|
|
||||||
def serve_file(self):
|
def serve_file(self):
|
||||||
if self.path.endswith(".md"):
|
if self.path.endswith(".md"):
|
||||||
self.serve_md()
|
self.serve_md()
|
||||||
|
|
|
@ -26,7 +26,7 @@ In the directory containing `devel-server.py`, you would run something like:
|
||||||
|
|
||||||
git clone /path/to/my/puzzles-repository puzzles
|
git clone /path/to/my/puzzles-repository puzzles
|
||||||
|
|
||||||
or
|
or on Unix:
|
||||||
|
|
||||||
ln -s /path/to/my/puzzles-repository puzzles
|
ln -s /path/to/my/puzzles-repository puzzles
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ body {
|
||||||
|
|
||||||
pre, tt {
|
pre, tt {
|
||||||
font-family: 'Dosis', monospace;
|
font-family: 'Dosis', monospace;
|
||||||
|
background-color: rgba(0, 0, 0, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal {
|
.terminal {
|
||||||
|
|
Loading…
Reference in New Issue