Skip to content

Commit 665956e

Browse files
committed
Merge #140: fix browser issues
50133fa fix browser issues (Graeme Byrne) Pull request description: * Duplicate was being used in `data/blog-posts` and `data/index-posts.ts`. Data now stored in data/posts.ts * `routes/+layout.ts`, `routes/(home)/+page.server.ts` and `routes/api/+server.ts` updated to access data from correct location. * Text in `prevNext` component modified to reflect issue #138 * `.md` files added to `.prettierignore` so `CodeBlock` component can be applied to all code blocks. * `CodeBlock.svelte` component modified as mentioned in #52. Inspiration for change came from https://www.roboleary.net/2022/01/13/copy-code-to-clipboard-blog.html?utm_source=chatgpt.com * In order to solve issue #137, the reliance on unsupported `startViewTransition` is removed, ensuring more consistent behavior across different browsers and preventing navigation issues. ``` const supportsViewTransition = typeof window !== 'undefined' && 'startViewTransition' in document; onNavigate((navigation) => { return new Promise((resolve) => { if (supportsViewTransition) { const transition = document.startViewTransition(async () => { if (contentDiv) { contentDiv.scrollTop = 0; } resolve(); await navigation.complete; }); } else { if (contentDiv) { contentDiv.scrollTop = 0; } resolve(); } }); }); ``` * Overlapping `PostTable.svelte` in blog posts as mentioned in #139. The below change explicitly handles the resize event with `on:resize`, preventing conflicts between automatic binding and reactive updates, ensuring smoother state management. ``` <svelte:window on:resize={() => (size = window.innerWidth)} /> <div class={size >= 1440 ? 'scroll-container' : ''} style={divStyle}> <div> <slot /> </div> </div> ``` ACKs for top commit: josecelano: ACK 50133fa Tree-SHA512: 4a042cc0a98abca811b9506e08e4d1edc614f0cce36e54286606e1801960e94d1947798de740b6f0ebf3e42a75e882b42cf8a27db9bff3d4ee2da847ff963d70
2 parents 68964e3 + 50133fa commit 665956e

18 files changed

+258
-483
lines changed

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ node_modules
1414
package-lock.json
1515
pnpm-lock.yaml
1616
yarn.lock
17+
18+
src/routes/blog/**/*.md

src/lib/components/molecules/CodeBlock.svelte

+36-27
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@
4646
</script>
4747

