Convert feed.ts to a mithril template

a8328f90f7a84456456190f7501f41f4ce61a09c

Tucker McKnight | Sun Jan 25 2026

Convert feed.ts to a mithril template
js_templates/feed.ts:1
Before
1
After
1
import m from 'mithril'
import render from 'mithril-node-render'
js_templates/feed.ts:15
Before
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    return `<?xml version="1.0" encoding="utf-8"?>
&lt;feed xmlns="http://www.w3.org/2005/Atom">
&lt;title&gt;Latest patches in ${branch.branchName}</title>
<link href="${ data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits.xml'}" rel="self" />
<link href="${data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName)}" />
&lt;updated&gt;${dateToRfc3339(currentRepo.commits.get(currentBranch.head).date)}</updated>
&lt;id&gt;${data.reposConfig.baseUrl}</id>
  &lt;author&gt;
    &lt;name&gt;${_.escape(currentRepo.name)} contributors</name>
  </author>
  ${currentBranchCommits.map((commit) => {
    const commitUrl = data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits/' + commit.commit.hash
  return `&lt;entry&gt;
    &lt;title&gt;${_.escape(commit.commit.message.split('\n')[0])}</title>
    &lt;author&gt;&lt;name&gt;${_.escape(commit.commit.author)}</name></author>
    <link href="${commitUrl}" />
    &lt;updated&gt;${dateToRfc3339(commit.commit.date)}</updated>
    &lt;id&gt;${commitUrl}</id>
    &lt;content type="text">${_.escape(commit.commit.message)}</content>
  </entry>`
  })}
</feed>`
After
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    return render([
      m.trust(&#39;&lt;?xml version="1.0" encoding="utf-8"?>'),
      m(&#39;feed', {xmlns: "http://www.w3.org/2005/Atom"}, [
        m(&#39;title&#39;, `Latest patches in ${branch.branchName}`),
        m.trust(`<link href="${ data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits.xml'}" rel="self" />`),
        m.trust(`<link href="${data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName)}" />`),
        m(&#39;updated&#39;, dateToRfc3339(currentRepo.commits.get(currentBranch.head).date)),
        m(&#39;id&#39;, data.reposConfig.baseUrl),
        m(&#39;author&#39;,
          m(&#39;name&#39;, `${_.escape(currentRepo.name)} contributors`)
        ),
        currentBranchCommits.map((commit) => {
          const commitUrl = data.reposConfig.baseUrl + '/repos/' + slugify(branch.repoName) + '/branches/' + slugify(branch.branchName) + '/commits/' + commit.commit.hash
          return m(&#39;entry&#39;, [
            m(&#39;title&#39;, _.escape(commit.commit.message.split('\n')[0])),
            m(&#39;author&#39;, m(&#39;name&#39;, _.escape(commit.commit.author))),
            m.trust(`<link href="${commitUrl}" />`),
            m(&#39;updated&#39;, dateToRfc3339(commit.commit.date)),
            m(&#39;id&#39;, commitUrl),
            m(&#39;content', {type: "text"}, _.escape(commit.commit.message)),
          ])
        })
      ])
    ])