Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions scripts/fetch-discussions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ mkdirSync(DATA_DIR, { recursive: true });
const API =
"https://api.github.com/repos/CodeGateSoftware/keel/discussions?per_page=50&state=open";

/** One output feed: category slug, destination file, item cap (#13). */
/**
* One output feed: category slug, destination file, item cap. `exclude`
* instead of `category` = everything but those slugs (#73: the community's
* own threads — Q&A, compliance classification, ideas — get a window
* without flooding the announcements archive).
*/
const FEEDS = [
{ category: "announcements", file: "discussions.json", maxItems: 10 },
{ category: "announcements", file: "discussions.json", maxItems: 30 },
{ category: "show-and-tell", file: "show-and-tell.json", maxItems: 5 },
{
category: null,
exclude: ["announcements", "show-and-tell"],
file: "community.json",
maxItems: 5,
label: "discussions",
},
];

const headers = {
Expand Down Expand Up @@ -61,7 +73,12 @@ const categoryUrl = (slug) =>
/** Write one feed's file from the fetched discussions. */
function writeFeed(feed, discussions) {
const items = discussions
.filter((discussion) => discussion.category?.slug === feed.category)
.filter((discussion) =>
feed.category
? discussion.category?.slug === feed.category
: !feed.exclude.includes(discussion.category?.slug ?? ""),
)
.sort((a, b) => b.created_at.localeCompare(a.created_at)) // newest first (#73)
.slice(0, feed.maxItems)
.map((discussion) => ({
number: discussion.number,
Expand All @@ -76,16 +93,16 @@ function writeFeed(feed, discussions) {
join(DATA_DIR, feed.file),
JSON.stringify(
{
category: feed.category,
categoryUrl: categoryUrl(feed.category),
category: feed.category ?? feed.label,
categoryUrl: feed.category ? categoryUrl(feed.category) : "https://github.com/CodeGateSoftware/keel/discussions",
fetchedAt: new Date().toISOString(),
items,
},
null,
2,
) + "\n",
);
console.log(` discussions: ${items.length} ${feed.category}(s) -> data/${feed.file}`);
console.log(` discussions: ${items.length} ${feed.category ?? feed.label}(s) -> data/${feed.file}`);
}

/** Degrade one feed's file: keep last-known data, else an empty stub. */
Expand All @@ -99,8 +116,8 @@ function degradeFeed(feed, reason) {
out,
JSON.stringify(
{
category: feed.category,
categoryUrl: categoryUrl(feed.category),
category: feed.category ?? feed.label,
categoryUrl: feed.category ? categoryUrl(feed.category) : "https://github.com/CodeGateSoftware/keel/discussions",
fetchedAt: null,
items: [],
},
Expand Down
133 changes: 127 additions & 6 deletions src/components/pages/NewsPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { t } from "../../i18n/ui";

interface Props {
locale: Locale;
/** 1-based page number; page 1 renders at /news/, archives at /news/2/… (#73). */
page?: number;
}

const { locale } = Astro.props;
const { locale, page = 1 } = Astro.props;
const c = news[locale];
const chrome = t(locale);

Expand Down Expand Up @@ -48,15 +50,35 @@ const showAndTell: DiscussionsFile =
fetchedAt: null,
items: [],
};

/** Community window (#73) — newest threads from every other category. */
const community: DiscussionsFile =
readDataFile<DiscussionsFile>("community.json") ?? {
category: "discussions",
categoryUrl: "https://github.com/CodeGateSoftware/keel/discussions",
fetchedAt: null,
items: [],
};

/** Pagination (#73) — five announcements per static page. */
const PAGE_SIZE = 5;
const totalPages = Math.max(1, Math.ceil(feed.items.length / PAGE_SIZE));
const current = Math.min(Math.max(1, page), totalPages);
const pageItems = feed.items.slice((current - 1) * PAGE_SIZE, current * PAGE_SIZE);
const pageHref = (n: number) => (n <= 1 ? localePath(locale, "news") : `/${locale}/news/${n}/`);
---

<Base
locale={locale}
pageKey="news"
title={c.title}
title={current > 1 ? `${c.title} — ${current}` : c.title}
description={c.description}
path={localePath(locale, "news")}
alternates={alternatesFor("news")}
path={current > 1 ? `/${locale}/news/${current}/` : localePath(locale, "news")}
alternates={
current > 1
? alternatesFor("news").map((alt) => ({ ...alt, path: `/${alt.locale}/news/${current}/` }))
: alternatesFor("news")
}
>
<div class="container">
<section class="hero">
Expand All @@ -80,7 +102,7 @@ const showAndTell: DiscussionsFile =
</div>
) : (
<ul class="news-list">
{feed.items.map((item) => (
{pageItems.map((item) => (
<li class="news-item">
<p class="meta">
<time datetime={item.createdAt}>{formatDate(item.createdAt)}</time>
Expand Down Expand Up @@ -109,10 +131,28 @@ const showAndTell: DiscussionsFile =
{locale === "ar" ? "خلاصة RSS" : locale === "fr" ? "Flux RSS" : "RSS feed"} ↗
</a>
</p>

{
totalPages > 1 && (
<nav class="news-pager" aria-label={locale === "ar" ? "تصفّح الأخبار" : locale === "fr" ? "Pagination des actualités" : "News pages"}>
{current > 1 && <a class="pager-arrow" href={pageHref(current - 1)} rel="prev">← {c.prevPage}</a>}
<span class="pager-numbers">
{Array.from({ length: totalPages }, (_, i) => i + 1).map((n) =>
n === current ? (
<span class="pager-current" aria-current="page">{n}</span>
) : (
<a href={pageHref(n)}>{n}</a>
),
)}
</span>
{current < totalPages && <a class="pager-arrow" href={pageHref(current + 1)} rel="next">{c.nextPage} →</a>}
</nav>
)
}
</section>

{
subscriptionsEnabled && (
current === 1 && subscriptionsEnabled && (
<section class="subscribe" aria-label={c.subscribeTitle}>
<h2>{c.subscribeTitle}</h2>
<p>{c.subscribeBody}</p>
Expand Down Expand Up @@ -177,11 +217,92 @@ const showAndTell: DiscussionsFile =
<a href={showAndTell.categoryUrl}>{chrome.actions.readOnGitHub} →</a>
</p>
</section>

{
current === 1 && (
<section class="prose" aria-label={c.communityTitle}>
<h2>{c.communityTitle}</h2>
<p>{c.communityBody}</p>
{community.items.length === 0 ? (
<div class="stale-banner" role="note">
<p>{chrome.news.secondaryEmpty}</p>
<p>
<a href={community.categoryUrl}>{chrome.actions.readOnGitHub} →</a>
</p>
</div>
) : (
<ul class="news-list secondary">
{community.items.map((item) => (
<li class="news-item">
<p class="meta">
<time datetime={item.createdAt}>{formatDate(item.createdAt)}</time>
{item.author && (
<>
<span class="dot" aria-hidden="true">·</span>
<span>{item.author}</span>
</>
)}
<span class="dot" aria-hidden="true">·</span>
<span>{chrome.news.comments(item.comments)}</span>
</p>
<p class="title">
<a href={item.url}>{item.title}</a>
</p>
{item.excerpt && <p class="excerpt">{item.excerpt}</p>}
</li>
))}
</ul>
)}
<p class="doc-meta">
<a href={community.categoryUrl}>{chrome.actions.readOnGitHub} →</a>
</p>
</section>
)
}
</div>
</div>
</Base>

<style>
/* Pagination (#73) — plain numbered pages, arrows on the outer edges. */
.news-pager {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 0.4rem 0.9rem;
margin-block: 1.8rem 0.5rem;
}

.news-pager a {
color: var(--link);
text-decoration: none;
padding: 0.25rem 0.5rem;
border-radius: 6px;
}

.news-pager a:hover {
background: var(--surface-2);
}

.pager-arrow {
font-weight: 600;
}

.pager-numbers {
display: inline-flex;
gap: 0.25rem;
}

.pager-current {
font-weight: 700;
color: var(--accent);
padding: 0.25rem 0.5rem;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--surface);
}

/* Secondary feed (#13) — same chrome as the announcements list, smaller and quieter. */
.news-list.secondary {
margin-block: 1rem;
Expand Down
Loading
Loading