began implementing automated markdown parsing using hedgedoc
This commit is contained in:
parent
e9f2a840a4
commit
5b4f213105
7 changed files with 39 additions and 18 deletions
|
|
@ -2,6 +2,9 @@ FROM python:3.10-alpine
|
|||
|
||||
ENV PYTHONBUFFERED 1
|
||||
RUN apk update && apk upgrade
|
||||
RUN apk add curl bash jq
|
||||
RUN curl https://raw.githubusercontent.com/hedgedoc/cli/master/bin/hedgedoc > /bin/hedgedoc
|
||||
RUN chmod +x /bin/hedgedoc
|
||||
RUN mkdir "/markdownblog"
|
||||
WORKDIR "/markdownblog"
|
||||
ADD ./requirements.txt /markdownblog/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
from blog.views import viewblog, addpost, createmocks, order
|
||||
from blog.views import viewblog, addpost, createmocks, order, index
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path('', viewblog, name="index"),
|
||||
path('', index, name="index"),
|
||||
path('manage/addpost', addpost, name='addpost'),
|
||||
path('manage/order', order, name='order'),
|
||||
path('mock/<str:objtype>/<int:n>/', createmocks, name='mock'),
|
||||
path('read/<str:title>', viewblog, name='readpost'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import random
|
||||
import markdown2
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import IntegrityError
|
||||
|
|
@ -12,13 +13,26 @@ from django.views.decorators.csrf import csrf_exempt
|
|||
from markdownblog import settings
|
||||
|
||||
|
||||
def viewblog(request) -> HttpResponse:
|
||||
def viewblog(request, title) -> HttpResponse:
|
||||
post = Blogpost.objects.get(title=title)
|
||||
filepath = os.path.join(os.environ.get("MD_FILE_PATH"), title + ".md")
|
||||
with open(filepath, 'r') as mdfile:
|
||||
md_file_content = mdfile.read()
|
||||
mdfile.close()
|
||||
|
||||
html = markdown2.markdown(md_file_content, extras=['footnote', 'task_list', 'strike'])
|
||||
|
||||
context = {'post': post, 'html': html}
|
||||
return render(request, 'blog/viewpost.html', context)
|
||||
|
||||
|
||||
def index(request) -> HttpResponse:
|
||||
return render(request, 'blog/index.html', {"debug": settings.DEBUG})
|
||||
|
||||
|
||||
@login_required
|
||||
@csrf_exempt
|
||||
def order(request):
|
||||
def order(request) -> HttpResponse:
|
||||
if request.method == "POST":
|
||||
root_id = int(request.POST['rootID']) if request.POST['rootID'] != 'root_list' else None
|
||||
child_id = int(request.POST['childID'])
|
||||
|
|
@ -67,7 +81,7 @@ def addpost(request) -> HttpResponse:
|
|||
with open(filepath, "w+") as mdfile:
|
||||
mdfile.write(markdown)
|
||||
mdfile.close()
|
||||
context['error'] = "Post " + title + " created."
|
||||
context['error'] = "Post \"" + title + "\" created."
|
||||
|
||||
return render(request, 'blog/addpost.html', context)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
{% if post.topic == None %}
|
||||
<li class="topic_list_element" draggable="true" ondragstart="drag(event)"
|
||||
id="list_elem_post_{{ post.id }}">
|
||||
Post: {{ post }}
|
||||
<a href="{% url 'readpost' title=post.title %}">{{ post }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
{% if post.topic.id == topic.id %}
|
||||
<li class="topic_list_element" draggable="true" ondragstart="drag(event)"
|
||||
id="list_elem_post_{{ post.id }}">
|
||||
Post: {{ post }}
|
||||
<a href="{% url 'readpost' title=post.title %}">{{ post }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
{% extends 'base/base.html' %}
|
||||
{% load static %}
|
||||
{% block title %}
|
||||
{{ post.title }}
|
||||
{% endblock %}
|
||||
{% block includehere %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% autoescape off %}
|
||||
{{ html }}
|
||||
{% endautoescape %}
|
||||
{% endblock %}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
django==4.0.5
|
||||
psycopg2-binary>=2.9.3
|
||||
factory-boy>=3.2.1
|
||||
factory-boy>=3.2.1
|
||||
markdown2>=2.4.3
|
||||
Loading…
Add table
Add a link
Reference in a new issue