From 1ed9638c04e16dea78c747a56b78dd3050507754 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Tue, 31 Dec 2024 21:39:16 +0530 Subject: Refactor, use adapter-static --- package-lock.json | 11 +++++++++++ package.json | 1 + src/routes/+layout.ts | 1 + src/routes/+page.svelte | 12 +++++++----- svelte.config.js | 10 ++++++++-- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/routes/+layout.ts diff --git a/package-lock.json b/package-lock.json index 33812e7..b62f5be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ }, "devDependencies": { "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-static": "^3.0.8", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^4.0.0", "@types/luxon": "^3.4.2", @@ -765,6 +766,16 @@ "@sveltejs/kit": "^2.0.0" } }, + "node_modules/@sveltejs/adapter-static": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-3.0.8.tgz", + "integrity": "sha512-YaDrquRpZwfcXbnlDsSrBQNCChVOT9MGuSg+dMAyfsAa1SmiAhrA5jUYUiIMC59G92kIbY/AaQOWcBdq+lh+zg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@sveltejs/kit": "^2.0.0" + } + }, "node_modules/@sveltejs/kit": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.15.1.tgz", diff --git a/package.json b/package.json index 412af5f..d5e8ed8 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "devDependencies": { "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-static": "^3.0.8", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^4.0.0", "@types/luxon": "^3.4.2", diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..189f71e --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1 @@ +export const prerender = true; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3b2ef88..093347f 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,8 +2,8 @@ import { DateTime } from "luxon"; const getCurrentYear = () => DateTime.now().year; - const getRelative = (year) => - DateTime.local(year).toRelative({ locale: "en" }); + const getRelative = (year: number) => + DateTime.local(year).toRelative({ locale: "en" })!; let year = $state(getCurrentYear()); let sqrt = $derived(year ** 0.5); @@ -12,12 +12,14 @@ let nextSqrt = $derived(isPerfectSquare ? sqrt + 1 : Math.ceil(sqrt)); let last = $derived(lastSqrt ** 2); let next = $derived(nextSqrt ** 2); - let nextRelative = $state(getRelative(next)); + let nextRelative: string = $state(""); - setInterval(() => { + const update = () => { year = getCurrentYear(); nextRelative = getRelative(next); - }, 500); + }; + update(); + setInterval(update, 500);
diff --git a/svelte.config.js b/svelte.config.js index 1295460..ab2813c 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,4 +1,4 @@ -import adapter from '@sveltejs/adapter-auto'; +import adapter from '@sveltejs/adapter-static'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; /** @type {import('@sveltejs/kit').Config} */ @@ -11,7 +11,13 @@ const config = { // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. // If your environment is not supported, or you settled on a specific environment, switch out the adapter. // See https://svelte.dev/docs/kit/adapters for more information about adapters. - adapter: adapter() + adapter: adapter({ + pages: 'build', + assets: 'build', + fallback: undefined, + precompress: false, + strict: true + }) } }; -- cgit v1.2.3-57-g22cb