diff --git a/assets/style.css b/assets/style.css index 2c56b2d..6bdfe3b 100644 --- a/assets/style.css +++ b/assets/style.css @@ -15,7 +15,7 @@ p { color: #ffffff; display: flex; flex-direction: column; - gap: 2rem; + gap: 1rem; justify-content: center; align-items: center; width: 1050px; @@ -104,6 +104,10 @@ p { font-size: 2.5rem; color: #6d728f; } +.commit .repo-name { + font-size: 2.5rem; + color: #6d728f; +} .repo .repo-name { font-weight: 800; @@ -140,6 +144,10 @@ p { width: 100%; } +.info-line:last-child { + margin-top: 1rem; +} + .info-line .author { color: #ffffff; font-weight: 700; diff --git a/server.js b/server.js index a7ed982..014760a 100644 --- a/server.js +++ b/server.js @@ -74,6 +74,53 @@ app.get('/:owner/:repo', async function (req, res) { res.send(await render(html)) }) +app.get('/:owner/:repo/commit/:hash', async function (req, res) { + const commitResp = await fetch( + `${forgejoBaseUrl}/api/v1/repos/${encodeURIComponent( + req.params.owner + )}/${encodeURIComponent(req.params.repo)}/git/commits/${encodeURIComponent( + req.params.hash + )}` + ) + if (!commitResp.ok) { + res.status(commitResp.status) + res.end() + return + } + const commit = await commitResp.json() + let languages = {} + const languagesResp = await fetch( + `${forgejoBaseUrl}/api/v1/repos/${encodeURIComponent( + req.params.owner + )}/${encodeURIComponent(req.params.repo)}/languages` + ) + if (languagesResp.ok) { + languages = getLanguagePercentages(await languagesResp.json()) + } + const html = await eta.renderAsync('commit', { + commit: { + ...commit.commit, + sha: commit.sha, + repository: { + full_name: `${req.params.owner}/${req.params.repo}` + }, + committer: commit.committer, + stats: commit.stats, + created_at: commit.created + }, + languages, + languageColors, + debug + }) + if (debug) { + res.send(await renderHtml(html)) + return + } + res.type('png') + res.set('Content-Disposition', 'inline') + res.send(await render(html)) +}) + app.get('/:owner/:repo/issue/:num', async function (req, res) { const issueResp = await fetch( `${forgejoBaseUrl}/api/v1/repos/${encodeURIComponent( diff --git a/views/commit.eta b/views/commit.eta new file mode 100644 index 0000000..4c7a532 --- /dev/null +++ b/views/commit.eta @@ -0,0 +1,39 @@ +<% layout('layout') %> +<% + let title = it.commit.message.split('\n')[0] + let body = it.commit.message.split('\n').slice(1).join('\n').trim() + const titleCharLimit = 50 + if (title.length > titleCharLimit) { + title = title.slice(0, titleCharLimit).trim() + '...' + } +%> +
+
+
+

@<%= it.commit.repository.full_name %>

+

<%= title %>

+ <% if (body) { %> +

+ <%= body %> +

+ <% } %> +
+
+ +
+
+
+

<%= it.commit.stats.total %> lines changed

+

+ +<%= it.commit.stats.additions %> + -<%= it.commit.stats.deletions %> +

+
+
+ +

<%= it.commit.committer.full_name || it.commit.committer.login %>

+

committed <%= new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(new Date(it.commit.created_at)) %>

+

ยท

+

<%= it.commit.sha.slice(0, 7) %>

+
+
\ No newline at end of file