-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
306 lines (276 loc) · 8.13 KB
/
Copy pathapp.js
File metadata and controls
306 lines (276 loc) · 8.13 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
const articles = [
{
title: "Home",
file: "./wiki/Home.md",
summary: "Top-level field manual and article index."
},
{
title: "Project Overview",
file: "./wiki/Project-Overview.md",
summary: "Defines the project in one pass: what it is, what it is not, and why it exists."
},
{
title: "Brand and Lore",
file: "./wiki/Brand-and-Lore.md",
summary: "Voice, visuals, taglines, and the thin layer of myth that makes the meme reusable."
},
{
title: "Tokenomics",
file: "./wiki/Tokenomics.md",
summary: "Simple structure, visible allocations, and no detective-board token design."
},
{
title: "Launch Plan",
file: "./wiki/Launch-Plan.md",
summary: "Funny on the outside, disciplined on the inside."
},
{
title: "Community and Content",
file: "./wiki/Community-and-Content.md",
summary: "Content loops, community mechanics, and the assets that make the joke travel."
},
{
title: "Risk and Transparency",
file: "./wiki/Risk-and-Transparency.md",
summary: "Disclosure standards and the lines the project should not cross."
},
{
title: "FAQ",
file: "./wiki/FAQ.md",
summary: "Short answers for the obvious questions people will ask first."
},
{
title: "Glossary",
file: "./wiki/Glossary.md",
summary: "Plain-language definitions for the terms people pretend everyone knows."
},
{
title: "Roadmap",
file: "./wiki/Roadmap.md",
summary: "A narrow roadmap that only contains things worth saying out loud."
}
];
const featuredArticles = [
{
title: "Brand and Lore",
file: "./wiki/Brand-and-Lore.md",
tag: "Identity Engine",
summary: "The page that explains why the monkey reads instantly and why the hat is not optional.",
bullets: [
"Voice and taglines that can survive repost culture",
"A lore model that stays thin instead of turning into nonsense",
"Visual rules for making the meme repeatable"
]
},
{
title: "Tokenomics",
file: "./wiki/Tokenomics.md",
tag: "Trust Layer",
summary: "The page that keeps the project from developing detective-board economics and mystery wallets.",
bullets: [
"Simple allocation model",
"Public controls and permissions checklist",
"A short list of trust-killing mistakes to avoid"
]
},
{
title: "Risk and Transparency",
file: "./wiki/Risk-and-Transparency.md",
tag: "Reality Check",
summary: "The page that draws the line between a funny project and dishonest messaging.",
bullets: [
"Plain-language risk statement",
"Rules for official links and corrections",
"Messaging that should never ship"
]
}
];
const articleGrid = document.querySelector("#article-grid");
const articleList = document.querySelector("#article-list");
const articleTitle = document.querySelector("#article-title");
const articleContent = document.querySelector("#article-content");
const featureGrid = document.querySelector("#feature-grid");
function escapeHtml(value) {
return value
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """)
.replaceAll("'", "'");
}
function inlineMarkdown(text) {
return escapeHtml(text)
.replace(/`([^`]+)`/g, "<code>$1</code>")
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
}
function markdownToHtml(markdown) {
const lines = markdown.split(/\r?\n/);
let html = "";
let inUl = false;
let inOl = false;
let inBlockquote = false;
function closeLists() {
if (inUl) {
html += "</ul>";
inUl = false;
}
if (inOl) {
html += "</ol>";
inOl = false;
}
}
function closeBlockquote() {
if (inBlockquote) {
html += "</blockquote>";
inBlockquote = false;
}
}
for (const line of lines) {
if (!line.trim()) {
closeLists();
closeBlockquote();
continue;
}
if (line.startsWith("### ")) {
closeLists();
closeBlockquote();
html += `<h3>${inlineMarkdown(line.slice(4))}</h3>`;
continue;
}
if (line.startsWith("## ")) {
closeLists();
closeBlockquote();
html += `<h2>${inlineMarkdown(line.slice(3))}</h2>`;
continue;
}
if (line.startsWith("# ")) {
closeLists();
closeBlockquote();
html += `<h1>${inlineMarkdown(line.slice(2))}</h1>`;
continue;
}
if (line.startsWith("> ")) {
closeLists();
if (!inBlockquote) {
html += "<blockquote>";
inBlockquote = true;
}
html += `<p>${inlineMarkdown(line.slice(2))}</p>`;
continue;
}
const orderedMatch = line.match(/^\d+\.\s+(.*)$/);
if (orderedMatch) {
closeBlockquote();
if (!inOl) {
closeLists();
html += "<ol>";
inOl = true;
}
html += `<li>${inlineMarkdown(orderedMatch[1])}</li>`;
continue;
}
const unorderedMatch = line.match(/^-\s+(.*)$/);
if (unorderedMatch) {
closeBlockquote();
if (!inUl) {
closeLists();
html += "<ul>";
inUl = true;
}
html += `<li>${inlineMarkdown(unorderedMatch[1])}</li>`;
continue;
}
closeLists();
closeBlockquote();
html += `<p>${inlineMarkdown(line)}</p>`;
}
closeLists();
closeBlockquote();
return html;
}
function renderCards() {
articleGrid.innerHTML = articles
.map(
(article) => `
<article>
<h3>${article.title}</h3>
<p>${article.summary}</p>
<a href="#wiki-browser" data-file="${article.file}">Read article</a>
</article>
`
)
.join("");
bindLoadArticleTriggers(articleGrid);
}
function renderFeaturedArticles() {
featureGrid.innerHTML = featuredArticles
.map(
(article) => `
<article class="feature-panel">
<span class="feature-panel__tag">${article.tag}</span>
<h3>${article.title}</h3>
<p>${article.summary}</p>
<ul>
${article.bullets.map((bullet) => `<li>${bullet}</li>`).join("")}
</ul>
<div class="feature-panel__actions">
<a class="button button--solid" href="#wiki-browser" data-file="${article.file}">Open in viewer</a>
<a class="button button--ghost" href="${article.file}">Read raw markdown</a>
</div>
</article>
`
)
.join("");
bindLoadArticleTriggers(featureGrid);
}
function bindLoadArticleTriggers(container) {
container.querySelectorAll("[data-file]").forEach((element) => {
element.addEventListener("click", () => {
loadArticle(element.dataset.file);
});
});
}
function renderList() {
articleList.innerHTML = articles
.map(
(article) => `
<button type="button" data-file="${article.file}" aria-pressed="false">
<strong>${article.title}</strong><br />
<span>${article.summary}</span>
</button>
`
)
.join("");
articleList.querySelectorAll("button[data-file]").forEach((button) => {
button.addEventListener("click", () => {
loadArticle(button.dataset.file);
});
});
}
async function loadArticle(file) {
articleList.querySelectorAll("button[data-file]").forEach((button) => {
button.setAttribute("aria-pressed", String(button.dataset.file === file));
});
const current = articles.find((article) => article.file === file);
articleTitle.textContent = current ? current.title : "Article";
articleContent.innerHTML = "<p>Loading article...</p>";
window.history.replaceState({}, "", `#${encodeURIComponent(file)}`);
try {
const response = await fetch(file);
if (!response.ok) {
throw new Error(`Failed to load ${file}`);
}
const markdown = await response.text();
articleContent.innerHTML = markdownToHtml(markdown);
} catch (error) {
articleContent.innerHTML = `<p>Could not load this article. ${escapeHtml(error.message)}</p>`;
}
}
renderCards();
renderFeaturedArticles();
renderList();
const initialHash = window.location.hash ? decodeURIComponent(window.location.hash.slice(1)) : "";
const initialFile = articles.some((article) => article.file === initialHash)
? initialHash
: "./wiki/Home.md";
loadArticle(initialFile);