Skip to content

Commit 7d1bc49

Browse files
committed
feat(site): add infinite scroll & in-page topic filtering with content-visibility optimization
1 parent db92be4 commit 7d1bc49

14 files changed

Lines changed: 907 additions & 82 deletions

File tree

‎apps/site/src/components/ContentCard.astro‎

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@ import CoverImage from "@/components/CoverImage.astro";
44
import FormattedDate from "@/components/FormattedDate.astro";
55
import { type ContentListItem, isPerson } from "@/lib/content";
66
import { resolveHref } from "@/lib/sanity/resolve-href";
7+
import { matchTopicsForText } from "@/lib/topics";
78
89
interface Props {
910
item: ContentListItem;
1011
priority?: boolean;
12+
deferred?: boolean;
1113
}
1214
13-
const { item, priority = false } = Astro.props;
15+
const { item, priority = false, deferred = !priority } = Astro.props;
1416
1517
const href = resolveHref(item._type, item.slug ?? undefined);
1618
const person = isPerson(item._type);
1719
const people = [
1820
...(item.author ?? []).map((p) => ({ ...p, type: "author" })),
1921
...(item.guest ?? []).map((p) => ({ ...p, type: "guest" })),
2022
];
23+
const matchedTopics = !person
24+
? matchTopicsForText(item.title, item.excerpt).slice(0, 2)
25+
: [];
2126
---
2227

23-
<article class="duo-card hand-border group flex h-full flex-col overflow-hidden p-5 transition-all duration-200 hover:-translate-y-1.5 hover:border-[#7C3AED] dark:hover:border-[#C084FC]">
28+
<article
29+
class:list={[
30+
"duo-card hand-border group flex h-full flex-col overflow-hidden p-5 transition-all duration-200 hover:-translate-y-1.5 hover:border-[#7C3AED] dark:hover:border-[#C084FC]",
31+
deferred && "infinite-card-deferred",
32+
]}
33+
>
2434
{
2535
href && (
2636
<a href={href} class="mb-4 block overflow-hidden rounded-2xl border-2 border-[#2A1155] bg-[#2A1155] dark:border-white/20 dark:bg-[#060E20]">
@@ -48,9 +58,41 @@ const people = [
4858
<div class="flex flex-1 flex-col justify-between">
4959
<div>
5060
{
51-
!person && item.date && (
52-
<div class="mb-2 inline-flex rounded-full border border-[#2A1155]/30 bg-[#EDE9FE] px-3 py-0.5 font-mono text-xs font-extrabold uppercase tracking-wider text-[#7C3AED] dark:border-purple-400/30 dark:bg-purple-950/80 dark:text-purple-200">
53-
<FormattedDate dateString={item.date} />
61+
!person && (item.date || matchedTopics.length > 0) && (
62+
<div class="mb-2.5 flex flex-wrap items-center gap-1.5">
63+
{item.date && (
64+
<div class="inline-flex rounded-full border border-[#2A1155]/30 bg-[#EDE9FE] px-3 py-0.5 font-mono text-xs font-extrabold uppercase tracking-wider text-[#7C3AED] dark:border-purple-400/30 dark:bg-purple-950/80 dark:text-purple-200">
65+
<FormattedDate dateString={item.date} />
66+
</div>
67+
)}
68+
{matchedTopics.map((topic) => (
69+
<a
70+
href={`/topic/${topic.slug}`}
71+
class="inline-flex items-center gap-1.5 rounded-full border border-[#2A1155] bg-white px-2.5 py-0.5 font-mono text-[11px] font-bold text-[#2A1155] transition-colors hover:bg-[#EDE9FE] dark:border-white/25 dark:bg-[#0B1326] dark:text-slate-200 dark:hover:bg-purple-950/60"
72+
>
73+
{topic.symbolLight && (
74+
<img
75+
src={topic.symbolLight}
76+
alt=""
77+
aria-hidden="true"
78+
class="h-3 w-auto object-contain dark:hidden"
79+
loading="lazy"
80+
decoding="async"
81+
/>
82+
)}
83+
{topic.symbolDark && (
84+
<img
85+
src={topic.symbolDark}
86+
alt=""
87+
aria-hidden="true"
88+
class="hidden h-3 w-auto object-contain dark:block"
89+
loading="lazy"
90+
decoding="async"
91+
/>
92+
)}
93+
<span>{topic.title}</span>
94+
</a>
95+
))}
5496
</div>
5597
)
5698
}

‎apps/site/src/components/CoverImage.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const alt = rawAlt && rawAlt.trim().length > 0 ? rawAlt : fallbackAlt;
7979
height={maxHeight}
8080
alt={alt}
8181
loading={priority ? "eager" : "lazy"}
82-
fetchpriority={priority ? "high" : "auto"}
82+
fetchpriority={priority ? "high" : undefined}
8383
decoding={priority ? "sync" : "async"}
8484
sizes={sizes}
8585
/>

0 commit comments

Comments
 (0)