Convert commit.ts to a mithril template

7d2ffa80003d332bc0d6f4a4ab41aa34b5b50bb4

Tucker McKnight | Sun Jan 25 2026

Convert commit.ts to a mithril template
js_templates/commit.ts:1
Before
1
After
1
import m from 'mithril'
import render from 'mithril-node-render'
js_templates/commit.ts:10
Before
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
  return `
    <div class="row">
      <div class="col-auto">
        <div class="bezel-secondary px-3 py-2">
          &lt;h1 class="fs-2">${data.patchInfo.commit.message.split('\n')[0]}</h2>
          &lt;div class="input-group mb-2 flex-nowrap">
            &lt;span class="font-monospace input-group-text border-info text-white text-bg-dark overflow-scroll">${data.patchInfo.commit.hash}</span>
            &lt;button data-copy-text='${data.patchInfo.commit.hash}' class="btn btn-info shadow-none copy-button"&gt;Copy&lt;/button>
          </div>
          &lt;p&gt;${data.patchInfo.commit.author} | ${date(data.patchInfo.commit.date)}</p>
          &lt;pre class="mb-0">${data.patchInfo.commit.message}</pre>
        </div>
      </div>
    </div>
    &lt;div class="row my-4">
      &lt;div class="col-auto">
        &lt;div class="form-check">
          &lt;input class="form-check-input" type="radio" name="unified" id="splitModeSwitch" value="split" onchange="toggleUnifiedMode(this)" checked>
          &lt;label class="form-check-label" for="splitModeSwitch"&gt;
            Side-by-side
          &lt;/label>
        </div>
        &lt;div class="form-check">
          &lt;input class="form-check-input" type="radio" name="unified" id="unifiedModeSwitch" value="unified" onchange="toggleUnifiedMode(this)">
          &lt;label class="form-check-label" for="unifiedModeSwitch"&gt;
            Stacked
          &lt;/label>
        </div>
      </div>
    </div>
    &lt;div class="row" id="diffs">
      ${data.patchInfo.commit.diffs.map((hunk) => {
        return `
          &lt;div class=hunk&gt;
            &lt;span class="font-monospace fw-bold"&gt;&lt;a href="${data.reposPath}/${slugify(data.patchInfo.repoName)}/branches/${slugify(data.patchInfo.branchName)}/files/${hunk.fileName.split('/').map((filePart) => { return filePart.split('.').map((subpart) => { return slugify(subpart)}).join('.')}).join('/')}.html">${hunk.fileName}:${hunk.lineNumber}</a></span>
            &lt;div class="diff d-flex">
              &lt;div class="flex-grow-1 diff-left pe-2">
                &lt;span class='font-monospace text-secondary'&gt;Before&lt;/span>
                &lt;div class="row">
                  &lt;div class="col-auto border-end"&gt;&lt;pre class="mb-0">
${lineNumbers(hunk.beforeText).map((lineNumber) => {
  return (lineNumber + hunk.lineNumber - 1).toString()
}).join('\n')}</pre></div>
                  <div class="col overflow-scroll">
                    &lt;pre class="mb-0" data-start=&quot;${hunk.lineNumber}&quot;&gt;&lt;code data-type=&quot;before&quot; class="line-numbers language-${languageExtension(hunk.fileName, data.patchInfo.repoName)}">${hunk.beforeText}</code></pre>
                  </div>
                </div>
              &lt;/div&gt;
              <div class="diff-right flex-grow-1">
                &lt;span class='font-monospace text-secondary'&gt;After&lt;/span>
                &lt;div class="row">
                  &lt;div class="col-auto border-end"&gt;&lt;pre class="mb-0">
${lineNumbers(hunk.beforeText).map((lineNumber) => {
  return (lineNumber + hunk.lineNumber - 1).toString()
}).join('\n')}</pre></div>
                  <div class="col overflow-scroll">
                    &lt;pre class="mb-0" data-start=&quot;${hunk.lineNumber}&quot;&gt;&lt;code data-type="after" class="line-numbers language-${languageExtension(hunk.fileName, data.patchInfo.repoName)}">${hunk.afterText}</code></pre>
                  </div>
                </div>
              </div>
            </div>
          </div>
        `
      }).join('')}
    </div>

    <script>
      const toggleUnifiedMode = (e) => {
        const diffs = document.getElementById('diffs')
        const afterDiffs = document.querySelectorAll('.diff-right')
        if (e.value == "unified") {
          diffs.classList.add("unified")
        }
        else {
          diffs.classList.remove("unified")
        }
      }
    </script>
  `
