Skip to content

Commit

Permalink
🚀 add pwd, lighthouse fixes (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath authored Apr 12, 2024
1 parent 66ad1bc commit 25eb351
Show file tree
Hide file tree
Showing 12 changed files with 1,147 additions and 78 deletions.
1,080 changes: 1,022 additions & 58 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion workspaces/website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ pnpm-debug.log*
bak
*.bak
cache
*.cache
*.cache
dev-dist
40 changes: 39 additions & 1 deletion workspaces/website/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import mdx from '@astrojs/mdx';
import partytown from '@astrojs/partytown';
import react from '@astrojs/react';
import lit from '@astrojs/lit';

import AstroPWA from '@vite-pwa/astro'
import sitemap from '@astrojs/sitemap';

// https://astro.build/config
export default defineConfig({
vite: {
logLevel: 'info',
define: {
__DATE__: `'${new Date().toISOString()}'`,
},
server: {
fs: {
// Allow serving files from hoisted root node_modules
allow: ['../..']
}
},
},
devToolbar: {
enabled: false
},
Expand All @@ -21,6 +33,32 @@ export default defineConfig({
},
site: 'https://scottnath.com',
integrations: [lit(), mdx(), sitemap(), react(),
AstroPWA({
mode: 'development',
base: '/',
scope: '/',
includeAssets: ['favicon.svg'],
registerType: 'autoUpdate',
manifest: {
name: 'Scott Nath PWA',
short_name: 'scottnath-pwa',
theme_color: '#0a0c10',
},
pwaAssets: {
config: true,
},
workbox: {
navigateFallback: '/',
globPatterns: ['**/*.{css,js,html,svg,png,ico,txt}'],
},
devOptions: {
enabled: true,
navigateFallbackAllowlist: [/^\//],
},
experimental: {
directoryAndTrailingSlashHandler: true,
}
}),
partytown({
// Adds dataLayer.push as a forwarding-event.
config: {
Expand Down
2 changes: 2 additions & 0 deletions workspaces/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@astrojs/partytown": "^2.0.4",
"@storybook/testing-library": "^0.2.2",
"@testing-library/react": "^15.0.0",
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/astro": "^0.3.1",
"@webcomponents/template-shadowroot": "^0.2.1",
"astro-icon": "^1.1.0",
"lit": "^3.1.2",
Expand Down
29 changes: 21 additions & 8 deletions workspaces/website/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions workspaces/website/pwa-assets.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
createAppleSplashScreens,
defineConfig,
minimal2023Preset,
} from '@vite-pwa/assets-generator/config'

export default defineConfig({
headLinkOptions: {
preset: '2023',
},
preset: {
...minimal2023Preset,
appleSplashScreens: createAppleSplashScreens({
padding: 0.3,
resizeOptions: { fit: 'contain', background: 'white' },
darkResizeOptions: { fit: 'contain', background: 'black' },
linkMediaOptions: {
log: true,
addMediaScreen: true,
xhtml: true,
},
}, ['iPad Air 9.7"']),
},
images: 'public/favicon.svg',
})
18 changes: 13 additions & 5 deletions workspaces/website/src/components/BaseHead.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { pwaInfo } from 'virtual:pwa-info';
import { pwaAssetsHead } from 'virtual:pwa-assets/head';
// Import the global.css file here so that it is included on
// all pages through the use of the <BaseHead /> component.
import '../styles/global.css';
Expand All @@ -15,11 +17,6 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const { title, description, image = PROFILE_PIC } = Astro.props;
---
<script defer data-domain="scottnath.com" src="https://plausible.io/js/script.js" type="text/partytown"></script>
<script defer data-domain="scottnath.com" src="https://plausible.io/js/script.outbound-links.js" type="text/partytown"></script>



<!-- Global Metadata -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
Expand Down Expand Up @@ -52,6 +49,17 @@ const { title, description, image = PROFILE_PIC } = Astro.props;
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />

<script defer data-domain="scottnath.com" src="https://plausible.io/js/script.js" type="text/partytown"></script>
<script defer data-domain="scottnath.com" src="https://plausible.io/js/script.outbound-links.js" type="text/partytown"></script>


{ pwaAssetsHead.themeColor && <meta name="theme-color" content={pwaAssetsHead.themeColor.content} /> }
{ pwaAssetsHead.links.map(link => (
<link {...link} />
)) }
{ pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} /> }
<script src="../pwa.js"></script>

<script>
// triggers a different favicon when the user switches tabs
const onVisibilityChange=()=>{
Expand Down
2 changes: 1 addition & 1 deletion workspaces/website/src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const navBorder = STRIPE_COLORS[0];

<WebRing />

<a href="/" class="you-still-here" title="You're still here? Go Home"><img src="/ferris-end-scene.avif" width="381" height="177" alt="You're still here? (Screen shot from Ferris Bueller's Day Off)" /></a>
<a href="/" class="you-still-here" title="You're still here? Go Home"><img src="/ferris-end-scene.avif" loading="lazy" width="381" height="177" alt="You're still here? (Screen shot from Ferris Bueller's Day Off)" /></a>
</footer>

<style define:vars={{ navBorder }}>
Expand Down
6 changes: 3 additions & 3 deletions workspaces/website/src/components/WebRing.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const navBorder = STRIPE_COLORS[0];
---

<div>
<h3>CS.Sjoy.lol <a href="https://cs.sjoy.lol">webring</a></h3>
<p>CS.Sjoy.lol <a href="https://cs.sjoy.lol">webring</a></p>
<div>
<a href="https://webri.ng/webring/cssjoy/previous?via=https://scottnath.com" aria-label="previous site">← Prev</a>
<a href="https://webri.ng/webring/cssjoy/random?via=https://scottnath.com" aria-label="random site">🎲</a>
Expand All @@ -14,13 +14,13 @@ const navBorder = STRIPE_COLORS[0];
</div>

<style define:vars={{ navBorder }}>
div:has(h3) {
div:has(p) {
display: inline-block;
border: 1px solid var(--navBorder);
padding: .5em 3em;
border-radius: 2em;

h3 {
p {
margin: 0;
padding-bottom: 1em;
}
Expand Down
2 changes: 2 additions & 0 deletions workspaces/website/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/vanillajs" />
11 changes: 11 additions & 0 deletions workspaces/website/src/pwa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { registerSW } from 'virtual:pwa-register'

registerSW({
immediate: true,
onRegisteredSW(swScriptUrl) {
console.log('SW registered: ', swScriptUrl)
},
onOfflineReady() {
console.log('PWA application ready to work offline')
},
})
7 changes: 6 additions & 1 deletion workspaces/website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
]
},
"jsx": "react-jsx",
"jsxImportSource": "react"
"jsxImportSource": "react",
"types": [
"astro/client",
"vite-plugin-pwa/vanillajs",
"vite-plugin-pwa/info"
]
}
}

0 comments on commit 25eb351

Please sign in to comment.