initial commit
This commit is contained in:
19
app/Dockerfile
Executable file
19
app/Dockerfile
Executable file
@@ -0,0 +1,19 @@
|
||||
FROM python:3.10-slim AS builder
|
||||
|
||||
ARG DEBUG_MODE=0
|
||||
ENV FLASK_DEBUG=$DEBUG_MODE
|
||||
|
||||
ENV FLASK_APP=app.py
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
|
||||
EXPOSE 443
|
||||
ENTRYPOINT ["flask"]
|
||||
CMD ["run", "--host=0.0.0.0", "--port=80"]
|
||||
# CMD ["--app", ".", "run", "--host=0.0.0.0", "--port=443"]
|
||||
|
||||
|
||||
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
35
app/app.py
Normal file
35
app/app.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from flask import Flask
|
||||
import markdown
|
||||
from pathlib import Path
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
CONTENT_DIR = Path(__file__).parent.parent / "content"
|
||||
|
||||
@app.route("/hello")
|
||||
def hello_world():
|
||||
return "<h1>Hello, World!</h1>"
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
# Write your markdown content
|
||||
md_content = "# Welcome to my blog!\nThis is rendered from **Markdown**."
|
||||
# Convert it to HTML
|
||||
html_content = markdown.markdown(md_content)
|
||||
return html_content
|
||||
|
||||
@app.route ("/post/<filename>")
|
||||
def render_markdown_file(filename):
|
||||
filePath = CONTENT_DIR / f"{filename}.md"
|
||||
# 3. Protect against missing files
|
||||
if not filePath.is_file():
|
||||
return f"<h1>404</h1><p>Could not find {filename}.md in {filePath}</p>", 404
|
||||
# else:
|
||||
# return f"<h1> found</h1> <p> found {filename} in {filePath}</p>"
|
||||
# 4. Open, read, and convert the file
|
||||
with open(filePath, "r", encoding="utf-8") as f:
|
||||
textContent = f.read()
|
||||
|
||||
htmlContent = markdown.markdown(textContent)
|
||||
|
||||
return htmlContent
|
||||
2
app/requirements.txt
Executable file
2
app/requirements.txt
Executable file
@@ -0,0 +1,2 @@
|
||||
flask
|
||||
markdown
|
||||
Reference in New Issue
Block a user