Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kmrasmussen committed May 18, 2024
0 parents commit 847372e
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import markdown2
import os
import time
from flask import Flask, render_template, send_from_directory
from os.path import exists, join

MD_DIR = '/home/ec2-user/docs'
FRONTPAGE_TITLE = 'kmrasmussen markdown docs'
assert exists(MD_DIR)
app = Flask(__name__)

@app.route('/styles.css')
def styles():
return send_from_directory('static', 'styles.css')

def get_md_files():
md_files = [f for f in os.listdir(MD_DIR) if f.endswith('.md')]
file_info = []
for file in md_files:
stat = os.stat(join(MD_DIR,file))
created = time.strftime("%B %d, %Y", time.localtime(stat.st_ctime))
modified = time.strftime("%B %d, %Y", time.localtime(stat.st_mtime))
file_info.append({
'name': file,
'created': created,
'modified': modified,
'url': f'/doc/{file}'
})
return file_info

@app.route('/')
def index():
files = get_md_files()
return render_template('index.html', files=files, frontpage_title=FRONTPAGE_TITLE)

@app.route('/doc/<filename>')
def doc(filename):
filename = join(MD_DIR, filename)
if not os.path.exists(filename):
return "File not found", 404
with open(filename, 'r') as f:
md_content = f.read()
html_content = markdown2.markdown(md_content, extras=["fenced-code-blocks", "code-friendly", "code-color"])
return render_template('doc.html', content=html_content)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=1234)
11 changes: 11 additions & 0 deletions nohup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* Serving Flask app 'app'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:1234
* Running on http://172.31.41.173:1234
Press CTRL+C to quit
80.198.54.247 - - [18/May/2024 18:26:10] "GET / HTTP/1.1" 200 -
80.198.54.247 - - [18/May/2024 18:26:10] "GET /styles.css HTTP/1.1" 304 -
80.198.54.247 - - [18/May/2024 18:26:13] "GET /doc/hierarchical_agents.md HTTP/1.1" 200 -
80.198.54.247 - - [18/May/2024 18:26:13] "GET /styles.css HTTP/1.1" 304 -
31 changes: 31 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* styles.css */
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.6;
}
h1, h2, h3, h4, h5, h6 {
line-height: 1.2;
}
ul {
padding-left: 20px;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
code {
font-size: 1.1em;
background-color: #f8f8f8;
padding: 2px 4px;
border-radius: 4px;
}
pre {
background-color: #f8f8f8;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
23 changes: 23 additions & 0 deletions templates/doc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/styles.css">
<script type="text/javascript" async>
MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
}
};
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js">
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body>
{{ content|safe }}
</body>
</html>
15 changes: 15 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<h1>{{ frontpage_title }}</h1>
<ul>
{% for file in files %}
<li><a href="{{ file.url }}">{{ file.name }}</a> (Created: {{ file.created }}, Modified: {{ file.modified }})</li>
{% endfor %}
</ul>
</body>
</html>

0 comments on commit 847372e

Please sign in to comment.