diff --git a/lib/hash.js b/lib/hash.js new file mode 100644 index 0000000..1ec5a0f --- /dev/null +++ b/lib/hash.js @@ -0,0 +1,5 @@ +import { createHash } from 'node:crypto' + +export default function hash(string) { + return createHash('md5').update(string).digest().toString('hex') +} diff --git a/server.js b/server.js index 2a62ca5..d218c60 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,7 @@ import { Eta } from 'eta' import render, { renderHtml } from './lib/render.js' import languageColors from './lib/languagecolors.js' import fetch from 'node-fetch' +import hash from './lib/hash.js' // satori is using the native fetch api, causing a warning, so make node-fetch the default globalThis.fetch = fetch @@ -109,7 +110,12 @@ app.get('/:owner/:repo/commit/:hash', async function (req, res) { repository: { full_name: `${req.params.owner}/${req.params.repo}` }, - committer: commit.committer, + committer: commit.committer ?? { + ...commit.commit.author, + avatar_url: `${forgejoBaseUrl}/avatar/${hash( + commit.commit.author.email.toLowerCase() + )}` + }, stats: commit.stats, created_at: commit.created }, diff --git a/views/commit.eta b/views/commit.eta index c5275d4..eeb984d 100644 --- a/views/commit.eta +++ b/views/commit.eta @@ -25,7 +25,7 @@ <%~ include('partials/commit-stats.eta', {stats: it.commit.stats}) %>
-

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

+

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

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

<%~ include('icons/code-commit.eta') %>

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