Jelajahi Sumber

refactor: consolidate and simplify compact views

- Consolidate the code for all compact views into a single file
- Make authors clickable in all compact views
- Improve archetypes

BREAKING CHANGES:
`abstract_short` field dropped in publications and talks in favour of
`summary` field.

See #918
See https://github.com/gcushen/hugo-academic/issues/916#issuecomment-462274214
George Cushen 6 tahun lalu
induk
melakukan
1584b2db62

+ 11 - 10
archetypes/publication/index.md

@@ -1,10 +1,9 @@
 +++
 title = "{{ replace .Name "-" " " | title }}"
 date = {{ .Date }}
-draft = false
 
 # Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
-authors = [""]
+authors = []
 
 # Publication type.
 # Legend:
@@ -21,13 +20,22 @@ publication_types = ["0"]
 publication = ""
 publication_short = ""
 
-# Abstract and optional shortened version.
+# Abstract.
 abstract = ""
+
+# Summary. An optional shortened abstract.
 abstract_short = ""
 
+# Digital Object Identifier (DOI)
+doi = ""
+
 # Is this a featured publication? (true/false)
 featured = false
 
+# Tags (optional).
+#   Set `tags = []` for no tags, or use the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
+tags = []
+
 # Projects (optional).
 #   Associate this publication with one or more of your projects.
 #   Simply enter your project's folder or file name without extension.
@@ -44,10 +52,6 @@ projects = []
 #   Otherwise, set `slides = ""`.
 slides = ""
 
-# Tags (optional).
-#   Set `tags = []` for no tags, or use the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
-tags = []
-
 # Links (optional).
 url_pdf = ""
 url_preprint = ""
@@ -63,9 +67,6 @@ url_source = ""
 #   Uncomment line below to enable. For multiple links, use the form `[{...}, {...}, {...}]`.
 # url_custom = [{name = "Custom Link", url = "http://example.org"}]
 
-# Digital Object Identifier (DOI)
-doi = ""
-
 # Featured image
 # To use, add an image named `featured.jpg/png` to your page's folder. 
 [image]

+ 24 - 21
archetypes/talk/index.md

@@ -1,7 +1,9 @@
 +++
 title = "{{ replace .Name "-" " " | title }}"
 date = {{ .Date }}  # Schedule page publish date.
-draft = false
+
+# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
+authors = []
 
 # Talk start and end times.
 #   End time can optionally be hidden by prefixing the line with `#`.
@@ -9,32 +11,27 @@ time_start = {{ .Date }}
 time_end = {{ .Date }}
 all_day = false
 
-# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
-authors = []
-
-# Abstract and optional shortened version.
-abstract = ""
-abstract_short = ""
+# Location of event.
+location = ""
 
 # Name of event and optional event URL.
 event = ""
 event_url = ""
 
-# Location of event.
-location = ""
+# Abstract. What's your talk about?
+abstract = ""
+
+# Summary. An optional shortened abstract.
+summary = ""
 
 # Is this a featured talk? (true/false)
 featured = false
 
-# Projects (optional).
-#   Associate this talk 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 = []
+# Tags (optional).
+#   Set `tags = []` for no tags, or use the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
+tags = []
 
-# Slides (optional).
+# Markdown Slides (optional).
 #   Associate this page with Markdown slides.
 #   Simply enter your slide deck's filename without extension.
 #   E.g. `slides = "example-slides"` references 
@@ -42,13 +39,19 @@ projects = []
 #   Otherwise, set `slides = ""`.
 slides = ""
 
-# Tags (optional).
-#   Set `tags = []` for no tags, or use the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
-tags = []
+# Optional filename of your slides within your talk folder or a URL.
+url_slides = ""
+
+# Projects (optional).
+#   Associate this talk 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 = []
 
 # Links (optional).
 url_pdf = ""
-url_slides = ""
 url_video = ""
 url_code = ""
 

+ 23 - 23
exampleSite/content/talk/example/index.md

@@ -1,7 +1,9 @@
 +++
 title = "Example Talk"
-date = 2017-01-01T00:00:00  # Schedule page publish date.
-draft = false
+date = 2017-01-01T00:00:00  # Schedule page publish date (not talk date).
+
+# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
+authors = []
 
 # Talk start and end times.
 #   End time can optionally be hidden by prefixing the line with `#`.
