Skip to content

Commit 9434f72

Browse files
authored
fix: resolve all svelte-check errors and warnings (#79)
- Add type casts for window.__pg_client_nav usage - Type blog post metadata and sort comparisons - Add href placeholder to obfuscated contact links (a11y) - Use $state() for contactEl binding - Remove unused browser import
1 parent 10aa7b6 commit 9434f72

7 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/routes/(marketing)/+layout.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { onMount } from 'svelte'
66
77
let { children } = $props()
8-
let contactEl
8+
let contactEl = $state<HTMLAnchorElement>()
99
1010
onMount(() => {
1111
if (contactEl) {
@@ -44,7 +44,7 @@
4444
<div class="footer-col">
4545
<h4>{$_('footer.connectTitle')}</h4>
4646
<ul>
47-
<li><a bind:this={contactEl} data-name="info" data-domain="postguard.eu">{$_('footer.contact')}</a></li>
47+
<li><a href="#contact" bind:this={contactEl} data-name="info" data-domain="postguard.eu">{$_('footer.contact')}</a></li>
4848
<li><a href="https://github.com/encryption4all">GitHub</a></li>
4949
<li><a href="https://business.postguard.eu">PostGuard for Business</a></li>
5050
</ul>

src/routes/(marketing)/+page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { redirect } from '@sveltejs/kit'
44
export function load({ url }) {
55
// Only redirect returning visitors on direct/external navigation (full page load),
66
// not on client-side navigations (e.g. clicking "Home" in the navbar).
7-
if (browser && !window.__pg_client_nav && localStorage.getItem('pg_visited')) {
7+
if (browser && !/** @type {any} */ (window).__pg_client_nav && localStorage.getItem('pg_visited')) {
88
redirect(302, '/fileshare')
99
}
1010
}

src/routes/(marketing)/+page.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<script lang="ts">
2-
import { browser } from '$app/environment'
32
import { onMount } from 'svelte'
43
import { _ } from 'svelte-i18n'
54
import SEO from '$lib/components/SEO.svelte'
65
7-
let contactEl
6+
let contactEl: HTMLAnchorElement
87
98
onMount(() => {
109
localStorage.setItem('pg_visited', 'true')
@@ -88,7 +87,7 @@
8887
<p>{$_('landing.business6Desc')}</p>
8988
</div>
9089
</div>
91-
<a bind:this={contactEl} data-name="info" data-domain="postguard.eu" class="business-cta">{$_('landing.businessCta')}</a>
90+
<a href="#contact" bind:this={contactEl} data-name="info" data-domain="postguard.eu" class="business-cta">{$_('landing.businessCta')}</a>
9291
</div>
9392
</section>
9493
</div>
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
/**
2+
* @typedef {{ slug: string, title: string, description: string, date: string, image?: string }} BlogPost
3+
*/
4+
15
export async function load() {
26
const postFiles = import.meta.glob('/src/content/blog/*.svx', { eager: true })
37

8+
/** @type {BlogPost[]} */
49
const posts = Object.entries(postFiles)
5-
.map(([path, module]) => ({
6-
slug: path.split('/').pop().replace('.svx', ''),
7-
...module.metadata,
8-
}))
9-
.sort((a, b) => new Date(b.date) - new Date(a.date))
10+
.map(([path, module]) => {
11+
const { metadata } = /** @type {{ metadata: Record<string, any> }} */ (module)
12+
return /** @type {BlogPost} */ ({
13+
slug: /** @type {string} */ (path.split('/').pop()).replace('.svx', ''),
14+
...metadata,
15+
})
16+
})
17+
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
1018

1119
return { posts }
1220
}

src/routes/(marketing)/blog/[slug]/+page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const posts = import.meta.glob('/src/content/blog/*.svx', { eager: true })
22

33
export function load({ params }) {
44
const path = `/src/content/blog/${params.slug}.svx`
5-
const post = posts[path]
5+
const post = /** @type {{ default: any, metadata: Record<string, any> }} */ (posts[path])
66

77
if (!post) {
88
throw new Error(`Post not found: ${params.slug}`)
@@ -16,6 +16,6 @@ export function load({ params }) {
1616

1717
export function entries() {
1818
return Object.keys(posts).map((path) => ({
19-
slug: path.split('/').pop().replace('.svx', ''),
19+
slug: /** @type {string} */ (path.split('/').pop()).replace('.svx', ''),
2020
}))
2121
}

src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Mark that the app has hydrated so subsequent navigations
77
// to / don't trigger the returning visitor redirect.
88
onMount(() => {
9-
window.__pg_client_nav = true
9+
;(window as any).__pg_client_nav = true
1010
})
1111
</script>
1212

src/routes/sitemap.xml/+server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function GET() {
55

66
const postFiles = import.meta.glob('/src/content/blog/*.svx', { eager: true })
77
const blogSlugs = Object.keys(postFiles).map(
8-
(path) => `/blog/${path.split('/').pop().replace('.svx', '')}`
8+
(path) => `/blog/${/** @type {string} */ (path.split('/').pop()).replace('.svx', '')}`
99
)
1010

1111
const pages = [...staticPages, ...blogSlugs]

0 commit comments

Comments
 (0)