1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-18 21:45:31 -04:00

fix post titles not shrinking on mobile view, and clean up optimize-image partial

This commit is contained in:
2020-07-14 20:29:49 -04:00
parent f5a38a71e9
commit a583a3a0e7
10 changed files with 159 additions and 147 deletions

View File

@@ -1,25 +1,30 @@
{{/* Automatic resizing for HiDPI/retina images */}}
{{/* Automatic scaling/optimization of HiDPI/retina images */}}
{{/* start with the original image located in the requesting page's files */}}
{{ $original := .Page.Resources.GetMatch (.Get "src") }}
{{ .Scratch.Set "image" $original }}
{{ $image := $original }}
{{/* default to page width */}}
{{ $setWidth := .Site.Params.Theme.maxWidth }}
{{/* check if a specific size was requested via a parameter & use that instead */}}
{{ if .Get "width" }}
{{ $setWidth = (int (.Get "width")) }}
{{ end }}
{{/* we want HiDPI images, so make the real image size 2x the display size */}}
{{ $retinaWidth := (mul $setWidth 2) }}
{{ if gt $original.Width $retinaWidth -}}
{{ $finalWidth := (printf "%dx" $retinaWidth) }}
{{ .Scratch.Set "image" ($original.Resize $finalWidth) }}
{{/* only resize image if it's wider than the set width or page width (times 2) */}}
{{ if gt $original.Width $retinaWidth }}
{{/* let .Resize determine the height itself */}}
{{ $image = $original.Resize (printf "%dx" $retinaWidth) }}
{{ end }}
{{ $image := .Scratch.Get "image" }}
{{ $origRatio := (div (float $image.Height) $image.Width) }}
{{/* calculate the final dimensions for <img> to use, keeping original aspect ratio */}}
{{ $aspectRatio := (div (float $image.Height) $image.Width) }}
{{ $displayWidth := $setWidth }}
{{ $displayHeight := (math.Ceil (mul $origRatio $setWidth)) }}
{{ $displayHeight := (math.Ceil (mul $aspectRatio $setWidth)) }}
{{ return (dict "Permalink" $image.Permalink "Width" $displayWidth "Height" $displayHeight "MediaType" $image.MediaType) }}
{{/* kick back an object that acts mostly like a normal image! */}}
{{ return (dict "Permalink" $image.Permalink "Width" $displayWidth "Height" $displayHeight "MediaType" $image.MediaType "originalPermalink" $original.Permalink) }}

View File

@@ -7,7 +7,7 @@
{{- end -}}
{{- end -}}
{{/* Article image */}}
{{/* Page image (via frontmatter) */}}
{{- with .Params.image -}}
{{- with $.Page.Resources.GetMatch . -}}
{{- $.Scratch.Set "pageImage" . -}}

View File

@@ -1,7 +1,7 @@
<div class="embed gh-buttons"><p>
<a class="github-button" href="https://github.com/{{ .Get "username" }}/{{ .Get "repo" }}" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star {{ .Get "username" }}/{{ .Get "repo" }} on GitHub">Star</a>&nbsp;&nbsp;&nbsp;
<div class="embed gh-buttons">
<a class="github-button" href="https://github.com/{{ .Get "username" }}/{{ .Get "repo" }}" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star {{ .Get "username" }}/{{ .Get "repo" }} on GitHub">Star</a>
<a class="github-button" href="https://github.com/{{ .Get "username" }}/{{ .Get "repo" }}/issues" data-icon="octicon-issue-opened" data-size="large" data-show-count="true" aria-label="Issues for {{ .Get "username" }}/{{ .Get "repo" }} on GitHub">Issue</a>
</p></div>
</div>
{{- define "__shortcode_gh-buttons_js" }}
<script async defer src="https://buttons.github.io/buttons.js"></script>