@@ -9,36 +11,27 @@ time_start = 2030-06-01T13:00:00
 time_end = 2030-06-01T15:00:00
 all_day = false
 
-# Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`.
-authors = []
-
-# Abstract and optional shortened version.
-abstract = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis posuere tellus ac convallis placerat. Proin tincidunt magna sed ex sollicitudin condimentum. Sed ac faucibus dolor, scelerisque sollicitudin nisi. Cras purus urna, suscipit quis sapien eu, pulvinar tempor diam."
-abstract_short = "An example talk using Academic's Markdown slides feature."
+# Location of event.
+location = "London, United Kingdom"
 
 # Name of event and optional event URL.
 event = "Academic Theme Conference"
 event_url = "https://example.org"
 
-# Location of event.
-location = "London, United Kingdom"
+# Abstract. What's your talk about?
+abstract = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis posuere tellus ac convallis placerat. Proin tincidunt magna sed ex sollicitudin condimentum. Sed ac faucibus dolor, scelerisque sollicitudin nisi. Cras purus urna, suscipit quis sapien eu, pulvinar tempor diam."
+
+# Summary. An optional shortened abstract.
+summary = "An example talk using Academic's Markdown slides feature."
 
 # Is this a featured talk? (true/false)
 featured = false
 
-# Projects (optional).
-#   Associate this talk 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"]
-
 # Tags (optional).
 #   Set `tags = []` for no tags, or use the form `tags = ["A Tag", "Another Tag"]` for one or more tags.
 tags = []
 
-# Slides (optional).
+# Markdown Slides (optional).
 #   Associate this talk with Markdown slides.
 #   Simply enter your slide deck's filename without extension.
 #   E.g. `slides = "example-slides"` references 
@@ -46,15 +39,22 @@ tags = []
 #   Otherwise, set `slides = ""`.
 slides = "example-slides"
 
+# Optional filename of your slides within your talk folder or a URL.
+url_slides = ""
+
+# Projects (optional).
+#   Associate this talk 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"]
+
 # Links (optional).
 url_pdf = ""
-url_slides = ""
 url_video = ""
 url_code = ""
 
-# Does the content use math formatting?
-math = true
-
 # Featured image
 # To use, add an image named `featured.jpg/png` to your page's folder. 
 [image]

+ 89 - 0
layouts/partials/li_compact.html

@@ -0,0 +1,89 @@
+{{ $item := . }}
+
+{{ $microdata_type := "CreativeWork" }}
+{{ $show_authors_only := false }}{{/* Show authors only or full metadata? */}}
+{{ $show_buttons := false }}
+
+{{/* Dynamic view adjusts to content type. */}}
+{{ if eq $item.Type "post" }}
+  {{ $microdata_type = "BlogPosting" }}
+{{ else if eq $item.Type "talk" }}
+  {{ $microdata_type = "Event" }}
+  {{ $show_authors_only = true }}
+  {{ $show_buttons = true }}
+{{ else if eq $item.Type "publication" }}
+  {{ $microdata_type = "ScholarlyArticle" }}
+  {{ $show_authors_only = true }}
+  {{ $show_buttons = true }}
+{{ end }}
+
+{{/* Get summary. */}}
+{{ $summary := "" }}
+{{ if $item.Params.summary }}
+  {{ $summary = $item.Params.summary | markdownify | emojify }}
+{{ else if .Params.abstract }}
+  {{ $summary = .Params.abstract | markdownify | emojify }}
+{{ else if $item.Truncated }}
+  {{ $summary = $item.Summary }}
+{{ end }}
+
+<div class="media stream-item" itemscope itemtype="http://schema.org/{{$microdata_type}}">
+  <div class="media-body">
+
+    <h3 class="article-title mb-0 mt-0" itemprop="name">
+      <a href="{{ $item.RelPermalink }}" itemprop="url">{{ $item.Title }}</a>
+    </h3>
+
+    {{ with $summary }}
+    <div class="article-style" itemprop="articleBody">
+      {{ . | truncate 135 }}
+    </div>
+    {{ end }}
+
+    <div class="stream-meta article-metadata">
+
+      {{ if eq $item.Type "talk" }}
+      <div>
+        <span itemprop="startDate">
+          {{ $date := $item.Params.time_start | default $item.Date }}
+          {{ (time $date).Format $.Site.Params.date_format }}
+          {{ if not $item.Params.all_day }}
+          {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }}
+          {{ end }}
+          {{ with .Params.time_end }}
+          &mdash; {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }}
+          {{ end }}
+        </span>
+        {{ with $item.Params.location }}
+        <span class="middot-divider"></span>
+        <span itemprop="location">{{ . }}</span>
+        {{ end }}
+      </div>
+      {{ end }}
+
+      {{ if and $show_authors_only $item.Params.authors }}
+      <div itemprop="author">
+        {{ partial "page_metadata_authors" $item }}
+      </div>
+      {{ else if not $show_authors_only }}
+        {{ partial "page_metadata" (dict "content" $item "is_list" 1) }}
+      {{ end }}
+    </div>
+
+    {{ if $show_buttons }}
+    <div class="btn-links">
+      {{ partial "page_links" (dict "content" $item "is_list" 1) }}
+    </div>
+    {{ end }}
+
+  </div>
+  <div class="ml-3">
+    {{ $resource := ($item.Resources.ByType "image").GetMatch "*featured*" }}
+    {{ with $resource }}
+    {{ $image := .Resize "150x" }}
+    <a href="{{ $item.RelPermalink }}">
+      <img src="{{ $image.RelPermalink }}" itemprop="image">
+    </a>
+    {{end}}
+  </div>
+</div>

