From 6778929449aed94edc1eaf642c0c44ac89fff819 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 31 Mar 2019 19:50:26 +0100 Subject: [PATCH] refactor: check admin created a homepage or give error --- archetypes/home.md | 7 ++++++- exampleSite/config/_default/languages.toml | 1 + layouts/partials/widget_page.html | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/archetypes/home.md b/archetypes/home.md index 674e7afb..ff1edd73 100644 --- a/archetypes/home.md +++ b/archetypes/home.md @@ -1,6 +1,7 @@ +++ # A section created with the Blank widget. -widget = "blank" # Do not modify this line! +widget = "blank" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 1 # Order that this section will appear. @@ -32,6 +33,10 @@ subtitle = "" # Text color (true=light or false=dark). # text_color_light = true +[design.spacing] + # Customize the section spacing. Order is top, right, bottom, left. + # padding = ["0px", "0px", "0px", "0px"] + [advanced] # Custom CSS. css_style = "" diff --git a/exampleSite/config/_default/languages.toml b/exampleSite/config/_default/languages.toml index 72b55a63..f7c6da68 100644 --- a/exampleSite/config/_default/languages.toml +++ b/exampleSite/config/_default/languages.toml @@ -5,6 +5,7 @@ # Configure the English version of the site. [en] languageCode = "en-us" + # contentDir = "content/en" # Uncomment for multi-lingual sites, and move English content into `en` sub-folder. # Uncomment the lines below to configure your website in a second language. #[zh] diff --git a/layouts/partials/widget_page.html b/layouts/partials/widget_page.html index f5e69ef6..b592f9aa 100644 --- a/layouts/partials/widget_page.html +++ b/layouts/partials/widget_page.html @@ -4,16 +4,20 @@ -{{/* Get widget page path */}} +{{/* Get widget page */}} {{ $page := "" }} {{ if .IsHome }} {{ $page = "/home" }} {{ else }} {{ $page = .File.Path }} {{ end }} +{{ $headless_bundle := site.GetPage $page }} +{{/* Check homepage exists */}} +{{ if not $headless_bundle }} + {{ errorf "Homepage not found or duplicate homepages detected for a localization! Add the `home/` folder (especially `/home/index.md`) to each language's content folder. For example, your site should have a `content/home/` folder containing `index.md` and your homepage sections, or for multi-language sites, `content/en/home/` and `content/zh/home/` etc. Refer to the 'Build Your Homepage' and 'Language' documentation at https://sourcethemes.com/academic/docs/ and the example homepage at https://github.com/gcushen/hugo-academic/tree/master/exampleSite/content/home/index.md ." }} +{{ end }} {{/* Load page sections */}} -{{ $headless_bundle := .Site.GetPage $page }} {{ range $index, $st := where ( $headless_bundle.Resources.ByType "page" ) ".Params.active" "!=" false }} {{/* Begin widget styling */}} {{ $bg := $st.Params.design.background }}