Tucker McKnight
Convert commits.ts to a mithril template
1
1
import m from 'mithril'
import render from 'mithril-node-render'
9 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
return `
<div class="row mt-3 mb-1">
<div class="col">
<p class="d-inline-block">Showing commits from <span class="font-monospace me-2">${data.patchPage.branchName}</span><a class="btn btn-outline-primary badge shadow-none" href="${nav.repoCurrentBranchRssFeed()}"><img src="${nav.rootPath()}frontend/img/rss-icon.svg" style="width: 11px; margin-right: 5px;" />RSS</a></p>
</div>
</div>
<nav>
<ul class="pagination">
${pagesJustForBranch(data.paginatedPatches, data.patchPage.repoName, data.patchPage.branchName).map((pageObj) => {
return `
<li class="page-item">
<a class="page-link ${pageObj.pageNumber === data.patchPage.pageNumber ? 'active' : ''}" href="${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${data.patchPage.branchName}/commits/page${pageObj.pageNumber}">${pageObj.pageNumber}</a>
</li>
`
}).join('')}
</ul>
</nav>
<div>
${data.patchPage.commits.map((commit) => {
return `
<div class="bezel-gray p-2 my-2" style="max-width: 40rem;">
<a class="fs-5" href="${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${slugify(data.patchPage.branchName)}/commits/${commit.hash}">
${commit.message.split('\n').slice(0, 1)}
</a>
<br />
<span>${date(commit.date)}</span>
<br />
<span>${commit.author}</span>
<p class="commit-hash font-monospace mb-0">${commit.hash}</p>
</div>
`
}).join('')}
</div>
<nav>
<ul class="pagination">
${pagesJustForBranch(data.paginatedPatches, data.patchPage.repoName, data.patchPage.branchName).map((pageObj) => {
return `
<li class="page-item">
<a class="page-link ${pageObj.pageNumber === data.patchPage.pageNumber ? 'active' : ''}" href="${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${data.patchPage.branchName}/commits/page${pageObj.pageNumber}">${pageObj.pageNumber}</a>
</li>
`
}).join('')}
</ul>
</nav>
`
9 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
return render([
m('div', {class: "row mt-3 mb-1"},
m('div', {class: "col"},
m('p', {class: "d-inline-block"}, [
'Showing commits from ',
m('span', {class: "font-monospace me-2"}, data.patchPage.branchName),
m('a', {
class: "btn btn-outline-primary badge shadow-none",
href: nav.repoCurrentBranchRssFeed()
}, [
m('img', {
src: `${nav.rootPath()}frontend/img/rss-icon.svg`,
style: "width: 11px; margin-right: 5px;"
}),
'RSS',
])
])
)
),
m('nav',
m('ul', {class: "pagination"},
pagesJustForBranch(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.branchName
).map((pageObj) => {
return m('li', {class: "page-item"},
m('a', {
class: `page-link ${pageObj.pageNumber === data.patchPage.pageNumber ? 'active' : ''}`,
href: `${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${data.patchPage.branchName}/commits/page${pageObj.pageNumber}`
}, pageObj.pageNumber)
)
})
)
),
m('div', data.patchPage.commits.map((commit) => {
return m('div', {
class: "bezel-gray p-2 my-2",
style: "max-width: 40rem;"
}, [
m('a', {
class: "fs-5",
href: `${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${slugify(data.patchPage.branchName)}/commits/${commit.hash}`,
}, commit.message.split('\n').slice(0, 1)),
m('br'),
m('span', date(commit.date)),
m('br'),
m('span', commit.author),
m('p', {class: "commit-hash font-monospace mb-0"}, commit.hash),
])
})),
m('nav',
m('ul', {class: "pagination"},
pagesJustForBranch(
data.paginatedPatches,
data.patchPage.repoName,
data.patchPage.branchName
).map((pageObj) => {
return m('li', {class: "page-item"},
m('a', {
class: `page-link ${pageObj.pageNumber === data.patchPage.pageNumber ? 'active' : ''}`,
href: `${data.reposPath}/${slugify(data.patchPage.repoName)}/branches/${data.patchPage.branchName}/commits/page${pageObj.pageNumber}`
}, pageObj.pageNumber)
)
})
)
)
])