From 2d389272f1f0efc01f2a958f17e1ed73578d5917 Mon Sep 17 00:00:00 2001 From: Jeffrey Tse Date: Sat, 26 Aug 2023 16:28:58 +0800 Subject: feat: rich excerpt with image support (#125) --- _config.yml | 9 +++-- _includes/functions/get_article_excerpt.html | 2 +- _includes/views/pagination-item.html | 35 +++++++++++++++---- _includes/views/pagination.html | 6 +++- _sass/yat/_layout.scss | 50 +++++++++++++++++++++++++++ assets/images/default-image.jpeg | Bin 0 -> 4357 bytes 6 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 assets/images/default-image.jpeg diff --git a/_config.yml b/_config.yml index 9724c6b..12c16cd 100644 --- a/_config.yml +++ b/_config.yml @@ -182,8 +182,13 @@ yat: # heading_style: null # Custom heading style (e.g. "font-weight: bold; text-decoration: underline") # subheading_style: null # Custom subheading style (e.g. color: gold) -# Excerpt size setting -# excerpt_size: 350 +# Excerpt settings +# excerpt: +# default_image: /assets/images/default-image.jpeg # Default image when the image style is not none +# image_style: z # Image layout style (It's value could be none, left, right, top, z, z-reverse) +# image_width: 38.2% # Image default width +# image_height: 160px # Image default height +# text_size: 350 # Words default size # Pagination setting # paginate: 5 diff --git a/_includes/functions/get_article_excerpt.html b/_includes/functions/get_article_excerpt.html index 2868b8d..b34a13f 100644 --- a/_includes/functions/get_article_excerpt.html +++ b/_includes/functions/get_article_excerpt.html @@ -12,7 +12,7 @@ {% assign excerpt_size = include.params.excerpt_size %} {% else %} {% assign excerpt_size = excerpt_size - | default: site.excerpt_size + | default: site.excerpt.text_size | default: 350 %} {% endif %} diff --git a/_includes/views/pagination-item.html b/_includes/views/pagination-item.html index fff6541..791fcda 100644 --- a/_includes/views/pagination-item.html +++ b/_includes/views/pagination-item.html @@ -4,11 +4,29 @@ {% assign lang = post.lang %} {%- include functions.html func='get_reading_time' -%} {% assign reading_time = return %} + {%- include functions.html func='get_article_excerpt' -%} {% assign excerpt = return %} {%- assign post_url = post.url | relative_url -%} -
  • +{%- assign name = 'excerpt.image_width' -%} +{%- include functions.html func='get_value' -%} +{%- assign image_width = return | default: '38.2%' -%} + +{%- assign name = 'excerpt.image_height' -%} +{%- include functions.html func='get_value' -%} +{%- assign image_height = return | default: '160px' -%} + +{%- assign name = 'excerpt.default_image' -%} +{%- include functions.html func='get_value' -%} +{%- assign default_image = return -%} + +{%- assign post_image = post.banner.image + | default: post.banner + | default: default_image + | default: '/assets/images/default-image.jpeg' -%} + +
  • {{ post.title | escape }} @@ -22,11 +40,16 @@ {%- endif -%} {{ reading_time }} - -

    - {{ excerpt }} Read More -

    -
    +
    + {%- if post_image -%} + +
    +
    + {%- endif -%} + +

    {{ excerpt }} Read More

    +
    +