chore: remove code duplication and clean up

This commit is contained in:
Cory Dransfeldt 2024-05-28 10:25:38 -07:00
parent 5a402c4def
commit 694dae0b06
No known key found for this signature in database
34 changed files with 246 additions and 292 deletions

View file

@ -1,6 +1,6 @@
{% assign media = data | normalizeMedia %}
{% assign media = data.items | default: data | normalizeMedia %}
<div class="media-grid {% if shape == 'square' %}square{% else %}vertical{% endif %}">
{% for item in media limit: count %}
{% for item in media limit: count | default: media.size %}
{% assign alt = item.alt | strip | escape %}
<a href="{{ item.url | stripUtm }}" title="{{ alt }}">
<div class="item-wrapper shadow">
@ -8,21 +8,22 @@
{% if item.title %}
<div class="header">{{ item.title }}</div>
{% endif %}
{% if item.subtext %}
<div class="subheader">
{{ item.subtext }}
</div>
{% if item.plays %}
<div class="subheader">{{ item.plays }} plays</div>
{% elsif item.subtext %}
<div class="subheader">{{ item.subtext }}</div>
{% endif %}
</div>
{%- capture loadingStrategy -%}
{%- if loading -%}{{ loading }}{%- else -%}lazy{%- endif -%}
{%- endcapture -%}
{% assign loadingStrategy = loading | default: 'lazy' %}
{% if shape == 'square' %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=240&h=240&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="240" height="240" />
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=240&h=240&fm=webp&q=85" alt="{{ alt }}" loading="{{ loadingStrategy }}" decoding="async" width="240" height="240" />
{% else %}
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=200&h=307&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="{{ loadingStrategy }}" decoding="async" width="200" height="307" />
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=200&h=307&fm=webp&q=85" alt="{{ alt }}" loading="{{ loadingStrategy }}" decoding="async" width="200" height="307" />
{% endif %}
</div>
</a>
{% endfor %}
</div>
</div>
{% unless count %}
{% render "partials/widgets/paginator.liquid", pagination:data %}
{% endunless %}

View file

@ -0,0 +1,22 @@
<div class="music-chart">
{% assign items = data.items | default: data %}
{% for item in items limit: count | default: items.size %}
{%- assign playTotal = playTotal | default: mostPlayed -%}
{%- assign percentage = item.plays | calculatePlayPercentage: playTotal -%}
<div class="item">
<div class="presentation">
<div class="count">{{ item.rank | formatNumber }}.</div>
<div class="info">
<div class="title">
<a href="{{ item.url }}">{{ item.title }}</a>
</div>
<div class="subtext">{{ item.artist }} • {{ item.plays }} plays</div>
</div>
</div>
{% render "partials/media/progress-bar.liquid", percentage:percentage %}
</div>
{% endfor %}
</div>
{% unless count %}
{% render "partials/widgets/paginator.liquid", pagination:data %}
{% endunless %}

View file

@ -1,19 +0,0 @@
<hr class="large-spacing" />
<div class="music-chart">
{% for item in data.items %}
{%- assign percentage = item.plays | calculatePlayPercentage:playTotal -%}
<div class="item">
<div class="presentation">
<div class="count">{{ item.rank | formatNumber }}.</div>
<div class="info">
<div class="title">
<a href="{{ item.url }}">{{ item.title }}</a>
</div>
<div class="subtext">{{ item.artist }} • {{ item.plays }} plays</div>
</div>
</div>
{% render "partials/media/progress-bar.liquid", percentage:percentage %}
</div>
{% endfor %}
</div>
{% render "partials/widgets/paginator.liquid", pagination:data %}

View file

@ -1,16 +0,0 @@
<hr class="large-spacing" />
<div class="media-grid square">
{% for item in data.items %}
{% assign alt = item.alt | strip | escape %}
<a href="{{ item.url | stripUtm }}" title="{{ alt }}">
<div class="item-wrapper shadow">
<div class="meta-text">
<div class="header">{{ item.title }}</div>
<div class="subheader">{{ item.plays }} plays</div>
</div>
<img src="https://coryd.dev/.netlify/images/?url={{ item.image }}&fit=cover&w=240&h=240&fm=webp&q=85"{% if alt %} alt="{{ alt }}"{% endif %} loading="eager" decoding="async" width="240" height="240" />
</div>
</a>
{% endfor %}
</div>
{% render "partials/widgets/paginator.liquid", pagination:data %}

View file

@ -1,4 +1,3 @@
{% if data.size > 0 %}
<div class="music-chart">
{% for item in data limit: 10 %}
{% capture alt %}{{ item.title | escape }} by {{ item.artist }}{% endcapture %}
@ -17,5 +16,4 @@
</div>
</div>
{% endfor %}
</div>
{% endif %}
</div>

View file

@ -1,21 +1,19 @@
{% if albumReleases.size > 0 %}
<h2 id="album-releases" class="section-header flex-centered">
{% tablericon "calendar-time" "Anticipated albums" %}
Anticipated albums
</h2>
<ul class="link-list">
{% for album in albumReleases %}
<li>
<strong>{{ album.date }}: </strong>
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
{{ album.title }}
</a>
<span> by </span>
<a href="{{ album.artist_url }}">
{{ album.artist }}
</a>
<span> • <a href="https://coryd.dev/music/genres/{{ album.genre | slugify | downcase }}">{{ album.genre }}</a></span>
</li>
{% endfor %}
</ul>
{% endif %}
<h2 id="album-releases" class="section-header flex-centered">
{% tablericon "calendar-time" "Anticipated albums" %}
Anticipated albums
</h2>
<ul class="link-list">
{% for album in albumReleases %}
<li>
<strong>{{ album.date }}: </strong>
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
{{ album.title }}
</a>
<span> by </span>
<a href="{{ album.artist_url }}">
{{ album.artist }}
</a>
<span> • <a href="https://coryd.dev/music/genres/{{ album.genre | slugify | downcase }}">{{ album.genre }}</a></span>
</li>
{% endfor %}
</ul>

View file

@ -1,19 +0,0 @@
{% if data.size > 0 %}
<div class="music-chart">
{% for item in data limit: 10 %}
{%- assign percentage = item.plays | calculatePlayPercentage: mostPlayed -%}
<div class="item">
<div class="presentation">
<div class="count">{{ item.rank | formatNumber }}.</div>
<div class="info">
<div class="title">
<a href="{{ item.url }}">{{ item.title }}</a>
</div>
<div class="subtext">{{ item.artist }} • {{ item.plays }} plays</div>
</div>
</div>
{% render "partials/media/progress-bar.liquid", percentage:percentage %}
</div>
{% endfor %}
</div>
{% endif %}

View file

@ -1,5 +1,5 @@
{% if percentage %}
<div class="progress-bar__wrapper">
<div class="progress-bar-wrapper">
<div style="width:{{ percentage }}" class="progress-bar"></div>
</div>
{% endif %}

View file

@ -1,27 +0,0 @@
<div class="watching grid">
{% for item in data.items %}
{% capture alt %}{{ item.title | escape }} ({{ item.year }}){% endcapture %}
<a href="{{ item.url }}">
<div class="watching item shadow">
<div class="meta-text">
{% if item.type == 'movie' %}
<div class="header">{{ item.title }}</div>
<div class="subheader flex-centered gap-xs">
{{ item.year }}
{% if rating and item.rating %}
<span class="rating"> ({{ item.rating }})</span>
{% endif %}
</div>
{% else %}
<div class="header">{{ item.name }}</div>
{% endif %}
</div>
{%- capture loadingStrategy -%}
{%- if loading -%}{{ loading }}{%- else -%}lazy{%- endif -%}
{%- endcapture -%}
<img src="https://coryd.dev/.netlify/images/?url={{ item.backdrop }}&fit=cover&w=256&h=144&fm=webp&q=85" alt="{{ alt }}" loading="{{ loadingStrategy }}" decoding="async" width="256" height="144" />
</div>
</a>
{% endfor %}
</div>
{% render "partials/widgets/paginator.liquid", pagination:data %}

View file

@ -1,26 +1,30 @@
<div class="watching grid">
{% for media in mediaItems limit: count %}
{% capture alt %}{{ media.title | escape }} ({{ media.year }}){% endcapture %}
<a href="{{ media.url }}">
{% assign items = data.items | default: mediaItems %}
{% for item in items limit: count %}
{% capture alt %}{{ item.title | escape }} ({{ item.year }}){% endcapture %}
<a href="{{ item.url }}">
<div class="watching item shadow">
<div class="meta-text">
{% if media.type == 'movie' %}
<div class="header">{{ media.title }}</div>
{% if item.type == 'movie' %}
<div class="header">{{ item.title }}</div>
<div class="subheader flex-centered gap-xs">
{{ media.year }}
{% if rating and media.rating %}
<span class="rating"> ({{ media.rating }})</span>
{{ item.year }}
{% if rating and item.rating %}
<span class="rating"> ({{ item.rating }})</span>
{% endif %}
</div>
{% else %}
<div class="header">{{ media.name }}</div>
<div class="header">{{ item.name }}</div>
{% endif %}
</div>
{%- capture loadingStrategy -%}
{%- if loading -%}{{ loading }}{%- else -%}lazy{%- endif -%}
{%- endcapture -%}
<img src="https://coryd.dev/.netlify/images/?url={{ media.backdrop }}&fit=cover&w=256&h=144&fm=webp&q=85" alt="{{ alt }}" loading="{{ loadingStrategy }}" decoding="async" width="256" height="144" />
<img src="https://coryd.dev/.netlify/images/?url={{ item.backdrop }}&fit=cover&w=256&h=144&fm=webp&q=85" alt="{{ alt }}" loading="{{ loadingStrategy }}" decoding="async" width="256" height="144" />
</div>
</a>
{% endfor %}
</div>
</div>
{% unless count %}
{% render "partials/widgets/paginator.liquid", pagination:data %}
{% endunless %}