Explorar o código

projects: Support featured image with automatic resizing

- Require Hugo v0.49
- Refactor project archetype to new Hugo v0.49 directory-based archetype
- Deprecate `image_preview` option
- Revise demo projects to use new functionality

See #708
George Cushen %!s(int64=6) %!d(string=hai) anos
pai
achega
8cea142b81

+ 2 - 13
archetypes/project.md → archetypes/project/index.md

@@ -10,22 +10,11 @@ tags = []
 # Project summary to display on homepage.
 summary = ""
 
-# Optional image to display on homepage.
-image_preview = ""
-
 # Optional external URL for project (replaces project detail page).
 external_link = ""
 
-# Does the project detail page use math formatting?
-math = false
-
-# Does the project detail page use source code highlighting?
-highlight = true
-
 # Featured image
-# Place your image in the `static/img/` folder and reference its filename below, e.g. `image = "example.jpg"`.
+# To use, add an image named `featured.jpg/png` to your project's folder. 
 [header]
-image = ""
-caption = ""
-
+caption = ""  # Optionally add a caption to the featured image.
 +++

BIN=BIN
exampleSite/content/project/external-project/featured.jpg


+ 7 - 10
exampleSite/content/project/example-external-project.md → exampleSite/content/project/external-project/index.md

@@ -1,16 +1,13 @@
 +++
-# Date this page was created.
-date = 2016-04-27T00:00:00
-
 # Project title.
 title = "External Project"
 
+# Date this page was created.
+date = 2016-04-27T00:00:00
+
 # Project summary to display on homepage.
 summary = "An example of linking directly to an external project website using `external_link`."
 
-# Optional image to display on homepage (relative to `static/img/` folder).
-image_preview = "boards.jpg"
-
 # Tags: can be used for filtering projects.
 # Example: `tags = ["machine-learning", "deep-learning"]`
 tags = ["Demo"]
@@ -18,8 +15,8 @@ tags = ["Demo"]
 # Optional external URL for project (replaces project detail page).
 external_link = "http://example.org"
 
-# Does the project detail page use math formatting?
-math = false
-
+# Featured image
+# To use, add an image named `featured.jpg/png` to your project's folder. 
+[header]
+caption = "Photo by Toa Heftiba on Unsplash"  # Optionally add a caption to the featured image.
 +++
-

BIN=BIN
exampleSite/content/project/internal-project/featured.jpg


+ 7 - 14
exampleSite/content/project/deep-learning.md → exampleSite/content/project/internal-project/index.md

@@ -1,15 +1,12 @@
 +++
+# Project title.
+title = "Internal Project"
+
 # Date this page was created.
 date = 2016-04-27T00:00:00
 
-# Project title.
-title = "Deep Learning"
-
 # Project summary to display on homepage.
-summary = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
-
-# Optional image to display on homepage (relative to `static/img/` folder).
-image_preview = "bubbles.jpg"
+summary = "An example of using the in-built project page."
 
 # Tags: can be used for filtering projects.
 # Example: `tags = ["machine-learning", "deep-learning"]`
@@ -18,14 +15,10 @@ tags = ["Deep Learning"]
 # Optional external URL for project (replaces project detail page).
 external_link = ""
 
-# Does the project detail page use math formatting?
-math = false
-
-# Optional featured image (relative to `static/img/` folder).
+# Featured image
+# To use, add an image named `featured.jpg/png` to your project's folder. 
 [header]
-image = "headers/bubbles-wide.jpg"
-caption = "My caption :smile:"
-
+caption = "Photo by rawpixel on Unsplash"  # Optionally add a caption to the featured image.
 +++
 
 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. Quisque risus orci, mollis id ante sit amet, gravida egestas nisl. Sed ac tempus magna. Proin in dui enim. Donec condimentum, sem id dapibus fringilla, tellus enim condimentum arcu, nec volutpat est felis vel metus. Vestibulum sit amet erat at nulla eleifend gravida.

BIN=BIN
exampleSite/static/img/bubbles.jpg


+ 1 - 1
layouts/partials/publication_links.html

@@ -36,7 +36,7 @@
     {{ i18n "btn_project" }}
   </a>
   {{ else }}
-    {{ errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $.File.Path . }}
+    {{/* errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $.File.Path . */}}
   {{ end }}
 {{ end }}
 {{ else }}

+ 1 - 1
layouts/partials/talk_links.html

@@ -27,7 +27,7 @@
     {{ i18n "btn_project" }}
   </a>
   {{ else }}
-    {{ errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $.File.Path . }}
+    {{/* errorf "The `projects` parameter in `content/%s` references a project file, `content/project/%s`, which cannot be found. Please either set `projects = []` or fix the reference." $.File.Path . */}}
   {{ end }}
 {{ end }}
 {{ range $.Params.url_custom }}

+ 10 - 8
layouts/partials/widgets/projects.html

@@ -71,18 +71,20 @@
     <div class="row isotope projects-container js-layout-masonry">
 
       {{ range $project := where $.Site.RegularPages "Type" ($page.Params.folder | default "project") }}
-      {{ $.Scratch.Set "project_url" $project.RelPermalink }}
-      {{ $.Scratch.Set "target" "" }}
-      {{ if $project.Params.external_link }}
-      {{   $.Scratch.Set "project_url" $project.Params.external_link }}
-      {{   $.Scratch.Set "target" "target=\"_blank\"" }}
-      {{ end }}
+        {{ $.Scratch.Set "project_url" $project.RelPermalink }}
+        {{ $.Scratch.Set "target" "" }}
+        {{ if $project.Params.external_link }}
+        {{   $.Scratch.Set "project_url" $project.Params.external_link }}
+        {{   $.Scratch.Set "target" "target=\"_blank\"" }}
+        {{ end }}
+        {{ $resource := ($project.Resources.ByType "image").GetMatch "*featured*" }}
       <div class="col-12 col-md-6 col-lg-4 project-item isotope-item {{ delimit (apply .Params.tags "urlize" ".") " " }}">
         <div class="card">
-          {{ with $project.Params.image_preview }}
+          {{ with $resource }}
+          {{ $image := .Fill "550x550" }}
           <a href="{{ $.Scratch.Get "project_url" }}" title="" class="card-image hover-overlay"
              {{ $.Scratch.Get "target" | safeHTMLAttr }}>
-            <img src="{{ "/img/" | relURL }}{{ . }}" alt="" class="img-responsive">
+            <img src="{{ $image.RelPermalink }}" alt="" class="img-responsive">
           </a>
           {{ end }}
           <div class="card-text">

+ 1 - 1
theme.toml

@@ -3,7 +3,7 @@ license = "MIT"
 licenselink = "https://github.com/gcushen/hugo-academic/blob/master/LICENSE.md"
 description = "The website designer for Hugo. Build anything and deploy with one click! Fully customizable with themes, plugins, and language packs."
 homepage = "https://sourcethemes.com/academic/"
-min_version = 0.48
+min_version = 0.49
 tags = ["academic",
         "portfolio",
         "responsive",