From ea4621aedb025c8ab44dcfb63d01d9b434297ea1 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 17 Mar 2019 20:31:13 +0000 Subject: [PATCH] refactor: homepage sections as headless leaf nodes See #970 --- exampleSite/content/home/about.md | 5 +++-- exampleSite/content/home/accomplishments.md | 3 ++- exampleSite/content/home/contact.md | 7 +++---- exampleSite/content/home/demo.md | 4 ++-- exampleSite/content/home/experience.md | 3 ++- exampleSite/content/home/featured.md | 3 ++- exampleSite/content/home/gallery/index.md | 10 ++++----- exampleSite/content/home/hero.md | 3 ++- exampleSite/content/home/index.md | 5 +++++ exampleSite/content/home/people.md | 7 +++---- exampleSite/content/home/posts.md | 3 ++- exampleSite/content/home/projects.md | 5 +++-- exampleSite/content/home/publications.md | 3 ++- exampleSite/content/home/skills.md | 9 ++++---- exampleSite/content/home/slider.md | 7 +++---- exampleSite/content/home/tags.md | 7 +++---- exampleSite/content/home/talks.md | 3 ++- layouts/home/list.html | 0 layouts/home/single.html | 0 layouts/index.json | 2 +- layouts/partials/widget_page.html | 18 +++++++++------- layouts/rss.xml | 4 ++-- layouts/section/home.html | 0 layouts/shortcodes/gallery.html | 23 +++++++++++++++------ layouts/sitemap.xml | 4 +--- layouts/widget_page/single.html | 1 + 26 files changed, 80 insertions(+), 59 deletions(-) create mode 100644 exampleSite/content/home/index.md delete mode 100644 layouts/home/list.html delete mode 100644 layouts/home/single.html delete mode 100644 layouts/section/home.html create mode 100644 layouts/widget_page/single.html diff --git a/exampleSite/content/home/about.md b/exampleSite/content/home/about.md index b396f2e5..47a8d49b 100644 --- a/exampleSite/content/home/about.md +++ b/exampleSite/content/home/about.md @@ -1,6 +1,7 @@ +++ -# About/Biography widget. -widget = "about" # Do not modify this line! +# About widget. +widget = "about" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 20 # Order that this section will appear in. diff --git a/exampleSite/content/home/accomplishments.md b/exampleSite/content/home/accomplishments.md index 2cb4799d..e2fd9a21 100644 --- a/exampleSite/content/home/accomplishments.md +++ b/exampleSite/content/home/accomplishments.md @@ -1,6 +1,7 @@ +++ # Accomplishments widget. -widget = "accomplishments" # Do not modify this line! +widget = "accomplishments" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 50 # Order that this section will appear. diff --git a/exampleSite/content/home/contact.md b/exampleSite/content/home/contact.md index a34f824c..6459d09f 100644 --- a/exampleSite/content/home/contact.md +++ b/exampleSite/content/home/contact.md @@ -1,14 +1,13 @@ +++ # Contact widget. -widget = "contact" # Do not modify this line! +widget = "contact" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false +weight = 130 # Order that this section will appear. title = "Contact" subtitle = "" -# Order that this section will appear in. -weight = 130 - # Automatically link email and phone? autolink = true diff --git a/exampleSite/content/home/demo.md b/exampleSite/content/home/demo.md index c709b7c7..92363e88 100644 --- a/exampleSite/content/home/demo.md +++ b/exampleSite/content/home/demo.md @@ -3,11 +3,11 @@ # Any elements can be added in the body: https://sourcethemes.com/academic/docs/writing-markdown-latex/ # Add more sections by duplicating this file and customizing to your requirements. -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 = 15 # Order that this section will appear. -# Note: a full width section format can be enabled by commenting out the `title` and `subtitle` with a `#`. title = "Demos" subtitle = "" diff --git a/exampleSite/content/home/experience.md b/exampleSite/content/home/experience.md index 94ffe748..12d7b3db 100644 --- a/exampleSite/content/home/experience.md +++ b/exampleSite/content/home/experience.md @@ -1,6 +1,7 @@ +++ # Experience widget. -widget = "experience" # Do not modify this line! +widget = "experience" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 40 # Order that this section will appear. diff --git a/exampleSite/content/home/featured.md b/exampleSite/content/home/featured.md index 06d588fc..345b6eac 100644 --- a/exampleSite/content/home/featured.md +++ b/exampleSite/content/home/featured.md @@ -3,7 +3,8 @@ # This section displays publications from `content/publication/` which have # `featured = true` in their front matter. -widget = "featured" # Do not modify this line! +widget = "featured" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 80 # Order that this section will appear. diff --git a/exampleSite/content/home/gallery/index.md b/exampleSite/content/home/gallery/index.md index edeb25dd..69b5a0b6 100644 --- a/exampleSite/content/home/gallery/index.md +++ b/exampleSite/content/home/gallery/index.md @@ -1,14 +1,12 @@ +++ -# Custom widget. -widget = "custom" # Do not modify this line! +# Gallery section using the Blank widget and Gallery element (shortcode). +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 = 66 # Order that this section will appear. -# Note: a full width section format can be enabled by commenting out the `title` and `subtitle` with a `#`. title = "Gallery" subtitle = "" - -# Order that this section will appear in. -weight = 66 +++ {{< gallery >}} diff --git a/exampleSite/content/home/hero.md b/exampleSite/content/home/hero.md index ee52ad21..df299d0c 100644 --- a/exampleSite/content/home/hero.md +++ b/exampleSite/content/home/hero.md @@ -1,6 +1,7 @@ +++ # Hero widget. -widget = "hero" # Do not modify this line! +widget = "hero" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 10 # Order that this section will appear. diff --git a/exampleSite/content/home/index.md b/exampleSite/content/home/index.md new file mode 100644 index 00000000..ef8bad51 --- /dev/null +++ b/exampleSite/content/home/index.md @@ -0,0 +1,5 @@ ++++ +# Homepage +type = "widget_page" +headless = true # Homepage is headless, other widget pages are not. ++++ diff --git a/exampleSite/content/home/people.md b/exampleSite/content/home/people.md index fe7730d2..94a1b0ba 100644 --- a/exampleSite/content/home/people.md +++ b/exampleSite/content/home/people.md @@ -1,14 +1,13 @@ +++ # People widget. -widget = "people" # Do not modify this line! +widget = "people" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = false # Activate this widget? true/false +weight = 68 # Order that this section will appear. title = "People" subtitle = "" -# Order that this section will appear in. -weight = 68 - # List user groups to display. # Edit each user's `user_groups` to add them to one or more of these groups. user_groups = ["Principal Investigators", diff --git a/exampleSite/content/home/posts.md b/exampleSite/content/home/posts.md index 1d0fab88..12b3b6f3 100644 --- a/exampleSite/content/home/posts.md +++ b/exampleSite/content/home/posts.md @@ -2,7 +2,8 @@ # A Recent Blog Posts section created with the Pages widget. # This section displays recent blog posts from `content/post/`. -widget = "pages" # Do not modify this line! +widget = "pages" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 60 # Order that this section will appear. diff --git a/exampleSite/content/home/projects.md b/exampleSite/content/home/projects.md index 4c0e9f7c..8378d229 100644 --- a/exampleSite/content/home/projects.md +++ b/exampleSite/content/home/projects.md @@ -1,6 +1,7 @@ +++ -# Portfolio widget. -widget = "portfolio" # Do not modify this line! +# A Projects section created with the Portfolio widget. +widget = "portfolio" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 65 # Order that this section will appear. diff --git a/exampleSite/content/home/publications.md b/exampleSite/content/home/publications.md index 1963062d..1d22f863 100644 --- a/exampleSite/content/home/publications.md +++ b/exampleSite/content/home/publications.md @@ -2,7 +2,8 @@ # A Recent Publications section created with the Pages widget. # This section displays recent blog posts from `content/publication/`. -widget = "pages" # Do not modify this line! +widget = "pages" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 90 # Order that this section will appear. diff --git a/exampleSite/content/home/skills.md b/exampleSite/content/home/skills.md index 0e71d2c7..9f9f18ed 100644 --- a/exampleSite/content/home/skills.md +++ b/exampleSite/content/home/skills.md @@ -1,14 +1,13 @@ +++ -# Feature/Skill widget. -widget = "featurette" # Do not modify this line! +# A Skills section created with the Featurette widget. +widget = "featurette" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false +weight = 30 # Order that this section will appear. title = "Skills" subtitle = "" -# Order that this section will appear in. -weight = 30 - # Showcase personal skills or business features. # # Add/remove as many `[[feature]]` blocks below as you like. diff --git a/exampleSite/content/home/slider.md b/exampleSite/content/home/slider.md index 0f1ca3d9..0aa7cdc6 100644 --- a/exampleSite/content/home/slider.md +++ b/exampleSite/content/home/slider.md @@ -1,10 +1,9 @@ +++ # Slider widget. -widget = "slider" # Do not modify this line! +widget = "slider" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = false # Activate this widget? true/false - -# Order that this section will appear in. -weight = 1 +weight = 1 # Order that this section will appear. # Slide interval. # Use `false` to disable animation or enter a time in ms, e.g. `5000` (5s). diff --git a/exampleSite/content/home/tags.md b/exampleSite/content/home/tags.md index d0d7d22e..4ad29fe5 100644 --- a/exampleSite/content/home/tags.md +++ b/exampleSite/content/home/tags.md @@ -1,11 +1,10 @@ +++ # Tag Cloud widget. -widget = "tag_cloud" # Do not modify this line! +widget = "tag_cloud" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false +weight = 120 # Order that this section will appear. title = "Popular Topics" subtitle = "" - -# Order that this section will appear in. -weight = 120 +++ diff --git a/exampleSite/content/home/talks.md b/exampleSite/content/home/talks.md index eeed17d1..2be02588 100644 --- a/exampleSite/content/home/talks.md +++ b/exampleSite/content/home/talks.md @@ -2,7 +2,8 @@ # A Recent and Upcoming Talks section created with the Pages widget. # This section displays recent talks from `content/talk/`. -widget = "pages" # Do not modify this line! +widget = "pages" # See https://sourcethemes.com/academic/docs/page-builder/ +headless = true # This file represents a page section. active = true # Activate this widget? true/false weight = 70 # Order that this section will appear. diff --git a/layouts/home/list.html b/layouts/home/list.html deleted file mode 100644 index e69de29b..00000000 diff --git a/layouts/home/single.html b/layouts/home/single.html deleted file mode 100644 index e69de29b..00000000 diff --git a/layouts/index.json b/layouts/index.json index 0863ffb6..29ff22bc 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -1,6 +1,6 @@ {{- /* Generate the search index. */ -}} {{- $index := slice -}} -{{- $pages := where .Site.RegularPages "Section" "!=" "home" -}} +{{- $pages := .Site.RegularPages -}} {{- /* Add the index page of docs separately since it's not in RegularPages above. */ -}} {{- $pages := $pages | union (where (where .Site.Pages "Kind" "section") "Type" "docs") -}} {{- /* Add author pages to index so their bios can be searched. Hide empty `/author/` node. */ -}} diff --git a/layouts/partials/widget_page.html b/layouts/partials/widget_page.html index fe92f5f2..183f10b1 100644 --- a/layouts/partials/widget_page.html +++ b/layouts/partials/widget_page.html @@ -4,15 +4,17 @@ -{{ $section := "" }} +{{/* Get widget page path */}} +{{ $page := "" }} {{ if .IsHome }} - {{ $section = "home" }} + {{ $page = "/home" }} {{ else }} - {{ $section = .Section }} + {{ $page = .File.Path }} {{ end }} - -{{ range $index, $st := where (where .Data.Pages "Section" $section) ".Params.active" "!=" false }} +{{/* 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 }} {{ $style := "" }} @@ -39,14 +41,17 @@ {{ end }} {{ $params := dict "root" $ "page" $st }} + {{ $hash_id := replace $st.File.ContentBaseName "index" (path.Base (path.Split .Path).Dir) }} + {{ $widget := or $st.Params.widget "blank" }} {{ if eq $widget "custom" }}{{ $widget = "blank" }}{{ end }}{{/* Support legacy Custom widget */}} {{ if eq $widget "projects" }}{{ $widget = "portfolio" }}{{ end }}{{/* Support legacy Projects widget */}} + {{ $widget_path := printf "widgets/%s.html" $widget }} {{ if in (slice "slider") $widget }} {{ partial $widget_path $params }} {{ else }} -
+
{{ partial $widget_path $params }}
@@ -54,6 +59,5 @@ {{ end }} {{ end }} - {{ partial "footer_container.html" . }} {{ partial "footer.html" . }} diff --git a/layouts/rss.xml b/layouts/rss.xml index 60b670a1..dab718b3 100644 --- a/layouts/rss.xml +++ b/layouts/rss.xml @@ -3,14 +3,14 @@ {{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }} {{ .Permalink }} Recent content {{ with .Title }}in {{.}} {{ end }}on {{ .Site.Title }} - Hugo -- gohugo.io{{ with .Site.LanguageCode }} + Source Themes Academic (https://sourcethemes.com/academic/){{ with .Site.LanguageCode }} {{.}}{{end}}{{ with .Site.Author.email }} {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Author.email }} {{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}{{end}}{{ with .Site.Copyright }} {{.}}{{end}}{{ if not .Date.IsZero }} {{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}{{ end }} - {{ range first 15 (where .Data.Pages "Type" "!=" "home") }} + {{ range first 15 .Data.Pages }} {{ .Title }} {{ .Permalink }} diff --git a/layouts/section/home.html b/layouts/section/home.html deleted file mode 100644 index e69de29b..00000000 diff --git a/layouts/shortcodes/gallery.html b/layouts/shortcodes/gallery.html index 43f321fc..1d4340e3 100644 --- a/layouts/shortcodes/gallery.html +++ b/layouts/shortcodes/gallery.html @@ -1,11 +1,22 @@ -{{ $album := "gallery" }} -{{ with .Get "album" }}{{ $album = . }}{{ end }} -{{ $album_path := printf "%s/*" $album }} -{{/* if eq .Page.Type "home" */}}{{/* $album_path = "*" */}}{{/* end */}} +{{/* Get album folder or default to `gallery/`. */}} +{{ $album := "" }} +{{ with .Get "album" }}{{ $album = . }}{{else}}{{ $album = "gallery" }}{{end}} + +{{/* Set image path and page bundle that images are associated with. */}} +{{ $album_path := "" }} +{{ $resource_page := "" }} +{{ if eq .Page.Parent.Type "widget_page" }} + {{ $album_path = printf "%s/%s/*" (path.Base (path.Split .Page.Path).Dir) $album }} + {{ $resource_page = $.Page.Parent }} +{{ else }} + {{ $album_path = printf "%s/*" $album }} + {{ $resource_page = $.Page }} +{{ end }} + \ No newline at end of file diff --git a/layouts/sitemap.xml b/layouts/sitemap.xml index 67f3f650..98ef318b 100644 --- a/layouts/sitemap.xml +++ b/layouts/sitemap.xml @@ -1,6 +1,5 @@ - {{ range (where .Data.Pages "Section" "!=" "home") }} - {{ if not .Params.widget }} + {{ range .Data.Pages }} {{ if .IsTranslated }} {{ range .Translations }} @@ -11,6 +10,5 @@ {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} {{ .Sitemap.Priority }}{{ end }} - {{ end }} {{ end }} diff --git a/layouts/widget_page/single.html b/layouts/widget_page/single.html new file mode 100644 index 00000000..e1d285b7 --- /dev/null +++ b/layouts/widget_page/single.html @@ -0,0 +1 @@ +{{ partial "widget_page.html" . }}