1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/pages/utils.py
Jake Howard 97601a7b53 Refactor view code
- Compress codebase
- Remove duplicate bulky code
- Use template directory to dictate sitemap
2016-04-05 19:38:09 +01:00

23 lines
572 B
Python

from django.conf import settings
from bs4 import BeautifulSoup
import markdown2
def get_context(path):
if path in settings.PAGE_CONTEXT:
context = dict(settings.DEFAULT_CONTEXT, **settings.PAGE_CONTEXT[path])
else:
context = dict(settings.DEFAULT_CONTEXT)
return context
def get_title_from_markdown(md):
html_tree = BeautifulSoup(md, "html.parser")
tag = html_tree.find('h1')
return tag.contents[0]
def parse_content(content, extension):
if extension == 'md':
return markdown2.markdown(content)
return content