+ 9 - 5
layouts/partials/li_list.html

@@ -1,23 +1,24 @@
 {{ $item := . }}
 
-{{ $microdata_type := "http://schema.org/CreativeWork" }}
+{{ $microdata_type := "CreativeWork" }}
 {{ $icon := "fa-file-alt" }}
 {{ $show_authors := false }}
 {{ $show_buttons := false }}
 
 {{/* Dynamic view adjusts to content type. */}}
 {{ if eq $item.Type "post" }}
-  {{ $microdata_type = "http://schema.org/BlogPosting" }}
+  {{ $microdata_type = "BlogPosting" }}
   {{ $icon = "fa-newspaper" }}
 {{ else if eq $item.Type "talk" }}
-  {{ $microdata_type = "http://schema.org/Event" }}
+  {{ $microdata_type = "Event" }}
   {{ $icon = "fa-calendar-alt" }}
 {{ else if eq $item.Type "publication" }}
+  {{ $microdata_type = "ScholarlyArticle" }}
   {{ $show_authors = true }}
   {{ $show_buttons = true }}
 {{ end }}
 
-<div class="view-list-item" itemscope itemtype="{{$microdata_type}}">
+<div class="view-list-item" itemscope itemtype="http://schema.org/{{$microdata_type}}">
   <i class="far {{$icon}} pub-icon" aria-hidden="true"></i>
   <a href="{{ $item.RelPermalink }}" itemprop="url"><span itemprop="name">{{ $item.Title }}</span></a>
 
@@ -29,6 +30,9 @@
       {{ if not $item.Params.all_day }}
       {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }}
       {{ end }}
+      {{ with .Params.time_end }}
+      &mdash; {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }}
+      {{ end }}
     </span>
     {{ with $item.Params.location }}
     <span class="middot-divider"></span>
@@ -37,7 +41,7 @@
   </div>
   {{ end }}
 
-  {{ if $show_authors }}
+  {{ if and $show_authors $item.Params.authors }}
   <div class="article-metadata" itemprop="author">
     {{ partial "page_metadata_authors" $item }}
   </div>

+ 0 - 36
layouts/partials/post_li_compact.html

