From 49f6b66f34f5019d582baabdd1ae713b163d3a3a Mon Sep 17 00:00:00 2001
From: Daniel Schadt <kingdread@gmx.de>
Date: Mon, 28 Nov 2022 17:51:00 +0100
Subject: Allow overwriting of the home page

---
 doc/administration/custom-pages.rst | 21 +++++++++++++++++++++
 fietsboek/views/default.py          | 13 +++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/doc/administration/custom-pages.rst b/doc/administration/custom-pages.rst
index 87d4c7c..db92c49 100644
--- a/doc/administration/custom-pages.rst
+++ b/doc/administration/custom-pages.rst
@@ -105,6 +105,27 @@ directory will be included:
     fietsboek.pages =
         /fietsboek/pages/
 
+Overwriting the Home Page
+-------------------------
+
+If you set a slug of ``/``, you can overwrite Fietsboek's custom home page:
+
+.. code:: markdown
+
+    Title: Home
+    Slug: /
+    Link-name: home
+
+    Welcome to Fietsboek!
+    =====================
+
+Note that you can use the same ``Locale`` and ``Show-to`` filters for the home
+page as you can for other custom pages. If no matching home page is found,
+Fietsboek will fall back to the default.
+
+When defining your own home page, make sure to still include it in the
+configuration!
+
 Tips & Tricks
 -------------
 
diff --git a/fietsboek/views/default.py b/fietsboek/views/default.py
index f61b95c..a36e4c3 100644
--- a/fietsboek/views/default.py
+++ b/fietsboek/views/default.py
@@ -26,6 +26,19 @@ def home(request):
     :rtype: pyramid.response.Response
     """
     if not request.identity:
+        # See if the admin set a custom home page
+        page = request.pages.find('/', request)
+        if page is not None:
+            return render_to_response(
+                'fietsboek:templates/static-page.jinja2',
+                {
+                    'title': page.title,
+                    'content': Markup(page.content),
+                },
+                request,
+            )
+
+        # Show the default home page
         locale = request.localizer.locale_name
         content = util.read_localized_resource(locale, "html/home.html")
         return {
-- 
cgit v1.2.3