From 1409ff96cdfc4fd6176f36f60fbe86dde1b3b6e4 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Tue, 8 Jun 2021 11:18:04 -0400 Subject: Added ability to override templates. This commit primarily adds the ability to override the base template by adding a '!' on HTML files. It also makes adjustments to the index page display to not show this extra character. Additions to the README reflecting this change, as well as small note on similarity to neocities was added --- .README.swp | Bin 0 -> 28672 bytes .server.py.swp | Bin 0 -> 16384 bytes README | 54 ++++++++++++++++++++++++++------- server.py | 3 +- templates/.base.html.swp | Bin 0 -> 12288 bytes templates/.index.html.swp | Bin 0 -> 12288 bytes templates/index.html | 2 +- templates/site/.home.html.swp | Bin 0 -> 12288 bytes templates/site/.license.html.swp | Bin 0 -> 12288 bytes templates/site/fun/.renegade.html!.swp | Bin 0 -> 12288 bytes templates/site/fun/renegade.html! | 6 ++++ 11 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 .README.swp create mode 100644 .server.py.swp create mode 100644 templates/.base.html.swp create mode 100644 templates/.index.html.swp create mode 100644 templates/site/.home.html.swp create mode 100644 templates/site/.license.html.swp create mode 100644 templates/site/fun/.renegade.html!.swp create mode 100644 templates/site/fun/renegade.html! diff --git a/.README.swp b/.README.swp new file mode 100644 index 0000000..8e1c84f Binary files /dev/null and b/.README.swp differ diff --git a/.server.py.swp b/.server.py.swp new file mode 100644 index 0000000..700dc05 Binary files /dev/null and b/.server.py.swp differ diff --git a/README b/README index 5ebe3c9..9dc6c4c 100644 --- a/README +++ b/README @@ -31,6 +31,18 @@ Flask has great documentation so I think you'll find it a pleasure to build on top of. +### Why not just neocities? + +Neocities is awesome! You should definitely host a site there. + +https://neocities.org/ + +It's easy to get a simple static site going there and it's totally free, but it +lacks server side scripting and a truly self-hosted option. This program gives +you a nice static base to start from, with the ability to script up you own +templates and whatever else Flask has to offer. + + ## Quick start It's recommended to run each server in it's own virtual environment. This @@ -38,11 +50,12 @@ program uses python 3.7, so change `python` to either `python3` or `python3.7` depending on your needs. First clone this repo (with git clone, or download the zip), change into the directory, then: - -`python -m venv env` -`pip install -r requirements.txt` -`python server.py` - +```bash +$ python -m venv env +$ source env/bin/activate +$ pip install -r requirements.txt +$ python server.py +``` Your server will (by default) be hosted on http://127.0.0.1:5000 @@ -119,6 +132,25 @@ You can of course link to external sites, but you must specify the protocol a relative path like `example.net/google.com`. +### Override base template + +Have a page with custom CSS, or need to get rid of the navbar entirely? No +worries! Just add a '!' at the end of you html file and EZCMS will interpret it +as it's own Jinja template without adding everything from the base template. +Tip: if you're just changing the CSS, you can start with the following +boilerplate: + +```code +{% extends 'base.html' %} +{% block css%} +//your cool css here +{% endblock %} +{% block content %} +//your cool content here +{% endblock %} +``` + + ### Making Secret Directories and Files This program follows the Unix convention of placing a "." before directories @@ -156,8 +188,8 @@ replace the HTML with your own license (or none), by editing There are a few special directories linked that are needed to customize your site. First the `static` directory, which holds your static files like CSS templates and images. Second the `raw` directory, which allows -the user to access files the `templates/site` as raw files instead of HTML. -You can disable it by deleting the code under `send_file_from_site` or +the user to access files the `templates/site` as raw files instead of HTML. +You can disable it by deleting the code under `send_file_from_site` or `send_file_from_static` in `server.py`. @@ -168,10 +200,10 @@ an appropriate container. Refer to https://flask.palletsprojects.com/en/2.0.x/de for options, but an easy option I like is to use uwsgi since it's well documented. - -`python -m venv env` -`pip install uwsgi` -`doas -u www uwsgi -s /var/path/to/your-flask.sock --manage-script-name --mount /=server:app --virtualenv ./env` +```bash +$ sudo pip install uwsgi +$ uwsgi -s /var/path/to/your-flask.sock --manage-script-name --mount /=server:app --virtualenv ./env +``` Then point your main http daemon (niginx, apache, httpd) to the socket you made. There are examples for a nginx configuration in the uWSGI and Flask docs: diff --git a/server.py b/server.py index 21ecb2f..15514ba 100644 --- a/server.py +++ b/server.py @@ -121,8 +121,9 @@ def render_file(path): if abs_path.endswith('.html'): with open(abs_path) as f: content = f.read() - print(path.split('/')[-2] + '/') return render_template_string(CONTENT_BLOCK.replace('$', content), **context) + elif abs_path.endswith('.html!'): + return render_template("site/" + path, **context) else: # not an html file, so don't render it return send_from_directory('templates/site/', path, diff --git a/templates/.base.html.swp b/templates/.base.html.swp new file mode 100644 index 0000000..9720cba Binary files /dev/null and b/templates/.base.html.swp differ diff --git a/templates/.index.html.swp b/templates/.index.html.swp new file mode 100644 index 0000000..87ff2f1 Binary files /dev/null and b/templates/.index.html.swp differ diff --git a/templates/index.html b/templates/index.html index 7e815e2..4bbad1d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@ {% if files %}

File Listing

{% for f in files %} -
  • {{ f }}
  • +
  • {{ f.rstrip('!') }}
  • {% endfor %} {% endif %} diff --git a/templates/site/.home.html.swp b/templates/site/.home.html.swp new file mode 100644 index 0000000..b2cc13b Binary files /dev/null and b/templates/site/.home.html.swp differ diff --git a/templates/site/.license.html.swp b/templates/site/.license.html.swp new file mode 100644 index 0000000..d1b0b90 Binary files /dev/null and b/templates/site/.license.html.swp differ diff --git a/templates/site/fun/.renegade.html!.swp b/templates/site/fun/.renegade.html!.swp new file mode 100644 index 0000000..6d77db2 Binary files /dev/null and b/templates/site/fun/.renegade.html!.swp differ diff --git a/templates/site/fun/renegade.html! b/templates/site/fun/renegade.html! new file mode 100644 index 0000000..cc1e6f8 --- /dev/null +++ b/templates/site/fun/renegade.html! @@ -0,0 +1,6 @@ + + +

    This file breaks all the rules!

    +

    This file doesn't use the base template.

    + + -- cgit v1.2.3