-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc-viewer.js
More file actions
286 lines (252 loc) · 9.28 KB
/
Copy pathdoc-viewer.js
File metadata and controls
286 lines (252 loc) · 9.28 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
(function () {
const capsules = Array.isArray(window.CAPSULES) ? window.CAPSULES : [];
const docs = window.CAPSULE_DOCS || {};
const renderer = window.MarkdownRenderer || {};
const escapeHtml = renderer.escapeHtml || ((value) => String(value ?? ""));
const DOC_TYPES = [
{
slug: "results",
key: "results",
label: "RESULTS",
field: "resultsMarkdown",
availabilityKey: "results",
description: "Run evidence, metrics, and result artifacts.",
sourcePath: (capsule) => capsule.resultsPath
},
{
slug: "readme",
key: "readme",
label: "README",
field: "readmeMarkdown",
availabilityKey: "readme",
description: "Usage, scope, and repository overview.",
sourcePath: (capsule) => capsule.readmePath
},
{
slug: "aqua-prompt",
key: "aquaPrompt",
label: "AQUA PROMPT",
field: "aquaPromptMarkdown",
availabilityKey: "aquaPrompt",
description: "Copy-ready instructions you can paste into Aqua.",
sourcePath: (capsule) => capsule.aquaPromptPath
},
{
slug: "how-to-implement",
key: "howToImplement",
label: "HOW TO IMPLEMENT",
field: "howToImplementMarkdown",
availabilityKey: "howToImplement",
description: "Technical implementation notes and adaptation guidance.",
sourcePath: (capsule) => capsule.howToImplementPath
},
{
slug: "review",
key: "review",
label: "REVIEW",
field: "reviewMarkdown",
availabilityKey: "review",
description: "Independent review summary of the current capsule state.",
sourcePath: (capsule) => capsule.reviewPath
}
];
const titleEl = document.getElementById("doc-title");
const subtitleEl = document.getElementById("doc-subtitle");
const kickerEl = document.getElementById("doc-kicker");
const typePillEl = document.getElementById("doc-type-pill");
const statusPillEl = document.getElementById("doc-status-pill");
const contentEl = document.getElementById("doc-content");
const backLinkEl = document.querySelector(".doc-back");
const atlasLinkEl = document.getElementById("doc-atlas-link");
const sourceLinkEl = document.getElementById("doc-source-link");
const summaryGridEl = document.getElementById("doc-summary-grid");
const docNavEl = document.getElementById("doc-nav");
const artifactsEl = document.getElementById("doc-artifacts");
const pageConfig = window.DOC_PAGE || {};
const params = new URLSearchParams(window.location.search);
const capsuleId = pageConfig.capsuleId || params.get("capsule");
const requestedDocType = pageConfig.docType || params.get("doc") || "readme";
const docType = DOC_TYPES.find((entry) => entry.slug === requestedDocType) || DOC_TYPES[1];
const capsule = capsules.find((item) => item.id === capsuleId);
function statusClass(status) {
if (status === "completed") return "completed";
if (status === "partial") return "partial";
return "blocked";
}
function normalizeRelativePath(value) {
return String(value || "").replace(/^\.\//, "");
}
function getAtlasHref() {
const prefix = pageConfig.atlasPrefix || "./";
return `${prefix}index.html#${capsule.id}`;
}
function getDocsPrefix() {
return pageConfig.docsPrefix || "./docs/";
}
function getAssetPrefix() {
return pageConfig.assetPrefix || "./";
}
function getDocHref(entry) {
return `${getDocsPrefix()}${capsule.id}-${entry.slug}.html`;
}
function getSourceHref() {
const sourcePath = docType.sourcePath(capsule);
return `${getAssetPrefix()}${normalizeRelativePath(sourcePath)}`;
}
function getResultsArtifacts() {
return Array.isArray((docs[capsule.id] || {}).resultsArtifacts)
? (docs[capsule.id] || {}).resultsArtifacts
: [];
}
function getFeaturedArtifacts() {
const artifacts = getResultsArtifacts();
const featuredPaths = Array.isArray(capsule.featuredArtifacts) ? capsule.featuredArtifacts : [];
if (!featuredPaths.length) {
return artifacts.slice(0, 4);
}
return featuredPaths
.map((relativePath) =>
artifacts.find((artifact) => normalizeRelativePath(artifact.path) === normalizeRelativePath(relativePath))
)
.filter(Boolean);
}
function renderList(items) {
if (!Array.isArray(items) || items.length === 0) {
return `<p class="supporting-note">No summary bullets were provided for this capsule.</p>`;
}
return `
<ul class="highlight-list">
${items.map((item) => `<li>${escapeHtml(item)}</li>`).join("")}
</ul>
`;
}
function renderArtifactList(artifacts) {
if (!artifacts.length) {
return `<p class="supporting-note">No result artifacts were indexed for this capsule.</p>`;
}
return `
<ul class="artifact-list compact-artifact-list">
${artifacts
.map(
(artifact) => `
<li class="artifact-item compact">
<div>
<a href="${getAssetPrefix()}${normalizeRelativePath(artifact.path)}">${escapeHtml(artifact.name)}</a>
<p class="artifact-note">${escapeHtml(artifact.path)}</p>
</div>
<div class="artifact-meta">
<span class="artifact-type">${escapeHtml(String(artifact.type).toUpperCase())}</span>
<span class="artifact-size">${escapeHtml(artifact.sizeLabel || "")}</span>
</div>
</li>
`
)
.join("")}
</ul>
`;
}
function renderSummaryCards() {
summaryGridEl.innerHTML = `
<section class="summary-card">
<p class="mini-label">Best for</p>
<p class="summary-card-copy">${escapeHtml(capsule.primaryUseCase || capsule.capsuleSummary)}</p>
</section>
<section class="summary-card">
<p class="mini-label">How to use</p>
<p class="summary-card-copy"><strong>${escapeHtml(capsule.usageMode)}</strong></p>
${renderList(capsule.usageHighlights)}
</section>
<section class="summary-card">
<p class="mini-label">Results snapshot</p>
${renderList(capsule.resultsHighlights)}
</section>
<section class="summary-card">
<p class="mini-label">Primary outputs</p>
${renderList(capsule.outputs)}
</section>
`;
}
function renderDocNav() {
const availability = capsule.docAvailability || {};
docNavEl.innerHTML = DOC_TYPES.filter((entry) => availability[entry.availabilityKey])
.map((entry) => {
const classes = ["doc-nav-link"];
if (entry.slug === docType.slug) {
classes.push("is-current");
}
return `<a class="${classes.join(" ")}" href="${getDocHref(entry)}">${escapeHtml(entry.label)}</a>`;
})
.join("");
}
function renderArtifactsPanel() {
const allArtifacts = getResultsArtifacts();
const featuredArtifacts = getFeaturedArtifacts();
if (docType.slug !== "results" || !artifactsEl) {
return;
}
artifactsEl.hidden = false;
artifactsEl.innerHTML = `
<div class="doc-artifacts-copy">
<p class="section-kicker">Result artifacts</p>
<h2>Open the evidence files that back this capsule</h2>
<p class="supporting-note">
Start with the featured artifacts, then open the full inventory if you need every machine-readable result file.
</p>
</div>
<div class="doc-artifacts-grid">
<section>
<p class="mini-label">Featured artifacts</p>
${renderArtifactList(featuredArtifacts)}
</section>
<section>
<p class="mini-label">All indexed artifacts</p>
${renderArtifactList(allArtifacts)}
</section>
</div>
`;
}
function renderMissingState() {
document.title = "Document not found";
kickerEl.textContent = "Capsule document";
titleEl.textContent = "Document not found";
subtitleEl.textContent = "The requested capsule document could not be loaded.";
typePillEl.textContent = "Missing";
statusPillEl.textContent = "Unavailable";
contentEl.innerHTML = "<p class=\"markdown-empty\">Check the capsule id and document type in the URL.</p>";
if (summaryGridEl) summaryGridEl.innerHTML = "";
if (docNavEl) docNavEl.innerHTML = "";
if (artifactsEl) artifactsEl.hidden = true;
}
if (!capsule || !renderer.renderMarkdown) {
renderMissingState();
return;
}
const capsuleDoc = docs[capsule.id] || {};
const markdown = capsuleDoc[docType.field];
if (!markdown) {
renderMissingState();
return;
}
document.title = `${capsule.title} ${docType.label}`;
kickerEl.textContent = `Challenge ${capsule.number}`;
titleEl.textContent = `${capsule.title} ${docType.label}`;
subtitleEl.textContent = capsule.directory;
typePillEl.textContent = docType.label;
statusPillEl.textContent = capsule.statusLabel;
statusPillEl.classList.add(statusClass(capsule.status));
contentEl.innerHTML = renderer.renderMarkdown(markdown);
if (backLinkEl) {
backLinkEl.href = getAtlasHref();
}
if (atlasLinkEl) {
atlasLinkEl.href = getAtlasHref();
}
if (sourceLinkEl) {
sourceLinkEl.href = getSourceHref();
sourceLinkEl.textContent =
docType.slug === "aqua-prompt" ? "Open raw AQUA_PROMPT.md" : "Open raw source file";
}
renderSummaryCards();
renderDocNav();
renderArtifactsPanel();
})();