Просмотр исходного кода

feat(project): list associated posts

Close #767
George Cushen 6 лет назад
Родитель
Сommit
3d9a1277a8

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

+ 6 - 0
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

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

+ 1 - 1
layouts/partials/page_metadata.html

@@ -45,7 +45,7 @@
   <a href="{{ $.RelPermalink }}#disqus_thread"><!-- Count will be inserted here --></a>
   {{ end}}
 
-  {{ if isset $.Params "categories" }}
+  {{ if $.Params.categories }}
   {{ $categoriesLen := len $.Params.categories }}
   {{ if gt $categoriesLen 0 }}
   <span class="middot-divider"></span>

+ 1 - 1
layouts/partials/post_li_detailed.html

@@ -1,4 +1,4 @@
-{{ $post := .post }}
+{{ $post := . }}
 
 <div class="card-simple" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
   {{ partial "page_metadata" (dict "content" $post "is_list" 1) }}

+ 1 - 1
layouts/partials/post_li_simple.html

@@ -1,4 +1,4 @@
-{{ $post := .post }}
+{{ $post := . }}
 
 <div class="pub-list-item" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
   <i class="far fa-newspaper pub-icon" aria-hidden="true"></i>

+ 1 - 1
layouts/partials/post_li_stream.html

@@ -1,4 +1,4 @@
-{{ $post := .post }}
+{{ $post := . }}
 
 <div class="media stream-item" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
   <div class="media-body">

+ 6 - 8
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}}
 

+ 16 - 0
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 }}
+        <h2>{{ (i18n "posts") }}</h2>
+        {{ 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 }}