Эх сурвалжийг харах

feat: automatically generate website icons

See #1439
George Cushen 5 жил өмнө
parent
commit
ce75013228

+ 0 - 0
static/img/icon-512.png → assets/images/icon.png


+ 2 - 2
layouts/index.webmanifest

@@ -6,11 +6,11 @@
   "theme_color": "{{ $scr.Get "primary" }}",
   "background_color": "{{ $scr.Get "primary" }}",
   "icons": [{
-    "src": "../img/icon-192.png",
+    "src": "{{ (partial "functions/get_icon" 192).RelPermalink }}",
     "sizes": "192x192",
     "type": "image/png"
     }, {
-    "src": "../img/icon-512.png",
+    "src": "{{ (partial "functions/get_icon" 512).RelPermalink }}",
     "sizes": "512x512",
     "type": "image/png"
      }],

+ 7 - 0
layouts/partials/functions/get_icon.html

@@ -0,0 +1,7 @@
+{{/* Function to get website icon image. */}}
+{{/* Input: size (int) */}}
+{{/* Output: resource (obj) */}}
+
+{{ $icon := resources.GetMatch "images/icon.png" }}
+{{ $icon_resized := $icon.Fill (printf "%sx%s Center" (string .) (string .)) }}
+{{ return $icon_resized }}

+ 1 - 1
layouts/partials/jsonld/article.html

@@ -10,7 +10,7 @@
 
 {{ $author := partial "functions/get_author_name" $page }}
 {{ $publisher := site.Params.org_name | default site.Title }}
-{{ $logo_url := printf "img/%s" (site.Params.logo | default "icon-512.png") | absURL }}
+{{ $logo_url := (printf "img/%s" (site.Params.logo | absURL)) | default (partial "functions/get_icon" 512).Permalink }}
 
 <script type="application/ld+json">
 {

+ 3 - 3
layouts/partials/site_head.html

@@ -142,8 +142,8 @@
   {{ end }}
 
   <link rel="manifest" href="{{ "index.webmanifest" | relLangURL }}">
-  <link rel="icon" type="image/png" href="{{ "img/icon-32.png" | relURL }}">
-  <link rel="apple-touch-icon" type="image/png" href="{{ "img/icon-192.png" | relURL }}">
+  <link rel="icon" type="image/png" href="{{(partial "functions/get_icon" 32).RelPermalink}}">
+  <link rel="apple-touch-icon" type="image/png" href="{{(partial "functions/get_icon" 192).RelPermalink}}">
 
   <link rel="canonical" href="{{ .Permalink }}">
 
@@ -163,7 +163,7 @@
     {{ $og_image = (printf "img/%s" site.Params.avatar) | absURL }}
     {{ $twitter_card = "summary" }}
   {{ else }}
-    {{ $og_image = "img/icon-192.png" | absURL }}
+    {{ $og_image = (partial "functions/get_icon" 512).Permalink }}
     {{ $twitter_card = "summary" }}
   {{ end }}
   {{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}}

+ 2 - 2
layouts/slides/baseof.html

@@ -10,8 +10,8 @@
   <meta name="generator" content="Source Themes Academic {{ site.Data.academic.version }}">
 
   <link rel="manifest" href="{{ "index.webmanifest" | relLangURL }}">
-  <link rel="icon" type="image/png" href="{{ "img/icon-32.png" | relURL }}">
-  <link rel="apple-touch-icon" type="image/png" href="{{ "img/icon-192.png" | relURL }}">
+  <link rel="icon" type="image/png" href="{{(partial "functions/get_icon" 32).RelPermalink}}">
+  <link rel="apple-touch-icon" type="image/png" href="{{(partial "functions/get_icon" 192).RelPermalink}}">
 
   <link rel="canonical" href="{{ .Permalink }}">
 

BIN
static/img/icon-192.png


BIN
static/img/icon-32.png