Add article thumb, cover and feature images

pull/360/head
James Panther 2022-11-09 09:30:26 +11:00
parent ca1f739eca
commit c9cf3c5f6b
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
26 changed files with 141 additions and 44 deletions

View File

@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added ### Added
- Support for article thumbnails, covers and featured images
- Traditional Chinese (Taiwan) translation ([#262](https://github.com/jpanther/congo/pull/262)) - Traditional Chinese (Taiwan) translation ([#262](https://github.com/jpanther/congo/pull/262))
- New `list.paginationWidth` parameter to specify how many pagination links are generated before they are truncated - New `list.paginationWidth` parameter to specify how many pagination links are generated before they are truncated
- Tailwind plugin for Prettier to standardise the order of CSS classes ([#268](https://github.com/jpanther/congo/pull/268)) - Tailwind plugin for Prettier to standardise the order of CSS classes ([#268](https://github.com/jpanther/congo/pull/268))

View File

@ -1799,6 +1799,14 @@ body:has(#menu-controller:checked) {
margin-top: 1.5rem; margin-top: 1.5rem;
} }
.mb-6 {
margin-bottom: 1.5rem;
}
.-mt-4 {
margin-top: -1rem;
}
.mr-3 { .mr-3 {
margin-right: 0.75rem; margin-right: 0.75rem;
} }
@ -2240,6 +2248,10 @@ body:has(#menu-controller:checked) {
padding-top: 0.75rem; padding-top: 0.75rem;
} }
.pr-4 {
padding-right: 1rem;
}
.pl-2 { .pl-2 {
padding-left: 0.5rem; padding-left: 0.5rem;
} }
@ -2854,6 +2866,10 @@ body:has(#menu-controller:checked) {
width: 50%; width: 50%;
} }
.sm\:w-40 {
width: 10rem;
}
.sm\:flex-row { .sm\:flex-row {
flex-direction: row; flex-direction: row;
} }
@ -2872,6 +2888,10 @@ body:has(#menu-controller:checked) {
padding-bottom: 2.5rem; padding-bottom: 2.5rem;
} }
.sm\:pr-6 {
padding-right: 1.5rem;
}
.sm\:pt-10 { .sm\:pt-10 {
padding-top: 2.5rem; padding-top: 2.5rem;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -89,6 +89,8 @@ Although these are the default schemes, you can also create your own. Refer to t
By default, Congo doesn't force you to use a particular content type. In doing so you are free to define your content as you wish. You might prefer _pages_ for a static site, _posts_ for a blog, or _projects_ for a portfolio. By default, Congo doesn't force you to use a particular content type. In doing so you are free to define your content as you wish. You might prefer _pages_ for a static site, _posts_ for a blog, or _projects_ for a portfolio.
### Directory structure
Here's a quick overview of a basic Congo project. All content is placed within the `content` folder: Here's a quick overview of a basic Congo project. All content is placed within the `content` folder:
```shell ```shell
@ -111,8 +113,45 @@ Here's a quick overview of a basic Congo project. All content is placed within t
└── congo └── congo
``` ```
{{< alert >}}
The key thing to note here is that within the content directory, normal article pages are named `index.md` while list pages are named `_index.md`. Any assets that go along with the article should be placed in a sub-directory alongside the index file.
{{< /alert >}}
It's important to have a firm grasp of how Hugo expects content to be organised as the theme is designed to take full advantage of Hugo page bundles. Be sure to read the [official Hugo docs](https://gohugo.io/content-management/organization/) for more information. It's important to have a firm grasp of how Hugo expects content to be organised as the theme is designed to take full advantage of Hugo page bundles. Be sure to read the [official Hugo docs](https://gohugo.io/content-management/organization/) for more information.
### Feature, cover and thumbnail images
The Congo theme supports displaying images on article listings and at the top of individual article pages. There are three types of images supported, each with their own use case: `feature`, `cover` and `thumb`.
In the example below, a cover and thumb image have been provided for the `first-post` article:
```shell
.
└── content
└── posts
├── _index.md
└── first-post
├── cover.jpg
├── index.md
└── thumb.jpg
```
The `thumb` image is used as the article thumbnail and will be displayed in article lists, and the `cover` image will be displayed at the top of the article content on individual article pages.
![A screenshot of an article with a thumbnail image](article-screenshot.jpg "This example shows an article with a thumbnail image.")
{{< alert >}}
In order to provide maximum performance, thumbnail images are automatically cropped and resized to a 4:3 ratio. Cover images will be automatically resized to fit their content, but any ratio is permitted.
{{< /alert >}}
The `feature` image is a special type, and when present, it will be used in place of _both_ the `thumb` and `cover` images. Feature images are also present in the article metadata, which is included when content is shared to third-party networks like Facebook and Twitter.
The theme will intelligently detect article images and automatically add them to your site. You don't have to refer to them in the front matter and simply need to place an appropriately named file within the page resources. If the term `feature`, `cover` or `thumb` is found anywhere in the image filename, then it will be used for that purpose.
The [Samples section]({{< ref "samples" >}}) provides a number of examples of these images (and you can view the [source code](https://github.com/jpanther/congo/tree/dev/exampleSite/content/samples) to see the file structure).
### Taxonomies
Congo is also flexible when it comes to taxonomies. Some people prefer to use _tags_ and _categories_ to group their content, others prefer to use _topics_. Congo is also flexible when it comes to taxonomies. Some people prefer to use _tags_ and _categories_ to group their content, others prefer to use _topics_.
Hugo defaults to using posts, tags and categories out of the box and this will work fine if that's what you want. If you wish to customise this, however, you can do so by creating a `taxonomies.toml` configuration file: Hugo defaults to using posts, tags and categories out of the box and this will work fine if that's what you want. If you wish to customise this, however, you can do so by creating a `taxonomies.toml` configuration file:

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

View File

@ -1,11 +1,11 @@
--- ---
title: "An External Article" title: "External Article - Why I switched to Fathom Analytics"
date: 2019-01-24 date: 2019-01-24
externalUrl: "https://jamespanther.com/writings/i-switched-from-google-analytics-to-fathom-analytics/" externalUrl: "https://jamespanther.com/writings/i-switched-from-google-analytics-to-fathom-analytics/"
summary: "The `externalUrl` front matter parameter can link to any URL." summary: "The `externalUrl` front matter parameter can link to any URL. This article looks just like any other, but will link to a post that is outside the Hugo project."
showReadingTime: false showReadingTime: false
_build: _build:
render: "false" render: "never"
list: "local" list: "local"
--- ---

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

View File

@ -1,4 +1,7 @@
{{ define "main" }} {{ define "main" }}
{{- $images := .Resources.ByType "image" }}
{{- $cover := $images.GetMatch "*cover*" }}
{{- $feature := $images.GetMatch "*feature*" | default $cover }}
<article> <article>
<header class="max-w-prose"> <header class="max-w-prose">
{{ if .Params.showBreadcrumbs | default (.Site.Params.article.showBreadcrumbs | default false) }} {{ if .Params.showBreadcrumbs | default (.Site.Params.article.showBreadcrumbs | default false) }}
@ -10,6 +13,17 @@
<div class="mt-8 mb-12 text-base text-neutral-500 dark:text-neutral-400 print:hidden"> <div class="mt-8 mb-12 text-base text-neutral-500 dark:text-neutral-400 print:hidden">
{{ partial "article-meta.html" (dict "context" . "scope" "single") }} {{ partial "article-meta.html" (dict "context" . "scope" "single") }}
</div> </div>
{{ with $feature }}
<img
class="mb-6 -mt-4 rounded-md"
srcset="
{{- (.Resize "330x").RelPermalink }} 330w,
{{- (.Resize "660x").RelPermalink }} 660w,
{{- (.Resize "1024x").RelPermalink }} 1024w,
{{- (.Resize "1320x").RelPermalink }} 2x"
src="{{ (.Resize "660x").RelPermalink }}"
/>
{{ end }}
</header> </header>
<section class="flex flex-col max-w-full mt-0 prose dark:prose-invert lg:flex-row"> <section class="flex flex-col max-w-full mt-0 prose dark:prose-invert lg:flex-row">
{{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in .TableOfContents "<ul") }} {{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in .TableOfContents "<ul") }}

View File

@ -1,44 +1,68 @@
<article> <article class="flex flex-row mt-6 max-w-prose">
<h3 class="flex items-center mt-6 text-xl font-semibold"> {{- $images := $.Resources.ByType "image" }}
{{ with .Params.externalUrl }} {{- $thumbnail := $images.GetMatch "*thumb*" }}
<div> {{- $feature := $images.GetMatch "*feature*" | default $thumbnail }}
{{- with $feature }}
<div class="flex-none pr-4 sm:pr-6 ">
<a
href="{{ with $.Params.externalUrl }}
{{ . }}
{{ else }}
{{ $.RelPermalink }}
{{ end }}"
>
<img
class="w-24 rounded-md sm:w-40"
srcset="
{{- (.Fill "160x120 smart").RelPermalink }} 160w,
{{- (.Fill "320x240 smart").RelPermalink }} 2x"
src="{{ (.Fill "160x120 smart").RelPermalink }}"
/>
</a>
</div>
{{- end }}
<div>
<h3 class="flex items-center text-xl font-semibold">
{{ with .Params.externalUrl }}
<div>
<a
class="text-neutral-800 decoration-primary-500 hover:underline hover:underline-offset-2 dark:text-neutral"
href="{{ . }}"
target="_blank"
rel="external"
>{{ $.Title | emojify }}</a
>
<span
class="text-xs align-top cursor-default text-neutral-400 dark:text-neutral-500"
title="{{ i18n "list.externalurl_title" }}"
>
<span class="rtl:hidden">&#8599;</span>
<span class="ltr:hidden">&#8598;</span>
</span>
</div>
{{ else }}
<a <a
class="text-neutral-800 decoration-primary-500 hover:underline hover:underline-offset-2 dark:text-neutral" class="text-neutral-800 decoration-primary-500 hover:underline hover:underline-offset-2 dark:text-neutral"
href="{{ . }}" href="{{ .RelPermalink }}"
target="_blank" >{{ .Title | emojify }}</a
rel="external"
>{{ $.Title | emojify }}</a
> >
<span {{ end }}
class="text-xs align-top cursor-default text-neutral-400 dark:text-neutral-500" {{ if and .Draft .Site.Params.article.showDraftLabel }}
title="{{ i18n "list.externalurl_title" }}" <div class=" ltr:ml-2 rtl:mr-2">
> {{ partial "badge.html" (i18n "article.draft" | emojify) }}
<span class="rtl:hidden">&#8599;</span> </div>
<span class="ltr:hidden">&#8598;</span> {{ end }}
</span> {{ if templates.Exists "partials/extend-article-link.html" }}
</div> {{ partial "extend-article-link.html" . }}
{{ else }} {{ end }}
<a </h3>
class="text-neutral-800 decoration-primary-500 hover:underline hover:underline-offset-2 dark:text-neutral" <div class="text-sm text-neutral-500 dark:text-neutral-400">
href="{{ .RelPermalink }}" {{ partial "article-meta.html" . }}
>{{ .Title | emojify }}</a
>
{{ end }}
{{ if and .Draft .Site.Params.article.showDraftLabel }}
<div class=" ltr:ml-2 rtl:mr-2">
{{ partial "badge.html" (i18n "article.draft" | emojify) }}
</div>
{{ end }}
{{ if templates.Exists "partials/extend-article-link.html" }}
{{ partial "extend-article-link.html" . }}
{{ end }}
</h3>
<div class="text-sm text-neutral-500 dark:text-neutral-400">
{{ partial "article-meta.html" . }}
</div>
{{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }}
<div class="py-1 prose dark:prose-invert">
{{ .Summary | emojify }}
</div> </div>
{{ end }} {{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }}
<div class="py-1 prose dark:prose-invert">
{{ .Summary | emojify }}
</div>
{{ end }}
</div>
</article> </article>

View File

@ -32,7 +32,6 @@
{{ $meta.Add "partials" (slice (partial "meta/edit.html" .)) }} {{ $meta.Add "partials" (slice (partial "meta/edit.html" .)) }}
{{ end }} {{ end }}
<div class="flex flex-row flex-wrap items-center"> <div class="flex flex-row flex-wrap items-center">
{{/* Output partials */}} {{/* Output partials */}}
{{ with ($meta.Get "partials") }} {{ with ($meta.Get "partials") }}