Files
website-v2/core/views.py
Greg Newman 2487c62d28 🚧 Markdown renderer
* Stubbed out TemplateView for rendering markdown files
* Added a BoostRenderer class to parse the markdown files to support the first iteration of a youtube shortcode and also a Pygments renderer for code blocks.
* Added default styles for some common markup so the rendered markdown looks better.

The pygments renderer is set to use Solarized Dark right now because that’s the closest I see that matches the design of the site.  This can be changed in the class.
2022-09-10 11:07:42 -04:00

27 lines
814 B
Python

import os.path
from django.http import Http404
from django.views.generic import TemplateView
from .markdown import process_md
class MarkdownTemplateView(TemplateView):
template_name = "markdown_template.html"
def get(self, request, *args, **kwargs):
filename = self.kwargs.get("title")
if not os.path.isfile(f"content/{filename}.md"):
raise Http404("Post not found")
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
filename = self.kwargs.get("title")
metadata, content = process_md(f"content/{filename}.md")
context["frontmatter"] = metadata
context["content"] = content
return context