mirror of
https://github.com/boostorg/website-v2.git
synced 2026-02-26 17:22:09 +00:00
* 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.
27 lines
814 B
Python
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
|