f432b40 / webui.mjs
diff --git a/webui.mjs b/webui.mjs
index df5a5c9..61e5ff2 100644
--- a/webui.mjs
+++ b/webui.mjs
@@ -149,7 +149,7 @@ ${entriesTable(entries, path)}`
return page(`${path || '/'} - ${name}`, body)
}
-export function blobPage({ name, path, size, text, binary, truncated, shownBytes, tooLarge }) {
+export function blobPage({ name, path, size, text, binary, truncated, shownBytes, tooLarge, commit }) {
let content
if (tooLarge) {
content = `<p>File is too large to show (${size} bytes).</p>`
@@ -159,14 +159,25 @@ export function blobPage({ name, path, size, text, binary, truncated, shownBytes
content = `<pre>${escapeHtml(text)}</pre>`
if (truncated) content += `<p>Showing the first ${shownBytes} bytes of ${size}.</p>`
}
+ const context = commit
+ ? `<p><a href="/commit/${commit.hash}"><code>${shortHash(commit.hash)}</code></a> / ${escapeHtml(path)}</p>`
+ : breadcrumbs(path, true)
const body = `<h1>${escapeHtml(name)}</h1>
-${breadcrumbs(path, true)}
+${context}
<p>${size} bytes</p>
${content}`
return page(`${path} - ${name}`, body)
}
-export function commitPage({ name, commit, stat }) {
+export function commitPage({ name, commit, files }) {
+ const rows = files.map(file => {
+ const count = value => value === null ? '-' : String(value)
+ return `<tr><td><a href="/commit/${commit.hash}/diff/${encodePath(file.path)}">${escapeHtml(file.path)}</a></td><td>${count(file.added)}</td><td>${count(file.removed)}</td></tr>`
+ }).join('\n')
+ const changed = files.length ? `<table>
+<tr><th>File</th><th>Added</th><th>Removed</th></tr>
+${rows}
+</table>` : '<p>No files changed.</p>'
const body = `<h1>${escapeHtml(name)}</h1>
${statusTable([
['Commit', `<code>${escapeHtml(commit.hash)}</code>`],
@@ -176,10 +187,21 @@ ${statusTable([
<h2>Message</h2>
<pre>${escapeHtml(commit.message)}</pre>
<h2>Changed files</h2>
-${stat.trim() ? `<pre>${escapeHtml(stat)}</pre>` : '<p>No files changed.</p>'}`
+${changed}`
return page(`${shortHash(commit.hash)} - ${name}`, body)
}
+export function diffPage({ name, commit, path, text, truncated, shownBytes, hasBlob }) {
+ const blobLink = hasBlob
+ ? `<p><a href="/commit/${commit.hash}/blob/${encodePath(path)}">View file at this commit</a></p>\n`
+ : ''
+ const body = `<h1>${escapeHtml(name)}</h1>
+<p><a href="/commit/${commit.hash}"><code>${shortHash(commit.hash)}</code></a> / ${escapeHtml(path)}</p>
+${blobLink}<pre>${escapeHtml(text)}</pre>
+${truncated ? `<p>Showing the first ${shownBytes} bytes of the diff.</p>` : ''}`
+ return page(`${path} - ${shortHash(commit.hash)} - ${name}`, body)
+}
+
export function notFoundPage(name, what) {
const body = `<h1>Not found</h1>
<p>${escapeHtml(what)} does not exist in this repository.</p>`
Git ยท Social feed