-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (157 loc) · 8.03 KB
/
script.js
File metadata and controls
175 lines (157 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const stories = [
{
topic: "government",
tag: "Civic Life",
title: "How County Government Took Shape",
body: "Frederick County's civic institutions grew out of colonial courthouse culture and expanded through the 19th and 20th centuries as population and services increased. The same public questions seen today about growth, schools, and infrastructure were already present in earlier debates over roads, taxation, and representation.",
linkage: "Current-event link: Government meetings and policy updates echo the county's long tradition of local decision-making."
},
{
topic: "transport",
tag: "Roads & Rail",
title: "Frederick as a Crossroads",
body: "Frederick developed as a strategic crossroads between the Chesapeake region and the interior. Turnpikes, rail links, and later highways made the county central to trade and military movement. That transportation legacy still defines commuter patterns and regional business.",
linkage: "Current-event link: Transportation projects and traffic discussions continue a centuries-old crossroads story."
},
{
topic: "agriculture",
tag: "Farm Heritage",
title: "Fields, Markets, and County Identity",
body: "Agriculture has long anchored Frederick County's economy. Grain, dairy, and livestock operations connected local farms with urban markets, while rural communities shaped social and political life. Even with modern industry, farmland remains part of county identity.",
linkage: "Current-event link: Coverage of farm policy, land use, or food systems connects directly to this heritage."
},
{
topic: "war",
tag: "Civil War Era",
title: "The Battle of Monocacy in Context",
body: "In July 1864, Union and Confederate forces clashed near Frederick in the Battle of Monocacy. Though Union troops were pushed back, the fight delayed Confederate progress toward Washington. Historians often note the battle's strategic impact despite its local destruction.",
linkage: "Current-event link: National conversations about military memory and public history often return to Monocacy's legacy."
},
{
topic: "health",
tag: "Public Health",
title: "From Frontier Medicine to Modern Care",
body: "Frederick's health systems evolved from small local practices and charitable institutions into modern hospitals and research-linked care. Epidemics, sanitation improvements, and changing demographics repeatedly pushed the county to redesign public health response.",
linkage: "Current-event link: Health alerts and hospital updates mirror recurring historical challenges in public health planning."
},
{
topic: "education",
tag: "Schools & Learning",
title: "Education Across Generations",
body: "County education grew from church and community-led schooling into a broad public system. Expansion reflected shifts in population, industrial needs, and civic expectations. Educational change in Frederick has consistently tracked social and economic change.",
linkage: "Current-event link: School board decisions and enrollment news fit into this long educational evolution."
},
{
topic: "environment",
tag: "Land & Water",
title: "Stewardship of Rivers and Ridges",
body: "Frederick County's geography, from river systems to mountain edges, shaped settlement and industry while creating long-term conservation challenges. Flood risk, watershed management, and land preservation are not new concerns but recurring regional themes.",
linkage: "Current-event link: Weather events, conservation planning, and land debates continue this environmental history."
},
{
topic: "economy",
tag: "Work & Industry",
title: "From Market Town to Mixed Economy",
body: "Frederick transitioned from a market-town economy toward a diverse mix that includes logistics, manufacturing, professional services, and technology. Economic reinvention has happened repeatedly as transportation, war, and policy shifted regional opportunity.",
linkage: "Current-event link: Jobs reports and business openings reflect a long pattern of adaptation in local industry."
}
];
const topicKeywords = {
government: ["council", "county", "city hall", "policy", "election", "budget", "board", "zoning"],
transport: ["traffic", "road", "highway", "transit", "bridge", "rail", "commute", "construction"],
agriculture: ["farm", "agriculture", "soil", "harvest", "dairy", "food", "market"],
war: ["veteran", "military", "war", "battle", "memorial", "defense"],
health: ["health", "hospital", "clinic", "virus", "public health", "medical"],
education: ["school", "student", "teacher", "education", "college", "campus"],
environment: ["climate", "storm", "flood", "river", "water", "environment", "park", "conservation"],
economy: ["jobs", "business", "economy", "employment", "development", "housing", "industry"]
};
function dayOfYear(date) {
const start = new Date(date.getFullYear(), 0, 0);
const diff = date - start;
const oneDay = 1000 * 60 * 60 * 24;
return Math.floor(diff / oneDay);
}
function pickDeterministicStory() {
const today = new Date();
const index = dayOfYear(today) % stories.length;
return stories[index];
}
function formatDate(date) {
return new Intl.DateTimeFormat("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric"
}).format(date);
}
function getKeywordsText(headline) {
return `${headline.title || ""} ${headline.description || ""}`.toLowerCase();
}
function findTopicFromHeadlines(headlines) {
for (const headline of headlines) {
const text = getKeywordsText(headline);
for (const [topic, words] of Object.entries(topicKeywords)) {
if (words.some((word) => text.includes(word))) {
return { topic, headline: headline.title || "a local headline" };
}
}
}
return null;
}
async function loadHeadlines() {
const endpoints = [
"https://api.allorigins.win/raw?url=" + encodeURIComponent("https://news.google.com/rss/search?q=Frederick+County+Maryland"),
"https://api.allorigins.win/raw?url=" + encodeURIComponent("https://news.google.com/rss/search?q=Maryland+news"),
"https://api.allorigins.win/raw?url=" + encodeURIComponent("https://news.google.com/rss/search?q=United+States+news")
];
for (const url of endpoints) {
try {
const response = await fetch(url, { cache: "no-store" });
if (!response.ok) {
continue;
}
const xml = await response.text();
const doc = new DOMParser().parseFromString(xml, "text/xml");
const items = [...doc.querySelectorAll("item")].slice(0, 8).map((item) => ({
title: item.querySelector("title")?.textContent || "",
description: item.querySelector("description")?.textContent || ""
}));
if (items.length) {
return items;
}
} catch {
// Continue to fallback source.
}
}
return [];
}
function renderStory(story, note) {
const today = new Date();
document.getElementById("story-date").textContent = formatDate(today);
document.getElementById("story-tag").textContent = story.tag;
document.getElementById("story-title").textContent = story.title;
document.getElementById("story-body").textContent = story.body;
document.getElementById("story-linkage").textContent = story.linkage;
document.getElementById("news-note").textContent = note;
}
async function initDailyStory() {
const deterministicStory = pickDeterministicStory();
renderStory(
deterministicStory,
"Using calendar-based daily rotation while checking current headlines for a tighter topical match."
);
const headlines = await loadHeadlines();
const matched = findTopicFromHeadlines(headlines);
if (!matched) {
renderStory(
deterministicStory,
"Live headline matching unavailable right now, so today's Frederick history story is selected from the rotating daily archive."
);
return;
}
const matchedStory = stories.find((story) => story.topic === matched.topic) || deterministicStory;
const note = `Matched to a current headline theme: ${matched.headline}`;
renderStory(matchedStory, note);
}
initDailyStory();