4848
<div class="code-block" class:full-bleed={fullBleed} bind:this={codeBlockElement}>
49-
{#if filename}
50-
<div class="filename">{filename}</div>
51-
{/if}
52-
{#if lang}
53-
<div class="lang">{lang}</div>
54-
{/if}
55-
<button
56-
class={`copy-button ${showCheckmark ? 'copy-button-green' : 'copy-button-gray'}`}
57-
onclick={copyToClipboard}
58-
>
59-
{#if showCheckmark}
60-
<Icon icon="charm:tick" color="#6cdb2e" />
61-
{:else}
62-
<Icon icon="ion:copy-outline" color="#FFFFFF" />
49+
<div class="code-block-info">
50+
{#if filename}
51+
<div class="filename">{filename}</div>
6352
{/if}
64-
</button>
53+
{#if lang}
54+
<div class="lang">{lang}</div>
55+
{/if}
56+
<button
57+
class={`copy-button ${showCheckmark ? 'copy-button-green' : 'copy-button-gray'}`}
58+
onclick={copyToClipboard}
59+
>
60+
{#if showCheckmark}
61+
Code Copied <Icon icon="charm:tick" color="#6cdb2e" />
62+
{:else}
63+
Copy Code<Icon icon="ion:copy-outline" color="#FFFFFF" />
64+
{/if}
65+
</button>
66+
</div>
6567
<div class="code-content">
6668
{#if code}
6769
<pre><code
@@ -85,10 +87,10 @@
8587
line-height: 1.33em;
8688
border-radius: 8px;
8789
box-shadow: var(--card-shadow);
88-
padding: 12px 10px 20px 10px;
90+
padding: 0 0 20px 0;
8991
min-height: 80px;
9092
background-color: #282c34 !important;
91-
93+
border: 1px solid gray;
9294
margin: 30px 0;
9395
9496
:global(pre) {
@@ -111,17 +113,21 @@
111113
112114
.code-content code {
113115
border-radius: 8px;
116+
margin: 1rem 0.5rem 0 0.5rem;
117+
padding: 20px;
118+
}
119+
120+
.code-block-info {
121+
display: flex;
122+
justify-content: space-between;
123+
border-bottom: 1px solid gray;
124+
padding: 0.3rem 0.5rem;
114125
}
115126
116127
.lang {
117-
position: absolute;
118-
right: 0;
119-
top: -15px;
120-
background-color: rgba(36, 36, 36, 1);
121-
border-radius: 8px;
122128
padding: 5px 10px;
123129
z-index: 2;
124-
font-size: 0.85em;
130+
font-size: 1em;
125131
}
126132
127133
.filename {
@@ -137,13 +143,16 @@
137143
}
138144
139145
.copy-button {
140-
position: absolute;
141-
top: 1.5rem;
142-
right: 1.5rem;
143-
padding: 0.25rem;
146+
display: flex;
147+
justify-content: center;
148+
align-items: center;
149+
border: 1px solid gray;
144150
border-radius: 0.375rem;
151+
gap: 0.5rem;
152+
padding: 0.25rem 0.5rem;
145153
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
146154
cursor: pointer;
155+
font-size: 0.85em;
147156
}
148157
149158
.copy-button-green {

src/lib/components/molecules/PostTable.svelte

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- @migration-task Error while migrating Svelte code: Can't migrate code with afterUpdate. Please migrate by hand. -->
21
<script lang="ts">
32
import { onMount } from 'svelte';
43
@@ -13,12 +12,14 @@
1312
}
1413
};
1514
16-
onMount(updateStyles);
15+
onMount(() => {
16+
updateStyles();
17+
});
1718
1819
$: updateStyles();
1920
</script>
2021

21-
<svelte:window bind:innerWidth={size} />
22+
<svelte:window on:resize={() => (size = window.innerWidth)} />
2223

2324
<div class={size >= 1440 ? 'scroll-container' : ''} style={divStyle}>
2425
<div>

src/lib/components/singletons/PrevNextPost.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<a href="/blog/{prevPost.meta.slug}">{prevPost?.meta?.title}</a>
4444
</div>
4545
{:else}
46-
<h3 class="inactive">You are reading our first post.</h3>
46+
<h3 class="inactive">You are reading our most recent post.</h3>
4747
{/if}
4848
</div>
4949

src/lib/data/blog-posts/index.ts

-9
This file was deleted.

src/lib/data/blog-posts/utils.ts

-80
This file was deleted.

src/lib/utils/index_posts.ts src/lib/data/posts.ts

-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ export const fetchMarkdownPosts = async () => {
2828
};
2929
})
3030
);
31-
3231
return allPosts;
3332
};

src/routes/(home)/+page.server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetchMarkdownPosts } from '$lib/utils/index_posts';
1+
import { fetchMarkdownPosts } from '$lib/data/posts';
22
import type { Contributor } from '$lib/utils/types';
33
import { fetchWithCache } from '$lib/utils/cache';
44

src/routes/+layout.svelte

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,27 @@
44
import Header from '$lib/components/organisms/Header.svelte';
55
import Footer from '$lib/components/organisms/Footer.svelte';
66
import { onNavigate } from '$app/navigation';
7+
78
let contentDiv: HTMLElement | null = null;
89
10+
const supportsViewTransition = typeof window !== 'undefined' && 'startViewTransition' in document;
11+
912
onNavigate((navigation) => {
1013
return new Promise((resolve) => {
11-
const transition = document.startViewTransition(async () => {
14+
if (supportsViewTransition) {
15+
const transition = document.startViewTransition(async () => {
16+
if (contentDiv) {
17+
contentDiv.scrollTop = 0;
18+
}
19+
resolve();
20+
await navigation.complete;
21+
});
22+
} else {
1223
if (contentDiv) {
13-
// Fix scroll
1424
contentDiv.scrollTop = 0;
1525
}
1626
resolve();
17-
await navigation.complete;
18-
});
27+
}
1928
});
2029
});
2130

src/routes/+layout.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export const prerender = true;
22

3-
import { filteredPosts } from '$lib/data/blog-posts';
3+
export const load = async ({ fetch }) => {
4+
const response = await fetch(`/api`);
5+
const posts = await response.json();
46

5-
export async function load() {
67
return {
7-
posts: filteredPosts
8+
posts
89
};
9-
}
10+
};

src/routes/api/+server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetchMarkdownPosts } from '$lib/utils/index_posts';
1+
import { fetchMarkdownPosts } from '$lib/data/posts';
22
import { json } from '@sveltejs/kit';
33

44
export const GET = async () => {

src/routes/blog/[slug]/+page.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetchMarkdownPosts } from '$lib/utils/index_posts';
1+
import { fetchMarkdownPosts } from '$lib/data/posts';
22

33
export async function load({ params }) {
44
const post = await import(`../${params.slug}.md`);

0 commit comments

Comments
 (0)