@@ -1,36 +0,0 @@
-{{ $post := . }}
-
-<div class="media stream-item" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
-  <div class="media-body">
-
-    <h3 class="article-title mb-0 mt-0" itemprop="headline">
-      <a href="{{ $post.RelPermalink }}" itemprop="url">{{ $post.Title }}</a>
-    </h3>
-
-    {{ $summary := "" }}
-    {{ if $post.Params.summary }}
-      {{ $summary = $post.Params.summary | markdownify }}
-    {{ else if $post.Truncated }}
-      {{ $summary = $post.Summary }}
-    {{ end }}
-    {{ with $summary }}
-    <div class="article-style" itemprop="articleBody">
-      {{ . | truncate 135 }}
-    </div>
-    {{ end }}
-
-    <div class="stream-meta">
-    {{ partial "page_metadata" (dict "content" $post "is_list" 1) }}
-    </div>
-
-  </div>
-  <div class="ml-3">
-    {{ $resource := ($post.Resources.ByType "image").GetMatch "*featured*" }}
-    {{ with $resource }}
-    {{ $image := .Resize "150x" }}
-    <a href="{{ $post.RelPermalink }}">
-      <img src="{{ $image.RelPermalink }}" itemprop="image">
-    </a>
-    {{end}}
-  </div>
-</div>

+ 0 - 42
layouts/partials/publication_li_compact.html

@@ -1,42 +0,0 @@
-<div class="media stream-item" itemscope itemtype="http://schema.org/ScholarlyArticle">
-  <div class="media-body">
-
-    <h3 class="article-title mb-0 mt-0" itemprop="name">
-      <a href="{{ .RelPermalink }}" itemprop="url">{{ .Title }}</a>
-    </h3>
-
-    {{ $summary := "" }}
-    {{ if .Params.abstract_short }}
-      {{ $summary = .Params.abstract_short | markdownify }}
-    {{ else if .Params.abstract }}
-      {{ $summary = .Params.abstract | markdownify }}
-    {{ else if .Truncated }}
-      {{ $summary = .Summary }}
-    {{ end }}
-    {{ with $summary }}
-    <div class="article-style" itemprop="articleBody">
-      {{ . | truncate 135 }}
-    </div>
-    {{ end }}
-
-    <div class="stream-meta article-metadata">
-      <div itemprop="author">
-        {{ partial "page_metadata_authors" . }}
-      </div>
-    </div>
-
-    <div class="btn-links">
-      {{ partial "page_links" (dict "content" . "is_list" 1) }}
-    </div>
-
-  </div>
-  <div class="ml-3">
-    {{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }}
-    {{ with $resource }}
-    {{ $image := .Resize "150x" }}
-    <a href="{{ $.RelPermalink }}">
-      <img src="{{ $image.RelPermalink }}" itemprop="image">
-    </a>
-    {{end}}
-  </div>
-</div>

+ 0 - 60
layouts/partials/talk_li_compact.html

@@ -1,60 +0,0 @@
-<div class="media stream-item" itemscope itemtype="http://schema.org/Event">
-  <div class="media-body">
-
-    <h3 class="article-title mb-0 mt-0" itemprop="name">
-      <a href="{{ .RelPermalink }}" itemprop="url">{{ .Title }}</a>
-    </h3>
-
-    {{ $summary := "" }}
-    {{ if .Params.abstract_short }}
-      {{ $summary = .Params.abstract_short | markdownify }}
-    {{ else if .Params.abstract }}
-      {{ $summary = .Params.abstract | markdownify }}
-    {{ else if .Truncated }}
-      {{ $summary = .Summary }}
-    {{ end }}
-    {{ with $summary }}
-    <div class="article-style" itemprop="articleBody">
-      {{ . | truncate 135 }}
-    </div>
-    {{ end }}
-
-    <div class="stream-meta article-metadata">
-      <div>
-        {{ $date := .Params.time_start | default .Date }}
-        {{ (time $date).Format $.Site.Params.date_format }}
-        {{ if not .Params.all_day }}
-          {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }}
-          {{ with .Params.time_end }}
-            &mdash; {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }}
-          {{ end }}
-        {{ end }}
-
-        {{ if .Params.event }}
-          <span class="middot-divider"></span> {{ .Params.event | markdownify }}
-        {{ else if .Params.event_short }}
-          <span class="middot-divider"></span> {{ .Params.event_short | markdownify }}
-        {{ end }}
-      </div>
-      <div itemprop="author">
-        {{ with .Params.authors }}
-        {{- delimit . ", " | markdownify -}}
-        {{- end -}}
-      </div>
-    </div>
-
-    <div class="btn-links">
-      {{ partial "page_links" (dict "content" . "is_list" 1) }}
-    </div>
-
-  </div>
-  <div class="ml-3">
-    {{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }}
-    {{ with $resource }}
-    {{ $image := .Resize "150x" }}
-    <a href="{{ $.RelPermalink }}">
-      <img src="{{ $image.RelPermalink }}" itemprop="image">
-    </a>
-    {{end}}
-  </div>
-</div>

