diff --git a/base.html b/base.html deleted file mode 100644 index fa1e655..0000000 --- a/base.html +++ /dev/null @@ -1,16 +0,0 @@ - -
-This page had been visited {counter['count']} times.
") -{% endpy3 %} - -{% markdown %}## Python sub process execution{% endmarkdown %} -{% py3 %} -print("First file: ",system("ls",output=False).split("\n")[0],"") -print("
",system("free -h",output=False),"") -print("
",system("df -h",output=False),"") -print("
",system("ps aux",output=False,stderr=True),"") -{% endpy3 %} -{% endblock content %} diff --git a/src/Dreamii.egg-info/PKG-INFO b/src/Dreamii.egg-info/PKG-INFO index 122598b..93057dd 100644 --- a/src/Dreamii.egg-info/PKG-INFO +++ b/src/Dreamii.egg-info/PKG-INFO @@ -50,7 +50,7 @@ These are instructions for USING Dreamii, not to modify it. python3 -m venv .venv source .venv/bin/activate pip install git+https://molodetz.nl/retoor/dreamii.git -echo > "# My first dreamii site" > index.md +echo "# My first dreamii site" > index.md dreamii serve 7331 ``` @@ -93,6 +93,7 @@ print( "" ) {% endpy3 %} +``` ### Example database usage See here an example of a visitor counter on your website. This is all you have to do. It's a persistent database. No configuration required! For more information how to use the database, visit the [dataset documentation](https://dataset.readthedocs.io/en/latest/). @@ -108,6 +109,7 @@ def increment(counter_name="default") print(f"
This page had been visited {counter()} times.
") {% endpy3 %} +``` ## Hidden files Files prefixed with `_` or `.` will not be displayed or rendered by Dreamii. This is for security and it is a convenient way to mark base templates. diff --git a/src/dreamii/app.py b/src/dreamii/app.py index cc306b0..a09eb0a 100644 --- a/src/dreamii/app.py +++ b/src/dreamii/app.py @@ -28,9 +28,10 @@ from app.app import Application as BaseApplication, BaseView import pathlib from aiohttp import web -from dreamii.markdown import MarkdownExtension, MarkdownRenderer +from dreamii.markdown import MarkdownExtension, MarkdownRenderer, render_markdown_sync from dreamii.python import PythonExtension import aiohttp_jinja2 +import html class TemplateView(BaseView): @@ -38,34 +39,59 @@ class TemplateView(BaseView): path = pathlib.Path(self.request.app.template_path).joinpath(str(path).lstrip('/')) if path.exists() and path.suffix in ['.html', '.md']: return str(path) - if path.joinpath('.html').exists(): - return str(path.joinpath('.html')) - if path.joinpath('.md').exists(): + elif path.joinpath('.md').exists(): return str(path.joinpath('.md')) - if path.is_dir(): + elif path.joinpath('.html').exists(): + return str(path.joinpath('.html')) + elif path.is_dir(): if path.joinpath('index.html').exists(): return str(path.joinpath('index.html')) - if path.joinpath('index.md').exists(): + elif path.joinpath('index.md').exists(): return str(path.joinpath('index.md')) return None async def render_template(self, path): - context = {'request': self.request, 'post': await self.request.post() or None} + context = {} + context['request'] = self.request + context['post'] = await self.request.post() + if not context['post']: + context['post'] = None try: context['json'] = await self.request.json() except: context['json'] = None + pass - response = None - if str(path.endswith('.md')): + if str(path).endswith(".md"): renderer = MarkdownRenderer(self.request.app, path) - response = web.Response(text=renderer.render()) - else: - response = await super().render_template(path, self.request, context) - - response.headers['Content-Type'] = 'text/html' - - return response + + + + + content = pathlib.Path(path).read_text() + if pathlib.Path(self.template_path).joinpath("_base.html").exists(): + markdown_default_page = "{% extends \"_base.html\" %}{% block content %}{% markdown %}"+content+"{% endmarkdown %}{% endblock %}