Pārlūkot izejas kodu

refactor: check admin created a homepage or give error

George Cushen 6 gadi atpakaļ
vecāks
revīzija
6778929449

+ 6 - 1
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 = ""

+ 1 - 0
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]

+ 6 - 2
layouts/partials/widget_page.html

@@ -4,16 +4,20 @@
 <!-- Flag for jQuery -->
 <span id="homepage" class="d-none"></span>
 
-{{/* 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 }}