After
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
  return render([
    m(&#39;div', {class: "row"},
      m(&#39;div', {class: "col-auto"},
        m(&#39;div', {class: "bezel-secondary px-3 py-2"}, [
          m(&#39;h1', {class: "fs-2"}, data.patchInfo.commit.message.split('\n')[0]),
          m(&#39;div', {class: "input-group mb-2 flex-nowrap"}, [
            m(&#39;span', {class: "font-monospace input-group-text border-info text-white text-bg-dark overflow-scroll"}, data.patchInfo.commit.hash),
            m(&#39;button', {'data-copy-text': data.patchInfo.commit.hash, class: "btn btn-info shadow-none copy-button"}, &#39;Copy&#39;)
          ]),
          m(&#39;p&#39;, `${data.patchInfo.commit.author} | ${date(data.patchInfo.commit.date)}`),
          m(&#39;pre', {class: "mb-0"}, data.patchInfo.commit.message)
        ])
      )
    ),
    m(&#39;div', {class: "row my-4"},
      m(&#39;div', {class: "col-auto"}, [
        m(&#39;div', {class: "form-check"}, [
          m(&#39;input', {
            class: "form-check-input",
            type: "radio",
            name: "unified",
            id: "splitModeSwitch",
            value: "split",
            onchange: "toggleUnifiedMode(this)",
            checked: true,
          }),
          m(&#39;label', {class: "form-check-label", for: "splitModeSwitch"}, &#39;Side-by-side&#39;),
        ]),
        m(&#39;div', {class: "form-check"}, [
          m(&#39;input', {
            class: "form-check-input",
            type: "radio",
            name: "unified",
            id: "unifiedModeSwitch",
            value: "unified",
            onchange: "toggleUnifiedMode(this)",
          }),
          m(&#39;label', {class: "form-check-label", for: "unifiedModeSwitch"}, &#39;Stacked&#39;)
        ])
      ])
    ),
    m(&#39;div', {class: "row", id: "diffs"}, data.patchInfo.commit.diffs.map((hunk) => {
      return m(&#39;div', {class: 'hunk&#39;}, [
        m(&#39;span', {class: "font-monospace fw-bold"},
          m(&#39;a&#39;, {
            href: `${data.reposPath}/${slugify(data.patchInfo.repoName)}/branches/${slugify(data.patchInfo.branchName)}/files/${hunk.fileName.split('/').map((filePart) => { return filePart.split('.').map((subpart) => { return slugify(subpart)}).join('.')}).join('/')}.html`
          }, `${hunk.fileName}:${hunk.lineNumber}`)
        ),
        m(&#39;div', {class: "diff d-flex"}, [
          m(&#39;div', {class: "flex-grow-1 diff-left pe-2"}, [
            m(&#39;span', {class: 'font-monospace text-secondary'}, &#39;Before&#39;),
            m(&#39;div', {class: "row"}, [
              m(&#39;div', {class: "col-auto border-end"}, m(&#39;pre&#39;, {class: "mb-0"}, lineNumbers(hunk.beforeText).map((lineNumber) => {
                return (lineNumber + hunk.lineNumber - 1).toString()
              }))),
              m('div', {class: "col overflow-scroll"},
                m(&#39;pre', {class: "mb-0", 'data-start&#39;: hunk.lineNumber}, m(&#39;code&#39;, {&#39;data-type&#39;: 'before&#39;, class: `line-numbers language-${languageExtension(hunk.fileName, data.patchInfo.repoName)}`}, hunk.beforeText))
              )
            ])
          ]),
          m(&#39;div&#39;, {class: "diff-right flex-grow-1"}, [
            m(&#39;span', {class: 'font-monospace text-secondary'}, &#39;After&#39;),
            m(&#39;div', {class: "row"},
              m(&#39;div', {class: "col-auto border-end"}, m(&#39;pre&#39;, {class: "mb-0"}, lineNumbers(hunk.beforeText).map((lineNumber) => {
                  return (lineNumber + hunk.lineNumber - 1).toString()
              }))),
              m('div', {class: "col overflow-scroll"},
                m(&#39;pre', {class: "mb-0", 'data-start&#39;: hunk.lineNumber},
                  m(&#39;code&#39;, {&#39;data-type&#39;: &quot;after", class: `line-numbers language-${languageExtension(hunk.fileName, data.patchInfo.repoName)}`}, hunk.afterText)
                )
              )
            )
          ])
        ])
      ])
    })),
    m('script', m.trust(`
const toggleUnifiedMode = (e) => {
  const diffs = document.getElementById('diffs')
  const afterDiffs = document.querySelectorAll('.diff-right')
  if (e.value == "unified") {
    diffs.classList.add("unified")
  }
  else {
    diffs.classList.remove("unified")
  }
}
`)
    )
  ])