admin page
All checks were successful
/ deploy (push) Successful in 1m8s

This commit is contained in:
Loyyd 2026-07-10 10:38:08 +02:00
parent aa10a4e22b
commit e2354234ae
2 changed files with 891 additions and 190 deletions

View file

@ -3,13 +3,25 @@ import SiteLayout from "../../components/SiteLayout.astro";
import { getSpeechArchive, uniqueSorted } from "../../lib/speeches";
const speeches = getSpeechArchive();
const years = uniqueSorted(speeches.map((speech) => speech.year), "desc");
const years = uniqueSorted(speeches.map((speech) => speech.year));
const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
const decades = uniqueSorted(
years.map((year) => `${Math.floor(Number.parseInt(year, 10) / 10) * 10}`),
);
const yearCounts = new Map(
years.map((year) => [year, speeches.filter((speech) => speech.year === year).length]),
);
const maxYearCount = Math.max(...yearCounts.values());
const initialResults = speeches.slice(0, 18);
const initialSpeech = initialResults[0];
const initialSpeechId = initialSpeech?.id ?? "";
const firstYear = years[0] ?? "";
const lastYear = years.at(-1) ?? "";
---
<SiteLayout
title="Speeches Archive &#8211; FFWPU Ireland"
description="Search the FFWPU Ireland archive of speeches by Rev. Sun Myung Moon and Dr. Hak Ja Han Moon by year, speaker, and text."
title="Speeches Explorer &#8211; FFWPU Ireland"
description={`Explore ${speeches.length} speeches in the FFWPU Ireland archive by year, decade, speaker, and full text.`}
bodyClass="page-template page-template-templates page-template-template-onecolumn page-template-templatestemplate-onecolumn-php page custom-background tribe-no-js metaslider-plugin parabola-image-three caption-light meta-light parabola_triagles parabola-menu-left"
pathname="/speeches/"
canonical="/speeches/"
@ -21,21 +33,32 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
<section id="container" class="one-column speeches-archive">
<div id="content" role="main">
<div class="post page type-page status-publish hentry">
<h1 class="entry-title">Speeches Archive</h1>
<div class="entry-content speech-explorer" data-speech-explorer>
<header class="speech-explorer-intro">
<p class="speech-explorer-kicker">FFWPU Ireland digital collection</p>
<h1 class="entry-title">Speeches Explorer</h1>
<p>Search the full archive, compare activity across the years, and select any result for a closer look.</p>
</header>
<dl class="speech-archive-overview" aria-label="Archive overview">
<div>
<dt>Speeches</dt>
<dd>{speeches.length.toLocaleString("en-IE")}</dd>
</div>
<div>
<dt>Years represented</dt>
<dd>{years.length}</dd>
</div>
<div>
<dt>Collection span</dt>
<dd>{firstYear}&ndash;{lastYear}</dd>
</div>
</dl>
<div class="entry-content">
<form class="speech-filters" id="speech-filters" role="search">
<div class="speech-filter speech-filter-search">
<label for="speech-search">Search text</label>
<input id="speech-search" name="q" type="search" autocomplete="off" placeholder="Search titles and full speech text" />
</div>
<div class="speech-filter">
<label for="speech-year">Year</label>
<select id="speech-year" name="year">
<option value="">All years</option>
{years.map((year) => <option value={year}>{year}</option>)}
</select>
<label for="speech-search">Search the full text</label>
<input id="speech-search" name="q" type="search" autocomplete="off" placeholder="Try peace, family, Ireland&hellip;" />
</div>
<div class="speech-filter">
@ -46,29 +69,121 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
</select>
</div>
<button class="speech-reset" type="reset">Reset filters</button>
<div class="speech-filter">
<label for="speech-decade">Decade</label>
<select id="speech-decade" name="decade">
<option value="">All decades</option>
{decades.map((decade) => <option value={decade}>{decade}s</option>)}
</select>
</div>
<div class="speech-filter">
<label for="speech-year">Year</label>
<select id="speech-year" name="year">
<option value="">All years</option>
{years.map((year) => <option value={year}>{year}</option>)}
</select>
</div>
<button class="speech-reset" type="reset">Clear filters</button>
</form>
<div class="speech-archive-status" aria-live="polite">
<strong id="speech-result-count">{speeches.length}</strong> speeches
<section class="speech-chart-section" aria-labelledby="speech-chart-title">
<div class="speech-section-heading">
<div>
<p class="speech-section-kicker">Distribution</p>
<h2 id="speech-chart-title">Speeches by year</h2>
</div>
<p class="speech-chart-summary" data-chart-summary>{speeches.length} speeches across {years.length} years</p>
</div>
<div
class="speech-year-chart"
data-year-chart
style={`--speech-year-columns: ${years.length}`}
role="group"
aria-label="Number of speeches in each year. Select a bar to filter the archive."
>
{
years.map((year, index) => {
const count = yearCounts.get(year) ?? 0;
const height = Math.max(3, Math.round((count / maxYearCount) * 100));
const showTick = index === 0 || index === years.length - 1 || Number.parseInt(year, 10) % 5 === 0;
return (
<button
class="speech-year-button"
type="button"
data-year={year}
data-chart-label={`${year}: ${count} ${count === 1 ? "speech" : "speeches"}`}
style={`--speech-bar-height: ${height}%`}
aria-label={`${year}: ${count} ${count === 1 ? "speech" : "speeches"}`}
aria-pressed="false"
>
<span class="speech-year-bar" aria-hidden="true"></span>
{showTick && <span class="speech-year-tick" aria-hidden="true">{year}</span>}
</button>
);
})
}
</div>
</section>
<div class="speech-explorer-layout">
<section class="speech-results-panel" aria-labelledby="speech-results-title">
<div class="speech-section-heading speech-results-heading">
<div>
<p class="speech-section-kicker">Browse</p>
<h2 id="speech-results-title">Archive results</h2>
</div>
<p class="speech-results-status" aria-live="polite" data-results-status>
Showing {initialResults.length} of {speeches.length}
</p>
</div>
<div class="speech-results" id="speech-results">
{
initialResults.map((speech, index) => (
<a
class:list={["speech-result", { "is-selected": index === 0 }]}
href={speech.url}
data-speech-id={speech.id}
aria-current={index === 0 ? "true" : undefined}
>
<span class="speech-result-topline">
<span class="speech-result-year">{speech.year}</span>
<span>{speech.speaker}</span>
</span>
<strong class="speech-result-title">{speech.title}</strong>
<span class="speech-result-excerpt">{speech.excerpt}</span>
</a>
))
}
</div>
<button class="speech-load-more" type="button" data-load-more>Show more speeches</button>
</section>
<aside class="speech-detail" aria-labelledby="speech-detail-label" data-speech-detail>
<p class="speech-section-kicker" id="speech-detail-label">Selected speech</p>
{
initialSpeech && (
<>
<p class="speech-detail-position" data-detail-position>1 of {speeches.length}</p>
<h2 data-detail-title>{initialSpeech.title}</h2>
<p class="speech-detail-meta" data-detail-meta>{initialSpeech.year} <span aria-hidden="true">&middot;</span> {initialSpeech.speaker}</p>
<p data-detail-excerpt>{initialSpeech.excerpt}</p>
<a class="speech-detail-link" href={initialSpeech.url} data-detail-link>Read the full speech <span aria-hidden="true">&rarr;</span></a>
<div class="speech-detail-nav" aria-label="Move through filtered speeches">
<button type="button" data-detail-previous disabled>Previous</button>
<button type="button" data-detail-next>Next</button>
</div>
</>
)
}
</aside>
</div>
<div class="speech-results" id="speech-results">
{
speeches.map((speech) => (
<article class="speech-result">
<div class="speech-result-meta">
<span>{speech.year}</span>
<span>{speech.speaker}</span>
</div>
<h2 class="speech-result-title">
<a href={speech.url}>{speech.title}</a>
</h2>
<p>{speech.excerpt}</p>
</article>
))
}
</div>
<p class="speech-explorer-message" data-explorer-message aria-live="polite">Loading full-text search&hellip;</p>
</div>
</div>
</div>
@ -78,69 +193,99 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
</div>
</div>
<script is:inline slot="scripts">
<script is:inline slot="scripts" define:vars={{ initialSpeechId }}>
(() => {
const explorer = document.querySelector("[data-speech-explorer]");
const form = document.getElementById("speech-filters");
const results = document.getElementById("speech-results");
const count = document.getElementById("speech-result-count");
const resultsStatus = explorer?.querySelector("[data-results-status]");
const searchInput = document.getElementById("speech-search");
const yearSelect = document.getElementById("speech-year");
const decadeSelect = document.getElementById("speech-decade");
const speakerSelect = document.getElementById("speech-speaker");
const chart = explorer?.querySelector("[data-year-chart]");
const chartSummary = explorer?.querySelector("[data-chart-summary]");
const detail = explorer?.querySelector("[data-speech-detail]");
const detailPosition = detail?.querySelector("[data-detail-position]");
const detailTitle = detail?.querySelector("[data-detail-title]");
const detailMeta = detail?.querySelector("[data-detail-meta]");
const detailExcerpt = detail?.querySelector("[data-detail-excerpt]");
const detailLink = detail?.querySelector("[data-detail-link]");
const previousButton = detail?.querySelector("[data-detail-previous]");
const nextButton = detail?.querySelector("[data-detail-next]");
const loadMoreButton = explorer?.querySelector("[data-load-more]");
const message = explorer?.querySelector("[data-explorer-message]");
if (!form || !results || !count || !searchInput || !yearSelect || !speakerSelect) {
if (
!explorer || !form || !results || !resultsStatus || !searchInput || !yearSelect ||
!decadeSelect || !speakerSelect || !chart || !chartSummary || !detail ||
!detailPosition || !detailTitle || !detailMeta || !detailExcerpt || !detailLink ||
!previousButton || !nextButton || !loadMoreButton || !message
) {
return;
}
let speeches = [];
let searchIndex = {};
let searchTerms = [];
const termCache = new Map();
let filteredSpeeches = [];
let selectedId = initialSpeechId;
let visibleLimit = 18;
let renderTimer = 0;
const termCache = new Map();
function normalize(value) {
return value
return String(value || "")
.normalize("NFKD")
.replace(/[\u0300-\u036f]/g, "")
.toLowerCase()
.trim();
}
function speechDecade(speech) {
return `${Math.floor(Number.parseInt(speech.year, 10) / 10) * 10}`;
}
function selectedFilters() {
return {
q: searchInput.value.trim(),
year: yearSelect.value,
speaker: speakerSelect.value,
decade: decadeSelect.value,
year: yearSelect.value,
};
}
function syncUrl(filters) {
const params = new URLSearchParams();
Object.entries(filters).forEach(([key, value]) => {
if (value) {
params.set(key, value);
}
});
const nextUrl = params.toString() ? `${window.location.pathname}?${params}` : window.location.pathname;
window.history.replaceState(null, "", nextUrl);
}
function hydrateFromUrl() {
const params = new URLSearchParams(window.location.search);
searchInput.value = params.get("q") || "";
yearSelect.value = params.get("year") || "";
speakerSelect.value = params.get("speaker") || "";
decadeSelect.value = params.get("decade") || "";
yearSelect.value = params.get("year") || "";
selectedId = params.get("speech") || selectedId;
}
function syncUrl(filters) {
const params = new URLSearchParams();
Object.entries(filters).forEach(([key, value]) => {
if (value) params.set(key, value);
});
if (selectedId) params.set("speech", selectedId);
const nextUrl = params.toString() ? `${window.location.pathname}?${params}` : window.location.pathname;
window.history.replaceState(null, "", nextUrl);
}
function decodeDocumentIds(value) {
return new Set(String(value || "").split(",").filter(Boolean).map((documentId) => Number.parseInt(documentId, 36)));
return new Set(
String(value || "")
.split(",")
.filter(Boolean)
.map((documentId) => Number.parseInt(documentId, 36)),
);
}
function unionSets(sets) {
const union = new Set();
sets.forEach((set) => {
set.forEach((value) => union.add(value));
});
sets.forEach((set) => set.forEach((value) => union.add(value)));
return union;
}
@ -148,26 +293,17 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
const smaller = left.size <= right.size ? left : right;
const larger = left.size <= right.size ? right : left;
const intersection = new Set();
smaller.forEach((value) => {
if (larger.has(value)) {
intersection.add(value);
}
if (larger.has(value)) intersection.add(value);
});
return intersection;
}
function documentsForTerm(term) {
if (termCache.has(term)) {
return termCache.get(term);
}
if (termCache.has(term)) return termCache.get(term);
const matches = [];
if (searchIndex[term]) {
matches.push(decodeDocumentIds(searchIndex[term]));
}
if (searchIndex[term]) matches.push(decodeDocumentIds(searchIndex[term]));
if (term.length >= 3) {
searchTerms.forEach((indexedTerm) => {
@ -184,75 +320,56 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
function searchCandidates(query) {
const terms = normalize(query).match(/[a-z0-9]+/g)?.filter((term) => term.length >= 2) ?? [];
if (!terms.length) {
return null;
}
if (!terms.length) return null;
return terms.reduce((candidateIds, term) => {
const termIds = documentsForTerm(term);
if (!candidateIds) {
return termIds;
}
return intersectSets(candidateIds, termIds);
return candidateIds ? intersectSets(candidateIds, termIds) : termIds;
}, null);
}
function matchesSpeechMetadata(speech, filters) {
if (filters.year && speech.year !== filters.year) {
return false;
}
if (filters.speaker && speech.speaker !== filters.speaker) {
return false;
}
function matchesMetadata(speech, filters) {
if (filters.speaker && speech.speaker !== filters.speaker) return false;
if (filters.decade && speechDecade(speech) !== filters.decade) return false;
return true;
}
function appendMeta(parent, values) {
values.filter(Boolean).forEach((value) => {
const span = document.createElement("span");
span.textContent = value;
parent.append(span);
});
}
function renderSpeech(speech) {
const article = document.createElement("article");
article.className = "speech-result";
const meta = document.createElement("div");
meta.className = "speech-result-meta";
appendMeta(meta, [speech.year, speech.speaker]);
const title = document.createElement("h2");
title.className = "speech-result-title";
function buildResult(speech) {
const link = document.createElement("a");
link.className = "speech-result";
link.href = speech.url;
link.textContent = speech.title;
title.append(link);
link.dataset.speechId = speech.id;
if (speech.id === selectedId) {
link.classList.add("is-selected");
link.setAttribute("aria-current", "true");
}
const excerpt = document.createElement("p");
const topline = document.createElement("span");
topline.className = "speech-result-topline";
const year = document.createElement("span");
year.className = "speech-result-year";
year.textContent = speech.year;
const speaker = document.createElement("span");
speaker.textContent = speech.speaker;
topline.append(year, speaker);
const title = document.createElement("strong");
title.className = "speech-result-title";
title.textContent = speech.title;
const excerpt = document.createElement("span");
excerpt.className = "speech-result-excerpt";
excerpt.textContent = speech.excerpt;
article.append(meta, title, excerpt);
return article;
link.append(topline, title, excerpt);
return link;
}
function render() {
const filters = selectedFilters();
const candidateIds = searchCandidates(filters.q);
const matched = speeches.filter((speech, index) => {
if (candidateIds && !candidateIds.has(index)) {
return false;
}
return matchesSpeechMetadata(speech, filters);
});
function renderResults() {
const shown = filteredSpeeches.slice(0, visibleLimit);
const fragment = document.createDocumentFragment();
if (matched.length) {
matched.forEach((speech) => fragment.append(renderSpeech(speech)));
if (shown.length) {
shown.forEach((speech) => fragment.append(buildResult(speech)));
} else {
const empty = document.createElement("p");
empty.className = "speech-empty-state";
@ -261,22 +378,144 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
}
results.replaceChildren(fragment);
count.textContent = matched.length.toString();
resultsStatus.textContent = filteredSpeeches.length
? `Showing ${shown.length} of ${filteredSpeeches.length}`
: "No results";
loadMoreButton.hidden = shown.length >= filteredSpeeches.length;
if (!loadMoreButton.hidden) {
const remaining = filteredSpeeches.length - shown.length;
loadMoreButton.textContent = `Show ${Math.min(18, remaining)} more`;
}
}
function renderDetail() {
const selectedIndex = filteredSpeeches.findIndex((speech) => speech.id === selectedId);
const speech = filteredSpeeches[selectedIndex];
if (!speech) {
detail.classList.add("is-empty");
detailPosition.textContent = "No selection";
detailTitle.textContent = "Choose a speech";
detailMeta.textContent = "";
detailExcerpt.textContent = "Select a result to see its details here.";
detailLink.hidden = true;
previousButton.disabled = true;
nextButton.disabled = true;
return;
}
detail.classList.remove("is-empty");
detailPosition.textContent = `${selectedIndex + 1} of ${filteredSpeeches.length}`;
detailTitle.textContent = speech.title;
detailMeta.textContent = `${speech.year} · ${speech.speaker}`;
detailExcerpt.textContent = speech.excerpt;
detailLink.href = speech.url;
detailLink.hidden = false;
previousButton.disabled = selectedIndex <= 0;
nextButton.disabled = selectedIndex >= filteredSpeeches.length - 1;
}
function renderChart(contextSpeeches, filters) {
const counts = new Map();
contextSpeeches.forEach((speech) => counts.set(speech.year, (counts.get(speech.year) || 0) + 1));
const chartYears = Array.from(new Set(speeches.map((speech) => speech.year)))
.filter((year) => !filters.decade || `${Math.floor(Number.parseInt(year, 10) / 10) * 10}` === filters.decade)
.sort();
const maxCount = Math.max(1, ...chartYears.map((year) => counts.get(year) || 0));
const fragment = document.createDocumentFragment();
chart.style.setProperty("--speech-year-columns", chartYears.length.toString());
chartYears.forEach((year, index) => {
const count = counts.get(year) || 0;
const height = count ? Math.max(3, Math.round((count / maxCount) * 100)) : 0;
const button = document.createElement("button");
button.type = "button";
button.className = "speech-year-button";
button.dataset.year = year;
button.dataset.chartLabel = `${year}: ${count} ${count === 1 ? "speech" : "speeches"}`;
button.style.setProperty("--speech-bar-height", `${height}%`);
button.setAttribute("aria-label", button.dataset.chartLabel);
button.setAttribute("aria-pressed", String(filters.year === year));
button.disabled = count === 0;
const bar = document.createElement("span");
bar.className = "speech-year-bar";
bar.setAttribute("aria-hidden", "true");
button.append(bar);
const showTick = index === 0 || index === chartYears.length - 1 || Number.parseInt(year, 10) % 5 === 0;
if (showTick) {
const tick = document.createElement("span");
tick.className = "speech-year-tick";
tick.setAttribute("aria-hidden", "true");
tick.textContent = year;
button.append(tick);
}
fragment.append(button);
});
chart.replaceChildren(fragment);
if (filters.year) {
const count = counts.get(filters.year) || 0;
chartSummary.textContent = `${count} ${count === 1 ? "speech" : "speeches"} in ${filters.year}`;
} else {
chartSummary.textContent = `${contextSpeeches.length} ${contextSpeeches.length === 1 ? "speech" : "speeches"} across ${chartYears.length} years`;
}
}
function render(options = {}) {
const filters = selectedFilters();
const normalizedQuery = normalize(filters.q);
const candidateIds = filters.q ? searchCandidates(filters.q) : null;
const contextSpeeches = speeches.filter((speech, index) => {
if (candidateIds && !candidateIds.has(index)) return false;
if (filters.q && !candidateIds && !normalize(`${speech.title} ${speech.excerpt}`).includes(normalizedQuery)) return false;
return matchesMetadata(speech, filters);
});
filteredSpeeches = filters.year
? contextSpeeches.filter((speech) => speech.year === filters.year)
: contextSpeeches;
if (!filteredSpeeches.some((speech) => speech.id === selectedId)) {
selectedId = filteredSpeeches[0]?.id || "";
}
renderChart(contextSpeeches, filters);
renderResults();
renderDetail();
syncUrl(filters);
if (options.focusSelected) {
results.querySelector(`[data-speech-id="${CSS.escape(selectedId)}"]`)?.focus();
}
}
function queueRender() {
window.clearTimeout(renderTimer);
visibleLimit = 18;
selectedId = "";
renderTimer = window.setTimeout(render, 120);
}
function selectByOffset(offset) {
const currentIndex = filteredSpeeches.findIndex((speech) => speech.id === selectedId);
const nextIndex = Math.max(0, Math.min(filteredSpeeches.length - 1, currentIndex + offset));
const nextSpeech = filteredSpeeches[nextIndex];
if (!nextSpeech) return;
selectedId = nextSpeech.id;
if (nextIndex >= visibleLimit) visibleLimit = nextIndex + 1;
renderResults();
renderDetail();
syncUrl(selectedFilters());
}
hydrateFromUrl();
fetch("/speeches/search-index.json")
.then((response) => {
if (!response.ok) {
throw new Error(`Speech index request failed: ${response.status}`);
}
if (!response.ok) throw new Error(`Speech index request failed: ${response.status}`);
return response.json();
})
.then((data) => {
@ -284,15 +523,69 @@ const speakers = uniqueSorted(speeches.map((speech) => speech.speaker));
searchIndex = Array.isArray(data) ? {} : data.index ?? {};
searchTerms = Object.keys(searchIndex);
termCache.clear();
explorer.classList.add("is-ready");
message.textContent = "Full-text search ready.";
render();
form.addEventListener("input", queueRender);
form.addEventListener("change", render);
form.addEventListener("reset", () => {
window.setTimeout(render, 0);
form.addEventListener("change", (event) => {
if (event.target === yearSelect && yearSelect.value) {
decadeSelect.value = speechDecade({ year: yearSelect.value });
}
if (event.target === decadeSelect && yearSelect.value && speechDecade({ year: yearSelect.value }) !== decadeSelect.value) {
yearSelect.value = "";
}
visibleLimit = 18;
selectedId = "";
render();
});
form.addEventListener("submit", (event) => {
event.preventDefault();
visibleLimit = 18;
selectedId = "";
render();
});
form.addEventListener("reset", () => {
window.setTimeout(() => {
visibleLimit = 18;
selectedId = "";
render();
searchInput.focus();
}, 0);
});
chart.addEventListener("click", (event) => {
const button = event.target.closest("[data-year]");
if (!button || button.disabled) return;
const year = button.dataset.year;
yearSelect.value = yearSelect.value === year ? "" : year;
if (yearSelect.value) decadeSelect.value = speechDecade({ year });
visibleLimit = 18;
selectedId = "";
render();
});
results.addEventListener("click", (event) => {
const link = event.target.closest("[data-speech-id]");
if (!link || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
event.preventDefault();
selectedId = link.dataset.speechId;
renderResults();
renderDetail();
syncUrl(selectedFilters());
});
loadMoreButton.addEventListener("click", () => {
visibleLimit += 18;
renderResults();
});
previousButton.addEventListener("click", () => selectByOffset(-1));
nextButton.addEventListener("click", () => selectByOffset(1));
})
.catch(() => {
count.textContent = results.querySelectorAll(".speech-result").length.toString();
message.textContent = "Full-text search is unavailable. The latest archive links are still available below.";
message.classList.add("is-error");
loadMoreButton.hidden = true;
});
})();
</script>