Skip to content

Commit

Permalink
CHORE: Add sveltekit sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mazipan committed Feb 20, 2024
1 parent 1cfce8a commit 086d19a
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"prepare": "svelte-kit sync",
"dev": "vite dev",
"build": "vite build && pnpm run make:timestamp && pnpm run make:sitemap",
"build": "svelte-kit sync && vite build && pnpm run make:timestamp && pnpm run make:sitemap",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand Down
2 changes: 1 addition & 1 deletion src/data/surah-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type SurahInfoItem = {
latin: string;
ayah_count: number;
index: number;
revelation?: number;
revelation?: 1 | 2;
};

export type SurahInfoPage = {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export const META_TITLE_SURAH = (name: string) =>
`Qur'an Surat ${name} | ${TITLE_CONSTANTS.TITLE_META}`;
export const META_DESC_SURAH = (name: string) => `Qur'an Surat ${name} ${postfix(true)}`;

export const META_TITLE_AYAH = (verseid: string, surahid: string, name: string, translation: string) =>
export const META_TITLE_AYAH = (verseid: string, surahid?: string, name?: string, translation?: string) =>
`QS ${surahid}:${verseid}, Surat ${name} - ${translation}, Ayat ${verseid || 1} | ${TITLE_CONSTANTS.TITLE_META}`;
export const META_DESC_AYAH = (verseid: string, surahid: string, name: string, translation: string) =>
export const META_DESC_AYAH = (verseid: string, surahid?: string, name?: string, translation?: string) =>
`Ayat ${verseid || 1} dari Surat ${name} - ${translation} - (QS ${surahid}:${verseid}) ${postfix(true)}`;

export type SeoArgs = {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/views/SurahPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import type { SurahInfoPage } from '$data/surah-info';
import { onMount } from 'svelte';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export let data: any;
let surahid = data?.surahid;
let surahData = data?.surahData;
let surahInfo = data?.surahInfo as SurahInfoPage;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let timeout: any = null
onMount(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/views/VersePage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
{@html serializeSchema(
getJsonLdArticle({
slug: `/surah/${surahid}/${verseid}`,
title: META_TITLE_AYAH(verseid, surahInfo.current.latin),
title: META_TITLE_AYAH(verseid, surahid, surahInfo.current.latin, surahInfo.current.translation),
cover: 'meta-image.png',
desc: META_DESC_AYAH(verseid, surahInfo.current.latin)
desc: META_DESC_AYAH(verseid, surahid, surahInfo.current.latin, surahInfo.current.translation)
})
)}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/views/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function loadVerseData(surahid: string, verseid: string) {
};
}
} catch (error) {
console.error("Error loading data in route '/[surahid]/[verseid]'", params, error);
console.error("Error loading data in route '/[surahid]/[verseid]'", error);
}
return {
surahid: surahid,
Expand Down
4 changes: 3 additions & 1 deletion src/routes/[surahid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import SurahPage from '$lib/views/SurahPage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

<SurahPage {data} />
<SurahPage data={data} />
2 changes: 2 additions & 0 deletions src/routes/[surahid]/[verseid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import VersePage from '$lib/views/VersePage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/routes/all-surah/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
for (const [_, surah] of Object.entries(surahInfo)) {
result[surah.index] = {
...surah,
revelation: MakkiyahMadaniyah[surah.index] ? MakkiyahMadaniyah[surah.index] : 0
revelation: MakkiyahMadaniyah[surah.index] as 1 | 2 ? MakkiyahMadaniyah[surah.index] as 1 | 2 : 1
};
}
return result;
Expand Down
2 changes: 2 additions & 0 deletions src/routes/amp/[surahid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import SurahPage from '$lib/views/SurahPage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/routes/amp/[surahid]/[verseid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import VersePage from '$lib/views/VersePage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/routes/juz-amma/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if (surah.index >= SURAH_START) {
result[surah.index] = {
...surah,
revelation: MakkiyahMadaniyah[surah.index] ? MakkiyahMadaniyah[surah.index] : 0
revelation: MakkiyahMadaniyah[surah.index] as 1 | 2 ? MakkiyahMadaniyah[surah.index] as 1 | 2 : 1
};
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
name="chk-translation"
checked={$settingTranslation}
on:change={(e) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const checked = e?.target?.checked ?? false;
localStorage.setItem(CONSTANTS.STORAGE_KEY.TRANSLATION, checked ? 'y' : 'n');

Expand All @@ -50,6 +52,8 @@
name="chk-tafsir"
checked={$settingTafsir}
on:change={(e) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const checked = e?.target?.checked ?? false;
localStorage.setItem(CONSTANTS.STORAGE_KEY.TAFSIR, checked ? 'y' : 'n');

Expand Down Expand Up @@ -104,6 +108,8 @@
name="chk-auto-next"
checked={$settingAutoNext}
on:change={(e) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const checked = e?.target?.checked ?? false;
localStorage.setItem(CONSTANTS.STORAGE_KEY.AUTO_NEXT, checked ? 'y' : 'n');

Expand All @@ -120,6 +126,8 @@
id="select-qari"
bind:value={$settingAudio}
on:change={(e) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const value = e?.target?.value ?? 1;
localStorage.setItem(CONSTANTS.STORAGE_KEY.AUDIO, value ? value : '1');
}}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/surah-madaniyah/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (MakkiyahMadaniyah[surah.index] === MADANIYAH_CODE) {
result[surah.index] = {
...surah,
revelation: MakkiyahMadaniyah[surah.index] ? MakkiyahMadaniyah[surah.index] : 0
revelation: MakkiyahMadaniyah[surah.index] as 1 | 2 ? MakkiyahMadaniyah[surah.index] as 1 | 2 : 1
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/surah-makkiyah/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if (MakkiyahMadaniyah[surah.index] === MAKKIYAH_CODE) {
result[surah.index] = {
...surah,
revelation: MakkiyahMadaniyah[surah.index] ? MakkiyahMadaniyah[surah.index] : 0
revelation: MakkiyahMadaniyah[surah.index] as 1 | 2 ? MakkiyahMadaniyah[surah.index] as 1 | 2 : 1
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/routes/surah/[surahid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import SurahPage from '$lib/views/SurahPage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/routes/surah/[surahid]/[verseid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import VersePage from '$lib/views/VersePage.svelte';
/** @type {import('./$types').PageData} */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export let data;
</script>

Expand Down
9 changes: 9 additions & 0 deletions src/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/// <reference types="@sveltejs/kit" />
/// <reference no-default-lib="true"/>
/// <reference lib="esnext" />
Expand All @@ -19,6 +20,7 @@ self.addEventListener('install', (event) => {
await cache.addAll(ASSETS);
}

// @ts-ignore
event.waitUntil(addFilesToCache());
});

Expand All @@ -30,14 +32,17 @@ self.addEventListener('activate', (event) => {
}
}

// @ts-ignore
event.waitUntil(deleteOldCaches());
});

self.addEventListener('fetch', (event) => {
// ignore POST requests etc
// @ts-ignore
if (event.request.method !== 'GET') return;

async function respond() {
// @ts-ignore
const url = new URL(event.request.url);
const cache = await caches.open(CACHE);

Expand All @@ -53,6 +58,7 @@ self.addEventListener('fetch', (event) => {
// for everything else, try the network first, but
// fall back to the cache if we're offline
try {
// @ts-ignore
const response = await fetch(event.request);

// if we're offline, fetch can return a value that is not a Response
Expand All @@ -62,11 +68,13 @@ self.addEventListener('fetch', (event) => {
}

if (response.status === 200) {
// @ts-ignore
cache.put(event.request, response.clone());
}

return response;
} catch (err) {
// @ts-ignore
const response = await cache.match(event.request);

if (response) {
Expand All @@ -79,5 +87,6 @@ self.addEventListener('fetch', (event) => {
}
}

// @ts-ignore
event.respondWith(respond());
});
10 changes: 1 addition & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"paths": {
"$lib": ["./src/lib"],
"$lib/*": ["./src/lib/*"],
"$data": ["./src/data"],
"$data/*": ["./src/data/*"],
"$store": ["./src/store"],
"$store/*": ["./src/store/*"]
}
}
},
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
Expand Down

0 comments on commit 086d19a

Please sign in to comment.