+ 1 - 1
layouts/partials/widgets/posts.html

@@ -31,7 +31,7 @@
       {{ else if eq $page.Params.view 3 }}
         {{ partial "post_li_card" . }}
       {{ else }}
-        {{ partial "post_li_compact" . }}
+        {{ partial "li_compact" . }}
       {{ end }}
     {{end}}
 

+ 1 - 1
layouts/partials/widgets/publications.html

@@ -28,7 +28,7 @@
       {{ else if eq $page.Params.view 4 }}
         {{ partial "publication_li_citation" . }}
       {{ else }}
-        {{ partial "publication_li_compact" . }}
+        {{ partial "li_compact" . }}
       {{ end }}
     {{ end }}
 

+ 1 - 1
layouts/partials/widgets/publications_featured.html

@@ -25,7 +25,7 @@
       {{ else if eq $page.Params.view 4 }}
         {{ partial "publication_li_citation" . }}
       {{ else }}
-        {{ partial "publication_li_compact" . }}
+        {{ partial "li_compact" . }}
       {{ end }}
     {{ end }}
 

+ 1 - 1
layouts/partials/widgets/talks.html

@@ -24,7 +24,7 @@
       {{ else if eq $page.Params.view 3 }}
         {{ partial "talk_li_card" . }}
       {{ else }}
-        {{ partial "talk_li_compact" . }}
+        {{ partial "li_compact" . }}
       {{ end }}
     {{ end }}
 

+ 1 - 1
layouts/partials/widgets/talks_featured.html

@@ -16,7 +16,7 @@
       {{ else if eq $page.Params.view 3 }}
         {{ partial "talk_li_card" . }}
       {{ else }}
-        {{ partial "talk_li_compact" . }}
+        {{ partial "li_compact" . }}
       {{ end }}
     {{ end }}
   </div>

+ 3 - 3
layouts/project/single.html

@@ -27,7 +27,7 @@
         {{ else if eq $page.Site.Params.projects.post_view 3 }}
           {{ partial "post_li_card" . }}
         {{ else }}
-          {{ partial "post_li_compact" . }}
+          {{ partial "li_compact" . }}
         {{ end }}
       {{ end }}
     {{ end }}
@@ -44,7 +44,7 @@
         {{ else if eq $page.Site.Params.projects.publication_view 4 }}
           {{ partial "publication_li_citation" . }}
         {{ else }}
-          {{ partial "publication_li_compact" . }}
+          {{ partial "li_compact" . }}
         {{ end }}
       {{ end }}
     {{ end }}
@@ -59,7 +59,7 @@
         {{ else if eq $page.Site.Params.projects.talk_view 3 }}
           {{ partial "talk_li_card" . }}
         {{ else }}
-          {{ partial "talk_li_compact" . }}
+          {{ partial "li_compact" . }}
         {{ end }}
       {{ end }}
     {{ end }}

+ 1 - 1
layouts/section/post.html

@@ -16,7 +16,7 @@
     {{ else if eq $.Params.view 3 }}
       {{ partial "post_li_card" . }}
     {{ else }}
-      {{ partial "post_li_compact" . }}
+      {{ partial "li_compact" . }}
     {{ end }}
   {{ end }}
 

+ 1 - 1
layouts/section/publication.html

@@ -65,7 +65,7 @@
           {{ else if eq $.Params.view 4 }}
             {{ partial "publication_li_citation" . }}
           {{ else }}
-            {{ partial "publication_li_compact" . }}
+            {{ partial "li_compact" . }}
           {{ end }}
         </div>
 

+ 1 - 1
layouts/section/talk.html

@@ -24,7 +24,7 @@
             {{ else if eq $.Params.view 3 }}
               {{ partial "talk_li_card" . }}
             {{ else }}
-              {{ partial "talk_li_compact" . }}
+              {{ partial "li_compact" . }}
             {{ end }}
           {{ end }}