Tucker McKnight <tucker.mcknight@gmail.com> | Sun Aug 31 2025
BROKEN HERE, add patches template. Breaks getLocation somehow?
3 4 5 6 7
import repos from './src/repos.ts'
import branches from './src/branches.ts'
import flatFiles from './src/flatFiles.ts'
import {getLocation} from './src/helpers.ts'
import repoOperations from './src/vcses/operations.ts'
3 4 5 6 7 8
import repos from './src/repos.ts'
import branches from './src/branches.ts'
import flatFiles from './src/flatFiles.ts'
import paginatedPatches from './src/paginatedPatches.ts'
import {getLocation} from './src/helpers.ts'
import repoOperations from './src/vcses/operations.ts'
15 16 17 18 19 20 21
const reposData = await repos(reposConfiguration)
const reposPath = reposConfiguration.path || "/repos"
eleventyConfig.addGlobalData("reposPath", reposPath)
eleventyConfig.addFilter("getFileName", (filePath) => {
const pathParts = filePath.split("/")
return pathParts[pathParts.length - 1]15 16 17 18 19 20 21 22 23 24 25 26 27
const reposData = await repos(reposConfiguration)
const reposPath = reposConfiguration.path || "/repos"
eleventyConfig.addGlobalData("repos", reposData)
eleventyConfig.addGlobalData("reposConfig", reposConfiguration)
eleventyConfig.addGlobalData("reposPath", reposPath)
const branchesData = branches(reposData)
eleventyConfig.addGlobalData("branches", branchesData)
eleventyConfig.addFilter("getFileName", (filePath) => {
const pathParts = filePath.split("/")
return pathParts[pathParts.length - 1]170 171 172 173 174
})
eleventyConfig.addAsyncFilter("getReadMe", async (repoName, branchName) => {
const location = getLocation(reposConfiguration, branchName, repoName)
const config = reposConfiguration.repos[repoName]
let command = ''170 171 172 173 174 175 176 177
})
eleventyConfig.addAsyncFilter("getReadMe", async (repoName, branchName) => {
console.log("getreadme")
console.log(branchName)
console.log(repoName)
const location = getLocation(reposConfiguration, branchName, repoName)
const config = reposConfiguration.repos[repoName]
let command = ''204 205 206 207 208 209
// BRANCHES.NJK
const branchesTemplate = fsImport.readFileSync(`${__dirname}/templates/branches.njk`).toString()
const branchesData = branches(reposData)
eleventyConfig.addTemplate(
'repos/branches.njk',
topLayoutPartial + branchesTemplate + bottomLayoutPartial,204 205 206 207 208
// BRANCHES.NJK
const branchesTemplate = fsImport.readFileSync(`${__dirname}/templates/branches.njk`).toString()
eleventyConfig.addTemplate(
'repos/branches.njk',
topLayoutPartial + branchesTemplate + bottomLayoutPartial,294 295 296 297 298
size: 1,
alias: "branch",
},
permalink: (data) => {
const repoName = data.branch.repoName
const branchName = data.branch.branchName294 295 296 297 298 299
size: 1,
alias: "branch",
},
branches: branchesData,
permalink: (data) => {
const repoName = data.branch.repoName
const branchName = data.branch.branchName308 309 310 311 312 313 314
navTab: "landing",
}
)
eleventyConfig.addGlobalData("repos", reposData)
eleventyConfig.addGlobalData("reposConfig", reposConfiguration)
eleventyConfig.addGlobalData("branches", branchesData)
}308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
navTab: "landing",
}
)
// PATCHES.NJK
const patchesTemplate = fsImport.readFileSync(`${__dirname}/templates/patches.njk`).toString()
const paginatedPatchesData = await paginatedPatches(reposData)
eleventyConfig.addTemplate(
`repos/patches.njk`,
topLayoutPartial + repoTemplate + bottomLayoutPartial,
{
pagination: {
data: "paginatedPatches",
size: 1,
alias: "patchPage",
},
paginatedPatches: paginatedPatchesData,
permalink: (data) => {
const repoName = data.patchPage.repoName
const branchName = data.patchPage.branchName
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/patches/page${data.patchPage.pageNumber}`
},
eleventyComputed: {
nav: {
repoName: (data) => data.patchPage.repoName,
branchName: (data) => data.patchPage.branchName,
}
},
navTab: "patches",
}
)
}
-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
let cachedFlatPatches = null
export default async (repos) => {
if (cachedFlatPatches !== null) { return cachedFlatPatches }
cachedFlatPatches = Object.keys(repos).flatMap((repoName) => {
return Object.keys(repos[repoName].branches).flatMap((branchName) => {
return repos[repoName].branches[branchName].patches.map((patch) => {
return {
patch,
branchName,
repoName,
}
})
})
})
return cachedFlatPatches
}136 137 138 139 140
}
const getLocation = (reposConfig: any, branchName: string, repoName: string): string => {
const config = reposConfig.repos[repoName]
if (config._type === "darcs") {
return config.branches[branchName].location136 137 138 139 140 141
}
const getLocation = (reposConfig: any, branchName: string, repoName: string): string => {
console.log(repoName)
const config = reposConfig.repos[repoName]
if (config._type === "darcs") {
return config.branches[branchName].location
-1 0 1 2 3 4 5 6 7 8 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
import flatPatchesFunc from './flatPatches.js'
let paginatedPatches = null
export default async (repos) => {
if (paginatedPatches !== null) { return paginatedPatches }
const flatPatches = await flatPatchesFunc(repos)
paginatedPatches = []
const patchesPerPage = 30
flatPatches.forEach((patch) => {
const index = paginatedPatches.findIndex((page) => {
return (
page.repoName === patch.repoName
&& page.branchName == patch.branchName
&& page.patches.length <= patchesPerPage
)
})
if (index === -1) {
const pageNumber = paginatedPatches.filter(page => (page.repoName === patch.repoName && page.branchName === patch.branchName)).length + 1
paginatedPatches.push({
repoName: patch.repoName,
branchName: patch.branchName,
patches: [patch.patch],
// current page number is one more than "how many items in paginatedPatches already
// have repoName as their repo name.
pageNumber,
})
}
else {
paginatedPatches[index].patches.push(patch.patch)
}
})
return paginatedPatches
}
-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<nav>
<ul class="pagination">
{% for pageObj in (paginatedPatches | pagesJustForBranch(patchPage.repoName, patchPage.branchName)) %}
<li class="page-item">
<a class="page-link {% if pageObj.pageNumber == patchPage.pageNumber %}active{% endif %}" href="{{reposPath}}/{{patchPage.repoName | slugify}}/branches/{{patchPage.branchName}}/patches/page{{pageObj.pageNumber}}">{{ pageObj.pageNumber }}</a>
</li>
{% endfor %}
</ul>
</nav>
<ul>
{% for patch in patchPage.patches %}
<li class="patch">
<div>
<span class="patch-name"><a href="/repos/{{patchPage.repoName | slugify}}/branches/{{patchPage.branchName | slugify}}/patches/{{patch.hash}}">{{patch.name}}</a></span>
<br />
<span>{{patch.date | date}}</span>
<br />
<span>{{patch.author}}</span>
<pre class="patch-hash">{{patch.hash}}</pre>
</div>
</li>
{% endfor %}
</ul>
<nav>
<ul class="pagination">
{% for pageObj in (paginatedPatches | pagesJustForBranch(patchPage.repoName, patchPage.branchName)) %}
<li class="page-item">
<a class="page-link {% if pageObj.pageNumber == patchPage.pageNumber %}active{% endif %}" href="/repos/{{patchPage.repoName | slugify}}/branches/{{patchPage.branchName}}/patches/page{{pageObj.pageNumber}}">{{ pageObj.pageNumber }}</a>
</li>
{% endfor %}
</ul>
</nav>