Skip to content

Commit

Permalink
favicon as image, not inline text
Browse files Browse the repository at this point in the history
  • Loading branch information
gugray committed Mar 23, 2024
1 parent 89cfeaf commit 90df364
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/admin-client/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ section {
.spacer { display: inline-block; width: 24px; }
#pnlImportErrors { white-space: pre-wrap; color: var(--clrError); }

#cnvIcon {
width: 256px; height: 256px; background-color: black;
}

@font-face {
font-display: swap;
font-family: 'Open Sans';
Expand Down
2 changes: 2 additions & 0 deletions src/admin-client/src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {feedUrls} from "./urls-debug.js";
import {initGenIcon} from "./gen-icon.js";

const elmTxtServerUrl = document.getElementById("txtServerUrl");
const elmTxtApiKey = document.getElementById("txtApiKey");
Expand Down Expand Up @@ -31,6 +32,7 @@ const feedImportStats = {

initParams();
initFeedImport();
initGenIcon();

function initParams() {
let stgs = null;
Expand Down
18 changes: 18 additions & 0 deletions src/admin-client/src/gen-icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let elmCanvas, elmLink;

export function initGenIcon() {

// Get elements
elmCanvas = document.getElementById("cnvIcon");
elmLink = document.getElementById("lnkSaveIcon");

// Draw parrot emoji
const ctx = elmCanvas.getContext("2d");
ctx.font = "192px Arial";
ctx.fillText("🦜", 36, 196);

// Get PNG image and add to link as data URL
const dataURL = elmCanvas.toDataURL("image/png");
elmLink.href = dataURL;
elmLink.download = "favicon-256.png";
}
7 changes: 7 additions & 0 deletions src/admin-client/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ <h2>Import feeds</h2>
<div id="pnlImportErrors"></div>
</section>

<section>
<h2>Generate favicon</h2>
<canvas width="256" height="256" id="cnvIcon"></canvas>
<br>
<a href="#" id="lnkSaveIcon">Save icon</a>
</section>

</body>
</html>
7 changes: 6 additions & 1 deletion src/server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

const assetsDir = "/assets"
const faviconName = "/favicon.ico"
const chunkSize = 65536
const strCacheControlHdr = "Cache-Control"

Expand Down Expand Up @@ -105,12 +106,16 @@ func handleStatic(logger shared.ILogger,

w.Header().Set(strCacheControlHdr, "max-age=31536000, immutable")

if !strings.HasPrefix(r.URL.Path, assetsDir) {
// We serve everything from /assets folder, EXCEPT favicon.ico, which gets special treatment
if r.URL.Path != faviconName && !strings.HasPrefix(r.URL.Path, assetsDir) {
return404()
return
}

fn := filepath.Join(wwwPathPrefx, r.URL.Path)
if r.URL.Path == faviconName {
fn = filepath.Join(wwwPathPrefx, assetsDir, r.URL.Path)
}
file, err := os.Open(fn)
if err != nil {
return404()
Expand Down
Binary file added src/server/www/assets/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/server/www/assets/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/server/www/assets/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions src/server/www/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<title>RSS Parrot</title>
<meta name="description" content="Home of RSS Parrot, a free Fediverse service that lets you turn Mastodon into an RSS or Atom feed reader." />
<meta name="og:description" content="Home of RSS Parrot, a free Fediverse service that lets you turn Mastodon into an RSS or Atom feed reader." />
<link rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🦜</text></svg>">
{{/* <link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png?ver={{ .Timestamp }}">*/}}
{{/* <link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png?ver={{ .Timestamp }}">*/}}
<link rel="stylesheet" href="/assets/style.css?ver={{ .Timestamp }}">
<script defer data-domain="rss-parrot.net" src="https://plausible.io/js/script.js"></script>
</head>
Expand Down

0 comments on commit 90df364

Please sign in to comment.