From 05ab78c861aa14e6087c90d69ae2725500dad2b1 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sat, 26 Oct 2024 08:56:19 -0700 Subject: [PATCH] chore: dry up templates --- config/filters/general.js | 4 + package-lock.json | 4 +- package.json | 2 +- .../partials/blocks/associated-media.liquid | 137 +++++++----------- src/includes/partials/blocks/index.liquid | 31 ++-- .../partials/blocks/mastodon-post.liquid | 4 +- src/includes/partials/footer.liquid | 6 +- src/includes/partials/media/grid.liquid | 66 ++++----- .../partials/media/music/chart.liquid | 8 +- .../partials/media/watching/hero.liquid | 18 +-- src/includes/partials/metadata.liquid | 21 ++- src/includes/partials/nav/link.liquid | 27 ++-- src/includes/partials/nav/menu.liquid | 2 +- src/pages/posts/post.html | 13 +- 14 files changed, 147 insertions(+), 196 deletions(-) diff --git a/config/filters/general.js b/config/filters/general.js index 47ae0bc5..d234ceed 100644 --- a/config/filters/general.js +++ b/config/filters/general.js @@ -15,4 +15,8 @@ export default { ellipsis: "...", }), shuffleArray, + pluralize: (count, string) => { + if (count === 1) return string; + return `${string}s`; + }, }; diff --git a/package-lock.json b/package-lock.json index 424e382d..4f674e29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "1.8.2", + "version": "1.8.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "1.8.2", + "version": "1.8.3", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.5.0", diff --git a/package.json b/package.json index 535ae42c..b0a778b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "1.8.2", + "version": "1.8.3", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "engines": { diff --git a/src/includes/partials/blocks/associated-media.liquid b/src/includes/partials/blocks/associated-media.liquid index 65b4628a..24ea252d 100644 --- a/src/includes/partials/blocks/associated-media.liquid +++ b/src/includes/partials/blocks/associated-media.liquid @@ -1,81 +1,56 @@ -{% if artists or books or genres or movies or posts or shows %}
{% endif %} - {% comment %} render related artists {% endcomment %} - {%- if artists -%} -

- {% tablericon "headphones" %} - Related artist(s) -

- - {%- endif -%} - {% comment %} render related books {% endcomment %} - {%- if books -%} -

- {% tablericon "books" %} - Related book(s) -

- - {%- endif -%} - {% comment %} render related genres {% endcomment %} - {%- if genres -%} -

- {% tablericon "headphones" %} - Related genre(s) -

- - {%- endif -%} - {% comment %} render related movies {% endcomment %} - {%- if movies -%} -

- {% tablericon "movie" %} - Related movie(s) -

- - {%- endif -%} - {% comment %} render related posts {% endcomment %} - {%- if posts -%} -

- {% tablericon "article" %} - Related post(s) -

- - {%- endif -%} - {% comment %} render related shows {% endcomment %} - {%- if shows -%} -

- {% tablericon "device-tv-old" %} - Related show(s) -

- - {%- endif -%} -{% if artists or books or genres or movies or posts or shows %}
{% endif %} \ No newline at end of file +{% assign media = artists | concat: books | concat: genres | concat: movies | concat: posts | concat: shows %} + +{% if media.size > 0 %} +
+ {% assign sections = + "artists:headphones:music:Related artist(s)," | append: + "books:books:books:Related book(s)," | append: + "genres:headphones:music:Related genre(s)," | append: + "movies:movie:movies:Related movie(s)," | append: + "posts:article:article:Related post(s)," | append: + "shows:device-tv-old:tv:Related show(s)" + | split: "," %} + + {% for section in sections %} + {% assign parts = section | split: ":" %} + {% assign key = parts[0] %} + {% assign icon = parts[1] %} + {% assign css_class = parts[2] %} + {% assign label = parts[3] %} + + {% case key %} + {% when "artists" %} {% assign items = artists %} + {% when "books" %} {% assign items = books %} + {% when "genres" %} {% assign items = genres %} + {% when "movies" %} {% assign items = movies %} + {% when "posts" %} {% assign items = posts %} + {% when "shows" %} {% assign items = shows %} + {% endcase %} + + {% if items and items.size > 0 %} +

+ {% tablericon icon %} + {{ label }} +

+ + {% endif %} + {% endfor %} +
+{% endif %} \ No newline at end of file diff --git a/src/includes/partials/blocks/index.liquid b/src/includes/partials/blocks/index.liquid index 1de6047f..b4df248b 100644 --- a/src/includes/partials/blocks/index.liquid +++ b/src/includes/partials/blocks/index.liquid @@ -1,17 +1,18 @@ {%- for block in blocks -%} - {%- if block.type == 'youtube_player' -%} - {% render "partials/blocks/youtube-player.liquid", url:block.url %} - {%- elsif block.type == 'github_banner' -%} - {% render "partials/blocks/banners/github.liquid", url:block.url %} - {%- elsif block.type == 'npm_banner' -%} - {% render "partials/blocks/banners/npm.liquid", url:block.url, command:block.command %} - {%- elsif block.type == 'rss_banner' -%} - {% render "partials/blocks/banners/rss.liquid", url:block.url, text:block.text %} - {%- elsif block.type == 'hero' -%} - {% render "partials/blocks/hero.liquid", globals:globals, image:block.image, alt:block.alt %} - {%- elsif block.type == 'markdown' -%} - {{ block.text | markdown }} - {%- elsif block.type == 'divider' -%} - {{ block.markup | markdown }} - {%- endif -%} + {%- case block.type -%} + {%- when 'youtube_player' -%} + {% render "partials/blocks/youtube-player.liquid", url: block.url %} + {%- when 'github_banner' -%} + {% render "partials/blocks/banners/github.liquid", url: block.url %} + {%- when 'npm_banner' -%} + {% render "partials/blocks/banners/npm.liquid", url: block.url, command: block.command %} + {%- when 'rss_banner' -%} + {% render "partials/blocks/banners/rss.liquid", url: block.url, text: block.text %} + {%- when 'hero' -%} + {% render "partials/blocks/hero.liquid", globals: globals, image: block.image, alt: block.alt %} + {%- when 'markdown' -%} + {{ block.text | markdown }} + {%- when 'divider' -%} + {{ block.markup | markdown }} + {%- endcase -%} {%- endfor -%} \ No newline at end of file diff --git a/src/includes/partials/blocks/mastodon-post.liquid b/src/includes/partials/blocks/mastodon-post.liquid index 25879b76..23a4dce4 100644 --- a/src/includes/partials/blocks/mastodon-post.liquid +++ b/src/includes/partials/blocks/mastodon-post.liquid @@ -15,9 +15,7 @@ - - Discuss on Mastodon - + Discuss on Mastodon {%- endif -%} \ No newline at end of file diff --git a/src/includes/partials/footer.liquid b/src/includes/partials/footer.liquid index a0456cba..a83ae04d 100644 --- a/src/includes/partials/footer.liquid +++ b/src/includes/partials/footer.liquid @@ -4,13 +4,13 @@ {%- endif -%} \ No newline at end of file diff --git a/src/includes/partials/media/grid.liquid b/src/includes/partials/media/grid.liquid index 5e51b6d5..fb56060f 100644 --- a/src/includes/partials/media/grid.liquid +++ b/src/includes/partials/media/grid.liquid @@ -1,62 +1,50 @@ {%- assign pageCount = pagination.pages.size | default: 0 -%} {%- assign hidePagination = pageCount <= 1 -%} -
+ {%- unless hidePagination -%} - {% render "partials/nav/paginator.liquid", pagination:pagination %} + {% render "partials/nav/paginator.liquid", pagination: pagination %} {%- endunless -%} \ No newline at end of file diff --git a/src/includes/partials/media/music/chart.liquid b/src/includes/partials/media/music/chart.liquid index 23dd775e..ac478684 100644 --- a/src/includes/partials/media/music/chart.liquid +++ b/src/includes/partials/media/music/chart.liquid @@ -6,13 +6,7 @@
{{ item.chart.title }} - {%- capture playsLabel -%} - {%- if item.chart.plays > 1 -%} - plays - {%- else -%} - play - {%- endif -%} - {%- endcapture -%} + {%- assign playsLabel = item.chart.plays | pluralize:"play" -%} {{ item.chart.artist }} {{ item.chart.plays }} {{ playsLabel }}
diff --git a/src/includes/partials/media/watching/hero.liquid b/src/includes/partials/media/watching/hero.liquid index 2d16c5d1..8b55c84e 100644 --- a/src/includes/partials/media/watching/hero.liquid +++ b/src/includes/partials/media/watching/hero.liquid @@ -9,22 +9,6 @@ ({{ movie.year }})
- + {% render "partials/blocks/hero.liquid", globals:globals, image:movie.backdrop, alt:movie.title %} \ No newline at end of file diff --git a/src/includes/partials/metadata.liquid b/src/includes/partials/metadata.liquid index 995e8471..fbbba4ae 100644 --- a/src/includes/partials/metadata.liquid +++ b/src/includes/partials/metadata.liquid @@ -6,27 +6,26 @@ {%- when 'blog' -%} {%- assign pageTitle = post.title -%} {%- assign pageDescription = post.description | markdown | strip_html | default: globals.site_description -%} - {%- when 'music-index' -%} - {%- assign pageTitle = 'Music / ' | append: globals.site_name -%} - {%- when 'music-period' -%} - {%- assign pageTitle = 'Music / ' | append: page.title | append: ' / ' | append: globals.site_name -%} + {%- when 'books' or 'books-year' -%} + {%- assign featuredBook = books.all | filterBooksByStatus: 'started' | reverse | first -%} + {%- assign ogImage = globals.cdn_url | append: featuredBook.grid.image -%} + {%- when 'books-year' -%} + {%- assign pageTitle = year.value | append: ' / Books / ' | append: globals.site_name -%} {%- when 'music' -%} {%- assign ogImage = globals.cdn_url | append: page.image -%} {%- when 'music-index' -%} + {%- assign pageTitle = 'Music / ' | append: globals.site_name -%} {%- assign ogImage = globals.cdn_url | append: music.week.artists[0].grid.image -%} + {%- when 'music-period' -%} + {%- assign pageTitle = 'Music / ' | append: page.title | append: ' / ' | append: globals.site_name -%} + {%- when 'page' -%} + {%- assign pageTitle = page.title | append: ' / ' | append: globals.site_name -%} {%- when 'watching' or 'favorite-movies' -%} {%- assign featuredMovie = movies.recentlyWatched | first -%} {%- assign ogImage = globals.cdn_url | append: featuredMovie.grid.backdrop -%} {%- when 'watching-shows' or 'favorite-shows' -%} {%- assign featuredShow = tv.recentlyWatched | first -%} {%- assign ogImage = globals.cdn_url | append: featuredShow.grid.backdrop -%} - {%- when 'books' or 'books-year' -%} - {%- assign featuredBook = books.all | filterBooksByStatus: 'started' | reverse | first -%} - {%- assign ogImage = globals.cdn_url | append: featuredBook.grid.image -%} - {%- when 'books-year' -%} - {%- assign pageTitle = year.value | append: ' / Books / ' | append: globals.site_name -%} - {%- when 'page' -%} - {%- assign pageTitle = page.title | append: ' / ' | append: globals.site_name -%} {%- else -%} {%- assign pageTitle = globals.site_name -%} {%- endcase -%} diff --git a/src/includes/partials/nav/link.liquid b/src/includes/partials/nav/link.liquid index cfd8c7f3..812ba8d5 100644 --- a/src/includes/partials/nav/link.liquid +++ b/src/includes/partials/nav/link.liquid @@ -1,21 +1,26 @@ -{%- assign categoryUrl = url | downcase -%} +{%- assign categoryUrl = link.permalink | downcase -%} {%- assign isHttp = categoryUrl contains "http" -%} {%- if categoryUrl | isLinkActive: page.url -%} - - {%- if icon -%} - {% tablericon icon %} - {{ title }} + + {%- if link.icon -%} + {% tablericon link.icon %} + {{ link.title }} {%- else -%} - {{ title }} + {{ link.title }} {%- endif -%} {%- else -%} - - {%- if icon -%} - {% tablericon icon %} - {{ title }} + + {%- if link.icon -%} + {% tablericon link.icon %} + {{ link.title }} {%- else -%} - {{ title }} + {{ link.title }} {%- endif -%} {%- endif -%} \ No newline at end of file diff --git a/src/includes/partials/nav/menu.liquid b/src/includes/partials/nav/menu.liquid index 7579c9ae..31c6a2be 100644 --- a/src/includes/partials/nav/menu.liquid +++ b/src/includes/partials/nav/menu.liquid @@ -6,7 +6,7 @@ {% render "partials/nav/theme-toggle.liquid" %} diff --git a/src/pages/posts/post.html b/src/pages/posts/post.html index c1ec50c2..4dfe7fa7 100644 --- a/src/pages/posts/post.html +++ b/src/pages/posts/post.html @@ -42,11 +42,14 @@ schema: blog {{ post.content | markdown }} {% render "partials/blocks/index.liquid", blocks:post.blocks %} {% render "partials/blocks/mastodon-post.liquid", post:post.mastodon_url %} - {% render "partials/blocks/associated-media.liquid", artists:post.artists %} - {% render "partials/blocks/associated-media.liquid", books:post.books %} - {% render "partials/blocks/associated-media.liquid", genres:post.genres %} - {% render "partials/blocks/associated-media.liquid", movie:post.movies %} - {% render "partials/blocks/associated-media.liquid", shows:post.shows %} + {% render "partials/blocks/associated-media.liquid", + artists: post.artists, + books: post.books, + genres: post.genres, + movies: post.movies, + posts: post.posts, + shows: post.shows + %} {% render "partials/blocks/banners/coffee.liquid" %} \ No newline at end of file