From 765a8ad0e324feadea26e6e310cf77f186396907 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sun, 7 Jan 2018 18:00:28 -0800 Subject: [PATCH] Added an option to specify the default page when a directory is the requested URL. This is equivalent to Apache's DirectoryIndex option. --- bin/cmless.py | 5 ++++- bin/config.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/cmless.py b/bin/cmless.py index 825ec25..44399c9 100755 --- a/bin/cmless.py +++ b/bin/cmless.py @@ -4,7 +4,7 @@ # See LICENSE file for copyright and license details. # Python imports -import sys +import sys, os # CMless imports import config, misc, template @@ -12,6 +12,9 @@ import config, misc, template def main(): print("Content-Type: text/html;charset=utf-8\n") + if os.environ['REQUEST_URI'][-1] == "/": + os.environ['REQUEST_URI'] = os.environ['REQUEST_URI'] + config.default_page + content = misc.load_file(config.site_template_prefix + "/" + config.template_file) content = template.page_title(content) content = template.site_title(content) diff --git a/bin/config.py b/bin/config.py index 5ee585f..83d9d32 100644 --- a/bin/config.py +++ b/bin/config.py @@ -16,6 +16,12 @@ site_name = "Site Name" # the CMless code. site_data_prefix = "../site/data" +# Default page name. This specifies the filename to serve (if exists) when a +# directory is specified as the REQUEST_URI. If is equivalent to Apache's +# DirectoryIndex configuration option. No file extension is necessary as the +# markup_file_extension configuration option handles that information. +default_page = "index" + # The prefix to the website template relative to the bin/ folder which contains # the CMless code. site_template_prefix = "../site/template" -- 2.20.1