From 3d9a1277a82ded759843395024e531c64437b91c Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 3 Nov 2018 22:37:36 +0000 Subject: [PATCH] feat(project): list associated posts Close #767 --- archetypes/post/index.md | 8 ++++++++ exampleSite/config.toml | 6 ++++++ .../content/post/getting-started/index.md | 8 ++++++++ layouts/partials/page_metadata.html | 2 +- layouts/partials/post_li_detailed.html | 2 +- layouts/partials/post_li_simple.html | 2 +- layouts/partials/post_li_stream.html | 2 +- layouts/partials/widgets/posts.html | 14 ++++++-------- layouts/project/single.html | 16 ++++++++++++++++ 9 files changed, 48 insertions(+), 12 deletions(-) diff --git a/archetypes/post/index.md b/archetypes/post/index.md index a981655c..98ae9829 100644 --- a/archetypes/post/index.md +++ b/archetypes/post/index.md @@ -11,6 +11,14 @@ authors = [] tags = [] categories = [] +# Projects (optional). +# Associate this post with one or more of your projects. +# Simply enter your project's folder or file name without extension. +# E.g. `projects = ["deep-learning"]` references +# `content/project/deep-learning/index.md`. +# Otherwise, set `projects = []`. +# projects = ["internal-project"] + # Featured image # To use, add an image named `featured.jpg/png` to your page's folder. [image] diff --git a/exampleSite/config.toml b/exampleSite/config.toml index e818a779..bc60c145 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -212,6 +212,12 @@ enableGitInfo = false # List publications and talks related to the project? list_children = true + # Post list format. + # 0 = Simple + # 1 = Detailed + # 2 = Stream + post_format = 2 + # Publication list format. # 0 = Simple # 1 = Detailed diff --git a/exampleSite/content/post/getting-started/index.md b/exampleSite/content/post/getting-started/index.md index 4047aa40..58f184ae 100644 --- a/exampleSite/content/post/getting-started/index.md +++ b/exampleSite/content/post/getting-started/index.md @@ -12,6 +12,14 @@ authors = [] tags = ["Academic"] summary = "Create a beautifully simple website or blog in under 10 minutes." +# Projects (optional). +# Associate this post with one or more of your projects. +# Simply enter your project's folder or file name without extension. +# E.g. `projects = ["deep-learning"]` references +# `content/project/deep-learning/index.md`. +# Otherwise, set `projects = []`. +# projects = ["internal-project"] + # Featured image # To use, add an image named `featured.jpg/png` to your project's folder. [image] diff --git a/layouts/partials/page_metadata.html b/layouts/partials/page_metadata.html index 884ed99e..effc7237 100644 --- a/layouts/partials/page_metadata.html +++ b/layouts/partials/page_metadata.html @@ -45,7 +45,7 @@ {{ end}} - {{ if isset $.Params "categories" }} + {{ if $.Params.categories }} {{ $categoriesLen := len $.Params.categories }} {{ if gt $categoriesLen 0 }} diff --git a/layouts/partials/post_li_detailed.html b/layouts/partials/post_li_detailed.html index bf8dd070..c9455386 100644 --- a/layouts/partials/post_li_detailed.html +++ b/layouts/partials/post_li_detailed.html @@ -1,4 +1,4 @@ -{{ $post := .post }} +{{ $post := . }}
{{ partial "page_metadata" (dict "content" $post "is_list" 1) }} diff --git a/layouts/partials/post_li_simple.html b/layouts/partials/post_li_simple.html index 5f8376de..b1435cec 100644 --- a/layouts/partials/post_li_simple.html +++ b/layouts/partials/post_li_simple.html @@ -1,4 +1,4 @@ -{{ $post := .post }} +{{ $post := . }}
diff --git a/layouts/partials/post_li_stream.html b/layouts/partials/post_li_stream.html index 3364027e..568a1f92 100644 --- a/layouts/partials/post_li_stream.html +++ b/layouts/partials/post_li_stream.html @@ -1,4 +1,4 @@ -{{ $post := .post }} +{{ $post := . }}
diff --git a/layouts/partials/widgets/posts.html b/layouts/partials/widgets/posts.html index 8b59226d..39a24ef1 100644 --- a/layouts/partials/widgets/posts.html +++ b/layouts/partials/widgets/posts.html @@ -45,13 +45,12 @@ {{ $show_post := $.Scratch.Get "show_post" }} {{ if ne $show_post "0" }} - {{ $params := dict "post" . }} {{ if eq $page.Params.list_format 0 }} - {{ partial "post_li_simple" $params }} + {{ partial "post_li_simple" . }} {{ else if eq $page.Params.list_format 1 }} - {{ partial "post_li_detailed" $params }} + {{ partial "post_li_detailed" . }} {{ else }} - {{ partial "post_li_stream" $params }} + {{ partial "post_li_stream" . }} {{ end }} {{end}} @@ -80,13 +79,12 @@ {{ $show_post := $.Scratch.Get "show_post" }} {{ if ne $show_post "0" }} - {{ $params := dict "post" . }} {{ if eq $page.Params.list_format 0 }} - {{ partial "post_li_simple" $params }} + {{ partial "post_li_simple" . }} {{ else if eq $page.Params.list_format 1 }} - {{ partial "post_li_detailed" $params }} + {{ partial "post_li_detailed" . }} {{ else }} - {{ partial "post_li_stream" $params }} + {{ partial "post_li_stream" . }} {{ end }} {{end}} diff --git a/layouts/project/single.html b/layouts/project/single.html index 347856fb..1b4dcfc8 100644 --- a/layouts/project/single.html +++ b/layouts/project/single.html @@ -25,6 +25,22 @@ {{ $project_path := .RelPermalink }} {{ if (.Site.Params.projects.list_children | default true) }} + + {{ $items := where (where .Site.RegularPages "Type" "post") ".Params.projects" "intersect" (slice $project) }} + {{ $count := len $items }} + {{ if ge $count 1 }} +

{{ (i18n "posts") }}

+ {{ range $items }} + {{ if eq $page.Site.Params.projects.post_format 0 }} + {{ partial "post_li_simple" . }} + {{ else if eq $page.Site.Params.projects.post_format 1 }} + {{ partial "post_li_detailed" . }} + {{ else }} + {{ partial "post_li_stream" . }} + {{ end }} + {{ end }} + {{ end }} + {{ $items := where (where .Site.RegularPages "Type" "publication") ".Params.projects" "intersect" (slice $project) }} {{ $items := $items | union (where (where .Site.RegularPages "Type" "publication") ".Params.url_project" $project_path) }} {{ $pubs_len := len $items }}