Răsfoiți Sursa

Merge pull request #216 from Troglodyne-Internet-Widgets/141

Add more comprehensive favicon handling
George S. Baugh 4 ani în urmă
părinte
comite
0aa13335e6

+ 1 - 1
Makefile

@@ -29,7 +29,7 @@ prereq-debian: prereq-debs prereq-perl prereq-frontend
 .PHONY: prereq-debs
 prereq-debs:
 	sudo apt-get update
-	sudo apt-get install -y sqlite3 libsqlite3-dev libdbd-sqlite3-perl cpanminus starman libxml2 curl                         \
+	sudo apt-get install -y sqlite3 libsqlite3-dev libdbd-sqlite3-perl cpanminus starman libxml2 curl                    \
 	    libtext-xslate-perl libplack-perl libconfig-tiny-perl libdatetime-format-http-perl libjson-maybexs-perl          \
 	    libuuid-tiny-perl libcapture-tiny-perl libconfig-simple-perl libdbi-perl libfile-slurper-perl libfile-touch-perl \
 	    libfile-copy-recursive-perl libxml-rss-perl libmodule-install-perl libio-string-perl                             \

+ 28 - 0
bin/favicon_mongler.pl

@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Cwd            ();
+use File::Basename ();
+use File::Which    ();
+
+die "Usage:\n    favicon_mongler.pl /path/to/favicon.svg" unless $ARGV[0];
+my $icon = Cwd::abs_path($ARGV[0]);
+my $bin = File::Which::which('inkscape');
+die "Please install inkscape" if !$bin;
+my $dir  = File::Basename::dirname($icon) || die "Can't figure out dir from $icon";
+
+my %files = (
+    180 => 'png',
+    192 => 'png',
+    512 => 'png',
+);
+foreach my $size ( sort { $b <=> $a } keys(%files) ) {
+    print "*** Generating ${size}x${size} .$files{$size} now... ***\n";
+    my @cmd = ( $bin, '-w', $size, '-h', $size, $icon, '-e', "$dir/favicon-$size.$files{$size}" );
+    system(@cmd) && die "Failed to run @cmd: $!";
+    print "*** Wrote $dir/favicon-$size.$files{$size} ***\n\n";
+}
+
+0;

+ 17 - 0
lib/Trog/Routes/JSON.pm

@@ -14,6 +14,11 @@ our %routes = (
         callback   => \&catalog,
         parameters => [],
     },
+    '/api/webmanifest' => {
+        method         => 'GET',
+        callback       => \&webmanifest,
+        parameters     => [],
+    },
 );
 
 my $contenttype = "Content-type:application/json;";
@@ -27,4 +32,16 @@ sub catalog ($query, $input, $=) {
     return [200,[$contenttype],[$enc->encode(\%rcopy)]];
 }
 
+sub webmanifest ($query, $input, $=) {
+    my $enc = JSON::MaybeXS->new( utf8 => 1 );
+    my %manifest = (
+        "icons" => [
+            { "src" => "$query->{theme_dir}/img/icon/favicon-192.png", "type" => "image/png", "sizes" => "192x192" },
+            { "src" => "$query->{theme_dir}/img/icon/favicon-512.png", "type" => "image/png", "sizes" => "512x512" },
+        ],
+    );
+
+    return [ 200, [$contenttype], [$enc->encode(\%manifest)] ];
+}
+
 1;

BIN
www/img/icon/favicon-180.png


BIN
www/img/icon/favicon-192.png


BIN
www/img/icon/favicon-512.png


+ 1 - 1
www/img/icon/tCMS.svg → www/img/icon/favicon.svg

@@ -15,7 +15,7 @@
    id="svg2"
    version="1.1"
    inkscape:version="0.91 r13725"
-   sodipodi:docname="tCMS.svg">
+   sodipodi:docname="favicon.svg">
   <defs
      id="defs4" />
   <sodipodi:namedview

+ 1 - 0
www/styles/login.css

@@ -6,6 +6,7 @@ body {
     margin: 0 auto;
     max-width: 25rem;
     color: white;
+    padding-top: 5rem;
 }
 #logo {
     display: block;

+ 4 - 1
www/templates/header.tx

@@ -3,7 +3,10 @@
     <head>
         <title><: $title :></title>
         <meta charset="utf-8" />
-        <link rel="icon" type="image/vnd.microsoft.icon" href="<: $theme_dir :>/img/icon/favicon.ico" />
+
+        <link rel="icon" type="image/svg+xml" href="<: $theme_dir :>/img/icon/favicon.svg">
+        <link rel="apple-touch-icon" href="<: $theme_dir :>/img/icon/favicon-180.png">
+        <link rel="manifest" href="/api/webmanifest">
 
         : if ($meta_desc) {
         <meta name="description" content="<: $meta_desc :>"/>

+ 1 - 1
www/templates/index.tx

@@ -40,6 +40,6 @@
 </div>
 : if ( $show_madeby ) {
 <a target="_blank" rel="noopener" class="trogged" href="https://tcms.troglodyne.net">
-<img src="/img/icon/tCMS.svg" style="height:2rem;" />
+<img src="/img/icon/favicon.svg" style="height:2rem;" />
 </a>
 : }

+ 1 - 1
www/templates/login.tx

@@ -1,7 +1,7 @@
 <div id="login">
     : include "jsalert.tx";
     <div>
-      <img id="logo" src="/img/icon/tCMS.svg" style="float:left" /><span style="font-family:courier;font-size:2rem;">CMS Login</span>
+      <img id="logo" src="/img/icon/favicon.svg" style="float:left" /><span style="font-family:courier;font-size:2rem;">CMS Login</span>
     </div>
     <div id="spacer" style="clear: both;"><br /></div>
     <form method="POST" action="/auth">