Skip to content

Commit c059405

Browse files
committed
Add astro-preload.
1 parent eb8741d commit c059405

File tree

7 files changed

+18
-163
lines changed

7 files changed

+18
-163
lines changed

astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import rehypeAutolinkHeadings from "rehype-autolink-headings";
1010
import metaTags from "astro-meta-tags";
1111
import pagefind from "astro-pagefind";
1212
import deleteUnusedImages from "astro-delete-unused-images";
13+
import preload from "astro-preload";
1314

1415
// https://astro.build/config
1516
export default defineConfig({
@@ -61,6 +62,7 @@ export default defineConfig({
6162
"/wasm-summit/": "/programme/wasm-summit/",
6263
},
6364
integrations: [
65+
preload(),
6466
mdx(),
6567
sitemap(),
6668
react(),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"astro-delete-unused-images": "^1.0.3",
2626
"astro-meta-tags": "^0.3.1",
2727
"astro-pagefind": "^1.8.1",
28+
"astro-preload": "^1.1.2",
2829
"clsx": "^2.1.1",
2930
"date-fns": "^4.1.0",
3031
"date-fns-tz": "^3.2.0",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/preloaded/.gitkeep

Whitespace-only changes.

src/image-cache.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/pages/session/[slug].astro

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { formatInTimeZone } from "date-fns-tz";
77
import { YouTube } from "@astro-community/astro-embed-youtube";
88
import { Picture } from "astro:assets";
99
import Markdown from "@ui/Markdown.astro";
10-
import { getCachedImage } from "../../image-cache";
1110
1211
export async function getStaticPaths() {
1312
const sessions = await getCollection("sessions");
@@ -24,19 +23,6 @@ const { entry } = Astro.props;
2423
2524
const speakers = await getEntries(entry.data.speakers);
2625
27-
const speakersWithCachedAvatars = await Promise.all(
28-
speakers.map(async (speaker) => {
29-
const cachedAvatarUrl = await getCachedImage(speaker.data.avatar);
30-
return {
31-
...speaker,
32-
data: {
33-
...speaker.data,
34-
avatar: cachedAvatarUrl,
35-
},
36-
};
37-
})
38-
);
39-
4026
// Resolve session codes to session data
4127
const resolveSessions = (codes: string[]) =>
4228
codes.map((code) => sessions.find((s) => s?.data?.code === code));
@@ -159,9 +145,9 @@ const nextSessionsOrdered = sameRoomNextSession
159145
<>
160146
<Separator />
161147
<h2 class="relative font-title text-primary font-bold mb-[0.6em] [&>a]:border-0 [&>a]:text-inherit text-5xl">
162-
The speaker{speakersWithCachedAvatars.length > 1 ? "s" : ""}
148+
The speaker{speakers.length > 1 ? "s" : ""}
163149
</h2>
164-
{speakersWithCachedAvatars.map((speaker) => (
150+
{speakers.map((speaker) => (
165151
<div class="md:grid grid-cols-[260px_1fr] md:gap-6">
166152
{speaker.data.avatar ? (
167153
<div class="flex items-start">

src/pages/speaker/[slug].astro

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,14 @@ import Prose from "../../components/prose/prose.astro";
55
import { Image } from "astro:assets";
66
import Markdown from "@ui/Markdown.astro";
77
import Headline from "@ui/Headline.astro";
8-
import { getCachedImage } from "../../image-cache";
8+
99
1010
export async function getStaticPaths() {
1111
const entries = await getCollection("speakers");
12-
13-
function isUrl(str: string): boolean {
14-
str = ensureHttps(str);
15-
const regex =
16-
/^(https?:\/\/)?([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,6})([\/\w@.-]*)$/;
17-
return regex.test(str);
18-
}
19-
20-
function ensureHttps(str: string): string {
21-
if (!/^https?:\/\//i.test(str)) {
22-
return "https://" + str;
23-
}
24-
return str;
25-
}
26-
27-
return Promise.all(
28-
entries.map(async (entry) => {
29-
let avatar: any;
30-
if (entry.data.avatar && isUrl(entry.data.avatar)) {
31-
try {
32-
avatar = await getCachedImage(entry.data.avatar);
33-
} catch (err) {
34-
console.log("Error with avatar: ",err);
35-
avatar = null;
36-
}
37-
}
38-
return {
39-
params: { slug: entry.id },
40-
props: {
41-
entry: {
42-
data: {
43-
...entry.data,
44-
avatar: avatar
45-
},
46-
},
47-
}, avatar
48-
};
49-
}),
50-
);
12+
return entries.map((entry) => ({
13+
params: { slug: entry.id },
14+
props: { entry },
15+
}));
5116
}
5217
5318
const { entry } = Astro.props;

0 commit comments

Comments
 (0)