Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favicons #6

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ node_modules
.vercel
.DS_Store
.sst
.tmp
.tmp

app/components/favicon/apple-touch-icon.png
app/components/favicon/icon-192.png
app/components/favicon/icon-512.png
app/components/favicon/favicon.ico
public/favicon.ico
25 changes: 25 additions & 0 deletions app/components/favicon/FavIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Based upon https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs

import appleTouchIcon from "./apple-touch-icon.png"
import favIcon from "./favicon.ico"
import icon from "./icon.svg"
import icon192 from "./icon-192.png"
import icon512 from "./icon-512.png"

export function FavIcon() {
return (
<>
<link rel="icon" href={favIcon} sizes="32x32" />
<link rel="icon" href={icon} type="image/svg+xml" />
<link rel="apple-touch-icon" href={appleTouchIcon} />
<link rel="manifest" href="/manifest.webmanifest" />
</>
)
}

export function webmanifestIcons() {
return {
icon192,
icon512
}
}
1 change: 1 addition & 0 deletions app/components/favicon/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 2 additions & 30 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type { PropsWithChildren } from "react"

import { Body } from "./components/body/Body"
import { FavIcon } from "./components/favicon/FavIcon"
import { Footer } from "./components/footer/Footer"
import { Header } from "./components/header/Header"
import { Main } from "./components/main/Main"
Expand All @@ -22,36 +23,7 @@ export function Layout({ children }: PropsWithChildren) {
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#5bbad5"
/>
<link rel="shortcut icon" href="/favicons/favicon.ico" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta
name="msapplication-config"
content="/favicons/browserconfig.xml"
/>
<meta name="theme-color" content="#ffffff" />
<FavIcon />
</head>
<Body>
<Header />
Expand Down
22 changes: 22 additions & 0 deletions app/routes/[manifest.webmanifest].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Create webmanifest file with processed icons
import { webmanifestIcons } from "~/components/favicon/FavIcon"

export const loader = () => {
const icons = webmanifestIcons()

// handle "GET" request
// set up our text content that will be returned in the response
const webmanifest = JSON.stringify({
icons: [
{ src: icons.icon192, type: "image/png", sizes: "192x192" },
{ src: icons.icon512, type: "image/png", sizes: "512x512" }
]
})
// return the text content, a status 200 success response, and set the content type to text/plain
return new Response(webmanifest, {
status: 200,
headers: {
"Content-Type": "application/json"
}
})
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test:lint": "eslint .",
"test:json-schema": "pnpm create:json-schema ; pnpx ajv-cli -s ./.tmp/data.schema.json -d 'app/data/*.json'",
"create:json-schema": "mkdir -p ./.tmp && pnpx typescript-json-schema app/data/data.types.ts ProjectsType -o ./.tmp/data.schema.json --skipLibCheck --ignoreErrors",
"create:favicons": "pnpx tsx tools/favicon-generator/favicon-generator.ts",
"fix": "eslint --fix .; prettier --write .",
"format": "prettier --write .",
"test:check-format": "prettier --check .",
Expand All @@ -19,7 +20,8 @@
"update:latest": "ncu --deep --upgrade --interactive",
"update:minor": "ncu --deep --upgrade --interactive --target minor",
"update:pnpm": "corepack up",
"deploy:prod": "sst deploy --stage production"
"deploy:prod": "sst deploy --stage production",
"prepare": "pnpm create:favicons"
},
"dependencies": {
"@effective/shadow": "^1.0.1",
Expand All @@ -37,14 +39,17 @@
"@effective/eslint-config": "^5.4.7",
"@remix-run/dev": "^2.10.3",
"@storybook/react": "^8.2.6",
"@tsconfig/node20": "^20.1.4",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vanilla-extract/css": "^1.15.3",
"@vanilla-extract/vite-plugin": "^4.0.13",
"@vercel/remix": "^2.10.3",
"eslint": "^8.57.0",
"ico-endec": "^0.1.6",
"npm-check-updates": "^16.14.20",
"prettier": "^3.3.3",
"sharp": "^0.33.4",
"sst": "ion",
"svgo": "^3.3.2",
"typescript": "^5.5.4",
Expand Down
Loading
Loading