Sat Sep 13 2025
Tucker McKnight <tucker.mcknight@gmail.com>
ac0345de909f8c5624b595e80f7d1fd0869f5c41
0
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
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
(function () {
var _a;
var setCheckbox = window.setCheckbox;
var currentTheme = window.currentTheme;
setCheckbox(currentTheme, document.getElementById('dark-mode-switch'));
var copyCommand = function (event) {
var elem = event.target;
var cloneText = elem.dataset.cloneUrl;
var originalInnerText = elem.innerText;
navigator.clipboard.writeText(cloneText).then(function () {
elem.innerText = "Copied";
});
window.setTimeout(function () {
elem.innerText = originalInnerText;
}, 5000);
};
var createClonePopover = function (currentRepo) {
var div = document.createElement('div');
div.id = "clone-popover";
div.innerHTML = jsVars.cloneDiv;
var popoverBtn = document.getElementById("clone-popover-btn");
var bsPopover = new bootstrap.Popover(popoverBtn, {
sanitize: false,
html: true,
content: div,
title: 'Clone',
});
div.querySelector("#clone-button").addEventListener('click', copyCommand);
document.body.addEventListener('click', function (event) {
var target = event.target;
// If they didn't click the #clone-popover-btn or if we're not inside of
// popover, or if we *are* inside of a popover but a different one than the
// current one, then close the popover.
var parentPopover = target.closest(".popover");
if (target.id !== "clone-popover-btn"
&& (parentPopover === null
|| parentPopover !== bsPopover.tip)) {
bsPopover.hide();
}
});
};
var toggleLastTouch = function (event) {
var isOn = event.target.checked;
var annotations = document.getElementById("annotations");
if (isOn) {
annotations.classList.remove("d-none");
}
else {
annotations.classList.add("d-none");
}
};
(_a = document.getElementById("showLastTouch")) === null || _a === void 0 ? void 0 : _a.addEventListener('click', toggleLastTouch);
var copyPull = function (event) {
var hash = event.target.dataset.hash;
var isDarcs = event.target.dataset.vcs === "darcs";
var copiedPrefix = isDarcs ? "darcs pull ".concat(jsVars.baseUrl, " -h ") : "";
var originalInnerHtml = event.target.innerHTML;
var copiedAlert = document.createElement('span');
copiedAlert.innerText = "Copied";
navigator.clipboard.writeText("".concat(copiedPrefix).concat(hash)).then(function () {
event.target.parentElement.appendChild(copiedAlert);
});
window.setTimeout(function () {
copiedAlert.remove();
}, 5000);
};
document.querySelectorAll(".copy-btn").forEach(function (element) {
element.addEventListener("click", copyPull);
});
var bootstrap = window.bootstrap;
var jsVars = window.jsVars;
if (jsVars.nav.repoName) {
createClonePopover(jsVars.nav.repoName);
}
}());
0
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
38
(function () {
var htmlElem = document.querySelector('html');
window['setMode'] = function (mode) {
localStorage.setItem('theme', mode);
if (mode === 'dark') {
htmlElem.setAttribute('data-bs-theme', mode);
}
else if (mode === 'light') {
htmlElem.setAttribute('data-bs-theme', mode);
}
else if (mode === 'auto') {
var preferred = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
htmlElem.setAttribute('data-bs-theme', preferred);
}
window['currentTheme'] = mode;
};
window['currentTheme'] = localStorage.getItem("theme") || "auto";
window['setMode'](window['currentTheme']);
window['setCheckbox'] = function (mode, element) {
if (mode === 'light') {
element.innerHTML = "<i class=\"bi bi-brightness-high\"></i>";
}
if (mode === 'dark') {
element.innerHTML = "<i class=\"bi bi-moon\"></i>";
}
if (mode === 'auto') {
element.innerHTML = "<i class=\"bi bi-yin-yang\"></i>";
}
var link = document.getElementById("prism-theme");
var preferred = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
var stylesheet = window['currentTheme'] === 'dark' || (window['currentTheme'] === 'auto' && preferred === 'dark') ? "prism_dark.css" : "prism.css";
link.href = link.href.split("/").slice(0, -1).concat(stylesheet).join("/");
};
window['toggleDarkMode'] = function (button) {
var clickedOption = button.dataset.themePref;
window['setMode'](clickedOption);
window['setCheckbox'](clickedOption, document.getElementById('dark-mode-switch'));
};
}());
0
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
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
339
340
341
342
343
344
345
346
347
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import fsImport from 'fs';
import util from 'util';
import childProcess from 'child_process';
import repos from "./src/repos.js";
import branches from "./src/branches.js";
import flatFiles from "./src/flatFiles.js";
import flatPatches from "./src/flatPatches.js";
import paginatedPatches from "./src/paginatedPatches.js";
import { getLocation } from "./src/helpers.js";
import repoOperations from "./src/vcses/operations.js";
const exec = util.promisify(childProcess.exec);
export default (eleventyConfig, reposConfiguration) => __awaiter(void 0, void 0, void 0, function* () {
// TODO: check if the render plugin is available and throw an error otherwise
// TODO: check if the highlight function is available
// TODO: throw an error if reposConfiguration is undefined
const reposData = yield repos(reposConfiguration);
// TODO: make a better way of making this default to "/repos" so that it doesn't have to
// be done again in src/repos.ts.
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];
});
const vendor = `${import.meta.dirname}/vendor`;
const frontend = `${import.meta.dirname}/frontend`;
eleventyConfig.addPassthroughCopy({
[vendor]: `${reposPath}/vendor`,
[frontend]: `${reposPath}/frontend`,
});
eleventyConfig.on("eleventy.after", (_a) => __awaiter(void 0, [_a], void 0, function* ({ directories, results, runMode, outputMode }) {
// Check to see if there is already a repo in all of the locations
// that should have one.
for (let repoName in reposConfiguration.repos) {
const repoConfig = reposConfiguration.repos[repoName];
if (repoConfig._type === "darcs") {
for (let branch in repoConfig.branches) {
const repoPath = eleventyConfig.dir.output + reposPath + "/" + eleventyConfig.getFilter("slugify")(repoName) + "/branches/" + branch;
const originalLocation = repoConfig.branches[branch].location;
// If it is there, do darcs pull
if (fsImport.existsSync(repoPath + "/_darcs")) {
yield exec(`(cd ${repoPath} && darcs pull --no-interactive)`);
}
else {
// If it is not there, do darcs clone
yield exec(`(cd ${repoPath} && mkdir -p temp; darcs clone ${originalLocation} temp/${branch} --no-working-dir; mv temp/${branch}/_darcs .; rm -R temp)`);
}
}
}
else if (repoConfig._type === "git") {
const repoPath = eleventyConfig.dir.output + reposPath + "/" + eleventyConfig.getFilter("slugify")(repoName);
const gitRepoName = eleventyConfig.getFilter("slugify")(repoName) + ".git";
// If it is there, do git pull
if (fsImport.existsSync(repoPath + ".git")) {
// git repos are just in the repos folder, not in their subdir
// create string of commands saying 'git fetch origin branch:branch' for each branch
const fetchCommands = repoConfig.branchesToPull.map(branch => `git fetch origin ${branch}:${branch}`).join('; ');
yield exec(`(cd ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} && ${fetchCommands}; git update-server-info)`);
}
else {
// If it is not there, do git clone
const originalLocation = repoConfig.location;
yield exec(`(cd ${eleventyConfig.dir.output + reposPath + "/"} && git clone ${originalLocation} ${gitRepoName} --bare)`);
yield exec(`(cd ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} && git update-server-info)`);
}
}
}
}));
eleventyConfig.addFilter("getDirectoryContents", (repo, branch, dirPath) => {
return reposData[repo].branches[branch].files.filter(file => file.startsWith(dirPath) && file !== dirPath);
});
eleventyConfig.addFilter("getRelativePath", (currentDir, fullFilePath) => {
return fullFilePath.replace(`${currentDir}/`, "");
});
eleventyConfig.addFilter("lineNumbers", (code) => {
const numLines = code.split('\n').length;
const lineNumbers = [];
for (let i = 1; i <= numLines; i++) {
lineNumbers.push(i);
}
return lineNumbers;
});
eleventyConfig.addFilter("highlightCode", (code, language) => {
return eleventyConfig.javascript.functions.highlight(language, code);
});
eleventyConfig.addFilter("languageExtension", (filename, repoName) => {
let extension = filename.split(".");
extension = extension[extension.length - 1];
const extensionsConfig = reposConfiguration.repos[repoName].languageExtensions;
return extensionsConfig && extensionsConfig[extension] ? extensionsConfig[extension] : extension;
});
eleventyConfig.addFilter("topLevelFilesOnly", (files, currentLevel) => {
const onlyUnique = (value, index, array) => {
return array.findIndex(test => test.name === value.name) === index;
};
const currentLevelDirLength = currentLevel.split('/').length;
const topLevels = [];
files.forEach((file) => {
if (file.startsWith(currentLevel)) {
const parts = file.split("/").filter(part => part !== ".");
topLevels.push(parts.slice(0, currentLevelDirLength).join('/'));
}
});
const withNameAndDirAttrs = topLevels.map((file) => {
// is a directory if the entire filename, plus a slash, is contained inside of any
// other file
const isDirectory = files.some((testFile) => {
return testFile.startsWith(file + '/') && (testFile !== file);
});
return { name: file.replace(currentLevel, ''), fullPath: file, isDirectory };
});
const sortedByDirectory = withNameAndDirAttrs.filter(onlyUnique).toSorted((a, b) => {
if (a.isDirectory && b.isDirectory) {
return 0;
}
if (a.isDirectory && !b.isDirectory) {
return -1;
}
return 1;
});
return sortedByDirectory;
});
eleventyConfig.addAsyncFilter("getFileLastTouchInfo", (repo, branch, filename) => __awaiter(void 0, void 0, void 0, function* () {
const ignoreExtensions = ['.png', '.jpg'];
if (ignoreExtensions.some(extension => filename.endsWith(extension))) {
return "";
}
const config = reposConfiguration.repos[repo];
const location = getLocation(reposConfiguration, branch, repo);
return repoOperations[config._type].getFileLastTouchInfo(repo, branch, filename, location);
}));
eleventyConfig.addAsyncFilter("isDirectory", (filename, repoName, branchName) => __awaiter(void 0, void 0, void 0, function* () {
const files = reposData[repoName].branches[branchName].files;
const isDirectory = files.some((testFile) => {
return testFile.startsWith(filename + '/') && (testFile !== filename);
});
return isDirectory;
}));
eleventyConfig.addAsyncFilter("getFileContents", (repo, branch, filename) => __awaiter(void 0, void 0, void 0, function* () {
const location = getLocation(reposConfiguration, branch, repo);
let command = '';
const config = reposConfiguration.repos[repo];
if (config._type === "git") {
command = `git show ${branch}:${filename}`;
}
else if (config._type === "darcs") {
command = `darcs show contents ${filename}`;
}
const res = yield exec(`(cd ${location} && ${command})`);
return res.stdout;
}));
eleventyConfig.addFilter("pagesJustForBranch", (pages, repoName, branchName) => {
return pages.filter(page => page.repoName === repoName && page.branchName === branchName);
});
eleventyConfig.addFilter("date", (dateString) => {
return new Date(dateString).toDateString();
});
eleventyConfig.addFilter("toDateObj", (dateString) => {
return new Date(dateString);
});
eleventyConfig.addAsyncFilter("getReadMe", (repoName, branchName) => __awaiter(void 0, void 0, void 0, function* () {
const location = getLocation(reposConfiguration, branchName, repoName);
const config = reposConfiguration.repos[repoName];
let command = '';
if (config._type === "git") {
command = `git show ${branchName}:README.md`;
}
else if (config._type === "darcs") {
command = `darcs show contents README.md`;
}
try {
const res = yield exec(`(cd ${location} && ${command})`);
return res.stdout;
}
catch (_a) {
return "";
}
}));
eleventyConfig.addFilter("jsonStringify", data => JSON.stringify(data));
const topLayoutPartial = fsImport.readFileSync(`${import.meta.dirname}/partial_templates/main_top.njk`).toString();
const bottomLayoutPartial = fsImport.readFileSync(`${import.meta.dirname}/partial_templates/main_bottom.njk`).toString();
// INDEX.NJK
const indexTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/index.njk`).toString();
eleventyConfig.addTemplate('repos/index.njk', topLayoutPartial + indexTemplate + bottomLayoutPartial, {
permalink: `${reposPath}/index.html`,
});
// BRANCHES.NJK
const branchesTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/branches.njk`).toString();
eleventyConfig.addTemplate('repos/branches.njk', topLayoutPartial + branchesTemplate + bottomLayoutPartial, {
pagination: {
data: "branches",
size: 1,
alias: "branchInfo",
},
permalink: (data) => {
const repoName = data.branchInfo.repoName;
const branchName = data.branchInfo.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/list/`;
},
eleventyComputed: {
nav: {
repoName: (data) => data.branchInfo.repoName,
branchName: (data) => data.branchInfo.branchName,
}
},
navTab: "branches",
});
// FILE.NJK
const fileTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/file.njk`).toString();
const flatFilesData = flatFiles(reposData);
eleventyConfig.addTemplate('repos/file.njk', topLayoutPartial + fileTemplate + bottomLayoutPartial, {
pagination: {
data: "flatFiles",
size: 1,
alias: "fileInfo",
},
flatFiles: flatFilesData,
permalink: (data) => {
const repoName = data.fileInfo.repoName;
const branchName = data.fileInfo.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/files/${eleventyConfig.getFilter("slugify")(data.fileInfo.file)}.html`;
},
eleventyComputed: {
nav: {
repoName: (data) => data.fileInfo.repoName,
branchName: (data) => data.fileInfo.branchName,
}
},
navTab: "files",
});
// FILES.NJK
const filesTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/files.njk`).toString();
eleventyConfig.addTemplate('repos/files.njk', topLayoutPartial + filesTemplate + bottomLayoutPartial, {
pagination: {
data: "branches",
size: 1,
alias: "branchInfo",
},
permalink: (data) => {
const repoName = data.branchInfo.repoName;
const branchName = data.branchInfo.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/files/`;
},
eleventyComputed: {
nav: {
repoName: (data) => data.branchInfo.repoName,
branchName: (data) => data.branchInfo.branchName,
}
},
navTab: "files",
});
// REPO.NJK
const repoTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/repo.njk`).toString();
eleventyConfig.addTemplate('repos/repo.njk', topLayoutPartial + repoTemplate + bottomLayoutPartial, {
pagination: {
data: "branches",
size: 1,
alias: "branch",
},
permalink: (data) => {
const repoName = data.branch.repoName;
const branchName = data.branch.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/`;
},
eleventyComputed: {
nav: {
repoName: (data) => data.branch.repoName,
branchName: (data) => data.branch.branchName,
}
},
navTab: "landing",
});
// PATCHES.NJK
const patchesTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/patches.njk`).toString();
const paginatedPatchesData = yield paginatedPatches(reposData);
eleventyConfig.addTemplate(`repos/patches.njk`, topLayoutPartial + patchesTemplate + 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",
});
// PATCH.NJK
const patchTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/patch.njk`).toString();
const flatPatchesData = yield flatPatches(reposConfiguration);
eleventyConfig.addTemplate(`repos/patch.njk`, topLayoutPartial + patchTemplate + bottomLayoutPartial, {
pagination: {
data: "flatPatches",
size: 1,
alias: "patchInfo",
},
flatPatches: flatPatchesData,
permalink: (data) => {
const repoName = data.patchInfo.repoName;
const branchName = data.patchInfo.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/patches/${data.patchInfo.patch.hash}/`;
},
eleventyComputed: {
nav: {
repoName: (data) => data.patchInfo.repoName,
branchName: (data) => data.patchInfo.branchName,
}
},
width: "full",
navTab: "patches",
});
// FEED.NJK
const feedTemplate = fsImport.readFileSync(`${import.meta.dirname}/templates/feed.njk`).toString();
eleventyConfig.addTemplate(`repos/feed.njk`, feedTemplate, {
pagination: {
data: "branches",
size: 1,
alias: "branch",
},
permalink: (data) => {
const repoName = data.branch.repoName;
const branchName = data.branch.branchName;
return `${reposPath}/${eleventyConfig.getFilter("slugify")(repoName)}/branches/${eleventyConfig.getFilter("slugify")(branchName)}/patches.xml`;
},
eleventyExcludeFromCollections: true,
});
});
0
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
</div>
</div>
</div>
<script>
const toggleUnifiedMode = (e) => {
const diffs = document.getElementById('diffs')
const afterDiffs = document.querySelectorAll('.diff-right')
if (e.checked) {
diffs.classList.add("unified")
afterDiffs.forEach((elem) => {
elem.classList.remove('border-start', 'ps-2')
})
}
else {
diffs.classList.remove("unified")
afterDiffs.forEach((elem) => {
elem.classList.add('border-start', 'ps-2')
})
}
}
const selectBranch = (e) => {
const values = e.value.split(",")
window.location = `{{reposPath}}/${values[0]}/branches/${values[1]}/${values[2]}`
}
</script>
<script src="{{reposPath}}/frontend/main.js"></script>
</body>
</html>
0
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<title>{% if nav.title %}{{nav.title}}{% else %}Repositories{% endif %}</title>
<script>
window.jsVars = {};
{% if nav %}
window.jsVars['baseUrl'] = `{{ repoConfig.repos[nav.repoName].baseUrl | jsonStringify | safe }}`;
window.jsVars['nav'] = {{nav | jsonStringify | safe}};
window.jsVars['cloneDiv'] = `{%- if reposConfig.repos[nav.repoName]._type == "darcs" -%}{% set url = repos[nav.repoName].cloneUrl + (nav.branchName | slugify) %}
<label class="form-label">HTTPS URL</label>
<div class="input-group d-flex flex-nowrap">
<span class="clone overflow-hidden input-group-text">
{{ url }}
</span>
<button data-clone-url="{{url}}" class="btn btn-primary" id="clone-button">Copy</button>
</div>{%- elif reposConfig.repos[nav.repoName]._type == "git" -%}<label class="form-label">HTTPS URL</label>
<div class="input-group d-flex flex-nowrap">
<span class="clone overflow-hidden input-group-text">
{% set url = repos[nav.repoName].cloneUrl %}
{{ url }}
</span>
<button data-clone-url="{{url}}" class="btn btn-primary" id="clone-button">Copy</button>
</div>
{%- endif -%}`;
{% endif %}
</script>
<script src="{{reposPath}}/frontend/top.js"></script>
<link rel="stylesheet" id="prism-theme" type="text/css" href="{{reposPath}}/vendor/prism.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-SgOJa3DmI69IUzQ2PVdRZhwQ+dy64/BUtbMJw1MZ8t5HZApcHrRKUc4W0kG879m7" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.6/dist/js/bootstrap.bundle.min.js" integrity="sha384-j1CDi7MgGQ12Z7Qab0qlWQ/Qqz24Gc6BM0thvEMVjHnfYGF0rmFCozFSxQBxwHKO" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="{{reposPath}}/vendor/main.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-lg">
<div class="row pt-5">
<div class="col">
<header>
<div class="row d-flex justify-content-between pb-3">
<div class="col-auto">
<nav class="fs-4">
<a href="{{reposPath}}">Repositories</a>{% if nav.repoName %}<span class="text-secondary mx-2">></span><a href="{{reposPath}}/{{nav.repoName | slugify}}/branches/{{reposConfig.repos[nav.repoName].defaultBranch | slugify}}">{{nav.repoName}}</a>{% endif %}
</nav>
</div>
<div class="col-auto d-flex align-items-center">
<div class="dropdown">
<button class="dropdown-toggle btn" id="dark-mode-switch" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-brightness-high"></i>
</button>
<ul class="dropdown-menu">
<li><button class="btn" data-theme-pref="light" onclick="toggleDarkMode(this)"><i class="bi bi-brightness-high mx-1"></i>Light</button></li>
<li><button class="btn" data-theme-pref="dark" onclick="toggleDarkMode(this)"><i class="bi bi-moon mx-1"></i>Dark</button></li>
<li><button class="btn" data-theme-pref="auto" onclick="toggleDarkMode(this)"><i class="bi bi-yin-yang mx-1"></i>Auto</button></li>
</ul>
</div>
</div>
</div>
{% if nav.repoName %}
<div class="row mb-4">
<div class="col-12 col-md order-2 order-md-1 pe-0">
<nav class="nav-tabs">
<ul class="nav">
<li class="nav-item">
<a class="nav-link {% if navTab == "landing" %}active{% endif %}" href="{{reposPath}}/{{nav.repoName | slugify}}/branches/{{nav.branchName}}">Landing Page</a>
</li>
<li class="nav-item">
<a class="nav-link {% if navTab == "files" %}active{% endif %}" href="{{reposPath}}/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/files">Files</a>
</li>
<li class="nav-item">
<a class="nav-link {% if navTab == "patches" %}active{% endif %}" href="{{reposPath}}/{{nav.repoName | slugify}}/branches/{{nav.branchName}}/patches/page1">Changes</a>
</li>
<li class="nav-item">
<a class="nav-link {% if navTab == "branches" %}active{% endif %}" href="{{reposPath}}/{{nav.repoName | slugify}}/branches/{{nav.branchName | slugify}}/list">Branches</a>
</li>
</ul>
</nav>
</div>
<div class="col-12 col-md-auto order-1 order-md-2 pb-2 pb-md-0 mb-2 mb-md-0 border-bottom">
<div class="row">
<div class="col-auto px-2">
<button type="button" id="clone-popover-btn" class="btn btn-sm btn-primary" data-bs-toggle="popover" data-bs-placement="bottom">Clone <i class="bi bi-caret-down-fill"></i></button>
</div>
<div class="col-auto px-2">
<div class="input-group input-group-sm">
<span class="input-group-text">Branch</span>
<select class="form-select" onchange="selectBranch(this)" aria-label="Repository branch selector">
{% for branch in branches %}
{% if branch.repoName == nav.repoName %}
<option value="{{branch.repoName | slugify}},{{branch.branchName | slugify}},{{nav.path}}" {% if branch.branchName == nav.branchName %}selected{% endif %}>{{branch.branchName}}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
</div>
</div>
</div>
{% endif %}
</header>
</div>
</div>
</div>
<div class="container-{% if width == "full"%}fluid{% else %}lg{% endif %}">
<div class="row">
<div class="col">
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
let cachedBranches = null;
export default (repos) => {
if (cachedBranches !== null) {
return cachedBranches;
}
cachedBranches = Object.keys(repos).flatMap((repoName) => {
return Object.keys(repos[repoName].branches).map((branchName) => {
return {
branchName,
repoName,
};
});
});
return cachedBranches;
};
0
0
export {};
0
0
export {};
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let cachedFlatFiles = null;
export default (repos) => {
if (cachedFlatFiles !== null) {
return cachedFlatFiles;
}
cachedFlatFiles = Object.keys(repos).flatMap((repoName) => {
return Object.keys(repos[repoName].branches).flatMap((branchName) => {
return repos[repoName].branches[branchName].files.map((file) => {
return {
file,
branchName,
repoName,
};
});
});
});
return cachedFlatFiles;
};
0
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
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
let cachedFlatPatches = null;
export default (repos) => __awaiter(void 0, void 0, void 0, function* () {
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;
});
0
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import _ from 'lodash';
import * as Diff from 'diff';
const getGitDiffsFromPatchText = (patchText) => {
const lines = patchText.split("\n");
const hunks = [];
let previousHunk = -1;
const filenameRegex = RegExp(/diff --git a\/(.*?) b\/(.*?)/);
const lineNumberRegex = RegExp(/@@ -(.*?)[,| ].*/);
let previousFilename = '';
let currentFilename = '';
let skipFourStartingAt = -1;
lines.forEach((line, index) => {
if (line.startsWith("diff")) {
previousFilename = currentFilename;
currentFilename = line.match(filenameRegex)[1];
if (previousHunk !== -1) {
skipFourStartingAt = index;
}
}
if (line.startsWith("@@") || index == lines.length - 1) {
if (previousHunk === -1) {
previousHunk = index;
return;
}
let hunkEndIndex = index + 1;
if (skipFourStartingAt !== -1 && skipFourStartingAt < hunkEndIndex) {
hunkEndIndex = skipFourStartingAt;
skipFourStartingAt = -1;
}
const lastHunk = lines.slice(previousHunk, hunkEndIndex);
let lastHunkBefore = lastHunk.filter(line => line.startsWith("-")).map(str => str.replace("-", "")).join("\n");
let lastHunkAfter = lastHunk.filter(line => line.startsWith("+")).map(str => str.replace("+", "")).join("\n");
lastHunkBefore = _.escape(lastHunkBefore);
lastHunkAfter = _.escape(lastHunkAfter);
const changeObject = Diff.diffWordsWithSpace(lastHunkBefore, lastHunkAfter);
let previousText = "";
let afterText = "";
changeObject.forEach((obj) => {
if (!obj.added && !obj.removed) {
previousText = previousText + obj.value;
afterText = afterText + obj.value;
}
if (obj.added) {
afterText = afterText + "<mark>" + obj.value + "</mark>";
}
if (obj.removed) {
previousText = previousText + "<mark>" + obj.value + "</mark>";
}
});
hunks.push({
file: previousFilename !== '' ? previousFilename : currentFilename,
lineNumber: parseInt(lines[previousHunk].match(lineNumberRegex)[1]),
previousText,
afterText,
});
previousFilename = '';
previousHunk = index;
}
});
return hunks;
};
/** @hidden */
const getDarcsDiffsFromPatchText = (patchText) => {
const lines = patchText.split("\n");
const hunks = [];
let previousHunk = -1;
lines.forEach((line, index) => {
if (line.startsWith("hunk") || index === lines.length - 1) {
if (previousHunk === -1) {
previousHunk = index;
return;
}
// get diff from previous hunk to this next one
const lastHunk = lines.slice(previousHunk, index + 1); // slice is non-inclusive for the end argument
let lastHunkBefore = lastHunk.filter(line => line.startsWith("-")).map(str => str.replace("-", "")).join("\n");
let lastHunkAfter = lastHunk.filter(line => line.startsWith("+")).map(str => str.replace("+", "")).join("\n");
lastHunkBefore = _.escape(lastHunkBefore);
lastHunkAfter = _.escape(lastHunkAfter);
let filename = lines[previousHunk].replace("hunk ./", "");
const changeObject = Diff.diffWords(lastHunkBefore, lastHunkAfter);
let previousText = "";
let afterText = "";
changeObject.forEach((obj) => {
if (!obj.added && !obj.removed) {
previousText = previousText + obj.value;
afterText = afterText + obj.value;
}
if (obj.added) {
afterText = afterText + "<mark>" + obj.value + "</mark>";
}
if (obj.removed) {
previousText = previousText + "<mark>" + obj.value + "</mark>";
}
});
const regex = RegExp(/(.*) ([0-9]+)$/);
const matches = filename.match(regex);
const file = matches[1];
const lineNumber = parseInt(matches[2]);
hunks.push({
file,
lineNumber,
previousText,
afterText,
});
previousHunk = index;
}
});
return hunks;
};
const getLocation = (reposConfig, branchName, repoName) => {
const config = reposConfig.repos[repoName];
if (config._type === "darcs") {
return config.branches[branchName].location;
}
else if (config._type === "git") {
return config.location;
}
};
export { getDarcsDiffsFromPatchText, getGitDiffsFromPatchText, getLocation, };
0
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
38
39
40
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import flatPatchesFunc from './flatPatches.js';
let paginatedPatches = null;
export default (repos) => __awaiter(void 0, void 0, void 0, function* () {
if (paginatedPatches !== null) {
return paginatedPatches;
}
const flatPatches = yield 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;
});
0
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import repoOperations from "./vcses/operations.js";
import { getLocation } from "./helpers.js";
import repoHelpers from "./vcses/helpers.js";
const getBranchNames = (repoConfig) => {
if (repoConfig._type === 'darcs') {
return Object.keys(repoConfig.branches);
}
else if (repoConfig._type === 'git') {
return repoConfig.branchesToPull;
}
};
let cachedRepos = null;
const repos = (reposConfig) => __awaiter(void 0, void 0, void 0, function* () {
if (cachedRepos !== null) {
return cachedRepos;
}
const repoNames = Object.keys(reposConfig.repos);
const reposTuples = yield Promise.all(repoNames.map((repoName) => __awaiter(void 0, void 0, void 0, function* () {
const vcs = reposConfig.repos[repoName]._type;
const branchNames = getBranchNames(reposConfig.repos[repoName]);
const branchTuples = yield Promise.all(branchNames.map((branchName) => __awaiter(void 0, void 0, void 0, function* () {
const repoLocation = getLocation(reposConfig, branchName, repoName);
const files = yield repoOperations[vcs].getFileList(repoName, branchName, repoLocation);
const patches = yield repoOperations[vcs].getBranchInfo(repoName, branchName, repoLocation);
return [branchName, {
files,
patches,
}];
})));
const branchesObject = {};
for (let branchTuple of branchTuples) {
branchesObject[branchTuple[0]] = branchTuple[1];
}
return [repoName, branchesObject];
})));
const reposObject = {};
for (let repoTuple of reposTuples) {
const repoName = repoTuple[0];
const repoType = reposConfig.repos[repoName]._type;
reposObject[repoName] = {
branches: repoTuple[1],
cloneUrl: repoHelpers[repoType].cloneUrl(reposConfig.baseUrl + (reposConfig.path || "/repos"), repoName)
};
}
cachedRepos = reposObject;
return reposObject;
});
export default repos;
0
0
1
2
3
4
export default {
cloneUrl: (baseUrl, repoName) => {
return `${baseUrl}/${repoName.toLowerCase().replaceAll(" ", "-")}/branches/`;
}
};
0
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
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
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import util from 'util';
import childProcess from 'child_process';
const exec = util.promisify(childProcess.exec);
import { getDarcsDiffsFromPatchText } from "../../helpers.js";
export const getFileList = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const command = "darcs show files";
const result = yield exec(`(cd ${repoLocation} && ${command})`);
const files = result.stdout.split("\n").filter(item => item.length > 0 && item != ".");
return files;
});
export const getBranchInfo = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const patches = new Map();
const totalPatchesCountRes = yield exec(`(cd ${repoLocation} && darcs log --count)`);
const totalPatchesCount = parseInt(totalPatchesCountRes.stdout);
let hunkRegex = RegExp(/^ *hunk /);
// Get 100 patches at a time and parse those
for (let i = 1; i <= totalPatchesCount; i = i + 100) {
let patchesSubsetRes = yield exec(`(cd ${repoLocation} && darcs log --index=${i}-${i + 100} -v)`);
let patchesSubset = patchesSubsetRes.stdout.split("\n");
do {
const nextPatchStart = patchesSubset.findIndex((line, index) => {
return (index > 0 && line.startsWith("patch ")) || index === patchesSubset.length - 1;
});
const isEndOfFile = nextPatchStart === patchesSubset.length - 1;
const currentPatch = patchesSubset.slice(0, isEndOfFile ? nextPatchStart : nextPatchStart - 1);
patchesSubset = patchesSubset.slice(nextPatchStart);
const hash = currentPatch[0].replace("patch ", "").trim();
const author = currentPatch[1].replace("Author: ", "").trim();
const date = currentPatch[2].replace("Date: ", "").trim();
const name = currentPatch[3].replace(" * ", "").trim();
const diffStart = currentPatch.findIndex((line) => {
return line.match(hunkRegex);
});
const description = currentPatch.slice(5, diffStart).map(str => str.replace(" ", "")).join("\n").trim();
const diffs = getDarcsDiffsFromPatchText(currentPatch.slice(diffStart).map(str => str.trimStart()).join("\n"));
patches.set(hash, {
name,
description,
author,
date,
hash,
diffs,
});
} while (patchesSubset.length > 1);
}
return Array.from(patches.values());
});
export const getFileLastTouchInfo = (repoName, branchName, filename, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const command = `darcs annotate --machine-readable ${filename}`;
const res = yield exec(`(cd ${repoLocation} && ${command})`);
const output = res.stdout;
const outputLines = output.split("\n").map((line) => {
return line.split(' ')[0];
});
return outputLines.map((line) => {
return { sha: line, author: '' };
});
});
0
0
1
2
3
4
export default {
cloneUrl: (baseUrl, repoName) => {
return `${baseUrl}/${repoName.toLowerCase().replaceAll(" ", "-")}.git`;
}
};
0
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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import util from 'util';
import childProcess from 'child_process';
const exec = util.promisify(childProcess.exec);
import { getGitDiffsFromPatchText } from "../../helpers.js";
export const getFileList = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const command = `git ls-tree -r --name-only ${branchName}`;
const result = yield exec(`(cd ${repoLocation} && ${command})`);
let files = result.stdout.split("\n").filter(item => item.length > 0 && item != ".");
// TODO: this could be better. This is adding each sub-path of a file to a set, so that
// we don't wind up with repeats, and then converting that back into an array. E.g. if
// we have two files:
// - posts/blog/one.md
// - posts/blog/two.md
// this will add the following to the set:
// posts, posts/blog, posts/blog/one.md, posts, posts/blog, posts/blog/two.md
// The repeats will be omitted because it's a Set, and the resulting array will
// be [posts, posts/blog, posts/blog/one.md, posts/blog/two.md].
// This is because it's convenient to have the directories show up as their own "file"
// in the file list, even though git doesn't treat them that way.
const fileSet = new Set();
files.forEach((file) => {
const fileParts = file.split("/");
const allPathsInFile = fileParts.reduce((accumulator, currentValue, index) => {
// Skip the first iteration, we have already added it as the initialValue
if (index === 0) {
return accumulator;
}
accumulator.push(accumulator[accumulator.length - 1] + '/' + currentValue);
return accumulator;
}, [fileParts[0]]);
allPathsInFile.forEach((path) => {
fileSet.add(path);
});
});
return Array.from(fileSet);
});
export const getBranchInfo = (repoName, branchName, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const patches = new Map();
const totalPatchesCountRes = yield exec(`(cd ${repoLocation} && git rev-list --count ${branchName})`);
const totalPatchesCount = parseInt(totalPatchesCountRes.stdout);
for (let i = 0; i < totalPatchesCount; i = i + 10) {
const gitLogSubsetRes = yield exec(`(cd ${repoLocation} && git log ${branchName} -p -n 10 --skip ${i})`);
let gitLogSubset = gitLogSubsetRes.stdout.split("\n");
do {
const nextPatchStart = gitLogSubset.findIndex((line, index) => {
return (index > 0 && line.startsWith("commit ")) || index === gitLogSubset.length - 1;
});
const isEndOfFile = nextPatchStart === gitLogSubset.length - 1;
const currentPatch = gitLogSubset.slice(0, isEndOfFile ? nextPatchStart : nextPatchStart - 1);
gitLogSubset = gitLogSubset.slice(nextPatchStart);
const hash = currentPatch[0].replace("commit ", "").trim();
const author = currentPatch[1].replace("Author: ", "").trim();
const date = currentPatch[2].replace("Date: ", "").trim();
const diffStart = currentPatch.findIndex((line) => {
return line.startsWith("diff ");
});
// Git log is indent four spaces by default -- remove those.
const commitMessage = currentPatch.slice(4, diffStart).map(str => str.replace(" ", ""));
const name = commitMessage[0].trim();
const description = commitMessage.slice(1, commitMessage.length - 1).filter((line) => {
// git log --porcelain output adds these "Ignore-this:" lines and I'm not sure what they are
return !line.startsWith('Ignore-this: ');
}).join("\n").trim();
const diffs = getGitDiffsFromPatchText(currentPatch.slice(diffStart).join("\n"));
patches.set(hash, {
name,
description,
author,
date,
hash,
diffs,
});
} while (gitLogSubset.length > 1);
}
return Array.from(patches.values());
});
export const getFileLastTouchInfo = (repo, branch, filename, repoLocation) => __awaiter(void 0, void 0, void 0, function* () {
const regex = RegExp(".* [0-9]+ [0-9]+");
const command = `git blame --porcelain ${branch} ${filename}`;
const res = yield exec(`(cd ${repoLocation} && ${command})`);
const output = res.stdout;
const outputLines = output.split("\n");
const initialValue = [[outputLines[0]]];
const chunked = outputLines.reduce((accumulator, currentLine, currentIndex) => {
// skip the first iteration since we already gave it initialValue
if (currentIndex == 0) {
return accumulator;
}
if (currentLine.match(regex)) {
accumulator.push([currentLine]);
return accumulator;
}
else {
accumulator[accumulator.length - 1].push(currentLine);
return accumulator;
}
}, initialValue);
let currentAuthor = '';
let authorsAndShasByLine = [];
chunked.forEach((chunk) => {
let shaAndLineNumberParts = chunk[0].split(' ');
let line = parseInt(shaAndLineNumberParts[2]);
let sha = shaAndLineNumberParts[0];
if (chunk[1] && chunk[1].startsWith('author ')) {
currentAuthor = chunk[1].replace('author ', '');
}
authorsAndShasByLine[line - 1] = { sha, author: currentAuthor };
});
return authorsAndShasByLine;
});
0
0
1
2
3
4
5
import gitHelpers from "./git/helpers.js";
import darcsHelpers from "./darcs/helpers.js";
export default {
git: gitHelpers,
darcs: darcsHelpers
};
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { getBranchInfo as getGitBranchInfo, getFileList as getGitFileList, getFileLastTouchInfo as getGitFileLastTouchInfo, } from "./git/operations.js";
import { getBranchInfo as getDarcsBranchInfo, getFileList as getDarcsFileList, getFileLastTouchInfo as getDarcsFileLastTouchInfo, } from "./darcs/operations.js";
const repoOperations = {
git: {
getBranchInfo: getGitBranchInfo,
getFileList: getGitFileList,
getFileLastTouchInfo: getGitFileLastTouchInfo,
},
darcs: {
getBranchInfo: getDarcsBranchInfo,
getFileList: getDarcsFileList,
getFileLastTouchInfo: getDarcsFileLastTouchInfo,
}
};
export default repoOperations;
0
0
1
2
3
4
5
6
7
<ul>
{% for branch in branches %}
{% set description = reposConfig.repos[branch.repoName].branches[branch.branchName].description %}
{% if branch.repoName == branchInfo.repoName %}
<li><a href="{{reposPath}}/{{branch.repoName | slugify}}/branches/{{branch.branchName | slugify}}">{{branch.branchName}}</a>{% if branch.branchName == branchInfo.branchName %} (current){% endif %}{% if description %} - {{ description }}{% endif %}</li>
{% endif %}
{% endfor %}
</ul>
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ page.lang }}">
<title>Latest patches in {{branch.branchName}}</title>
<link href="{{ ('/repos/' + (branch.repoName | slugify) + '/branches/' + (branch.branchName | slugify) + '/patches.xml')| htmlBaseUrl(reposConfig.baseUrl) }}" rel="self" />
<link href="{{ ('/repos/' + (branch.repoName | slugify) + '/branches/' + (branch.branchName | slugify)) | htmlBaseUrl(reposConfig.baseUrl) }}" />
{% set lastPatch = repos[branch.repoName].branches[branch.branchName].patches | last %}
<updated>{{ lastPatch.date | toDateObj | dateToRfc3339 }}</updated>
<id>{{ reposConfig.baseUrl | addPathPrefixToFullUrl }}</id>
<author>
<name>{{branch.repoName}} contributors</name>
</author>
{%- for patch in repos[branch.repoName].branches[branch.branchName].patches | reverse %}
{%- set absolutePostUrl %}{{ ('/repos/' + (branch.repoName | slugify) + '/branches/' + (branch.branchName | slugify) + '/patches/' + patch.hash) | htmlBaseUrl(reposConfig.baseUrl) }}{% endset %}
<entry>
<title>{{ patch.name }}</title>
<author><name>{{ patch.author }}</name></author>
<link href="{{ absolutePostUrl }}" />
<updated>{{ patch.date | toDateObj | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id>
<content type="html">{{ patch.description | renderTransforms({}, reposConfig.baseUrl) }}</content>
</entry>
{%- endfor %}
</feed>
0
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<h3>{{fileInfo.file | getFileName}}</h3>
{% if fileInfo.file | isDirectory(fileInfo.repoName, fileInfo.branchName) %}
<ul class="list-group">
{% set dirs = fileInfo.repoName | getDirectoryContents(fileInfo.branchName, fileInfo.file) | topLevelFilesOnly(fileInfo.file + '/') %}
{% for dir in dirs %}
<li class="list-group-item">
{% if dir.isDirectory %}
<i class="bi bi-folder-fill"></i>
{% else %}
<i class="bi bi-file-earmark"></i>
{% endif %}
<a href="{{reposPath}}/{{fileInfo.repoName | slugify}}/branches/{{fileInfo.branchName | slugify}}/files/{{dir.fullPath | slugify}}.html">{{fileInfo.file | getRelativePath(dir.name)}}</a>
</li>
{% endfor %}
</ul>
{% else %}
<div class="row py-2">
<div class="col">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="showLastTouch">
<label class="form-check-label" for="showLastTouch">Show last line change</label>
</div>
</div>
</div>
<div class="row">
<div class="col-auto border-end">
{% set fileContents = fileInfo.repoName | getFileContents(fileInfo.branchName, fileInfo.file) %}
<code style="white-space: pre;"><pre class="language-text">
{%- for lineNumber in fileContents | lineNumbers -%}
{{ lineNumber }}
{% endfor -%}</pre></code>
</div>
<div id="annotations" class="col-auto d-none">
{% set annotations = fileInfo.repoName | getFileLastTouchInfo(fileInfo.branchName, fileInfo.file) %}
<code style="white-space: pre;"><pre class="language-text">
{%- for annotation in annotations -%}
<a href="{{reposPath}}/{{fileInfo.repoName | slugify}}/branches/{{fileInfo.branchName | slugify}}/patches/{{annotation.sha}}">{{ (annotation.sha | truncate(6, true, '')) }}</a> {{ annotation.author }}
{% endfor -%}
</pre></code>
</div>
<div class="col overflow-scroll">
<code>
{{- fileContents | highlightCode((fileInfo.file | languageExtension(fileInfo.repoName))) | safe }}
</code>
</div>
</div>
{% endif %}
<script type="text/javascript">
const toggleLastTouch = (event) => {
const isOn = event.target.checked
const annotations = document.getElementById("annotations")
if (isOn) {
annotations.classList.remove("d-none")
} else {
annotations.classList.add("d-none")
}
}
document.getElementById("showLastTouch")?.addEventListener('click', toggleLastTouch)
</script>
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<div class="row">
<div class="col">
<ul class="list-group">
{% set files = repos[branchInfo.repoName].branches[branchInfo.branchName].files | topLevelFilesOnly('') %}
{% for file in files %}
<li class="list-group-item">
{% if file.isDirectory %}
<i class="bi bi-folder-fill"></i>
{% else %}
<i class="bi bi-file-earmark"></i>
{% endif %}
<a href="{{reposPath}}/{{branchInfo.repoName | slugify}}/branches/{{branchInfo.branchName | slugify}}/files/{{file.fullPath | slugify}}.html">{{file.name}}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
0
0
1
2
3
4
<ul>
{% for repoName, options in repos %}
<li><a href="{{reposPath}}/{{repoName | slugify}}/branches/{{reposConfig.repos[repoName].defaultBranch}}">{{repoName}}</a></li>
{% endfor %}
</ul>
0
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
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
<div class="container-lg">
<div class="row">
<div class="col-auto">
<h1>{{patchInfo.patch.name}}</h2>
<p>{{patchInfo.patch.date | date }}</p>
<p>{{patchInfo.patch.author }}</p>
<pre>{{patchInfo.patch.description}}</pre>
</div>
</div>
<div class="row">
<div class="col-auto">
<p class="font-monospace fw-bold text-secondary">{{patchInfo.patch.hash}}</p>
{% if reposConfig.repos[patchInfo.repoName]._type == "darcs" %}
<div class="input-group mb-3 d-flex flex-nowrap">
<span id="clone-command" class="clone input-group-text overflow-hidden">
{% set url = [reposConfig.baseUrl, reposPath, "/", patchInfo.repoName | slugify, "/branches/", patchInfo.branchName | slugify] | join | url %}
darcs pull {{ url }} -h {{patchInfo.patch.hash}}
</span>
<button class="btn btn-primary" id="clone-button" onclick="copyCommand()">Copy</button>
</div>
{% endif %}
</div>
</div>
</div>
<div class="container-fluid border-top">
<div class="row my-2">
<div class="col-auto d-flex align-items-center fs-4">
<i class="bi bi-layout-split"></i><span class="fs-6 mx-1">Side-by-side</span>
<div class="form-check form-switch mb-1 px-2">
<input class="form-check-input mx-0" type="checkbox" id="unifiedModeSwitch" value="unified" onchange="toggleUnifiedMode(this)" aria-label="Toggle switch for stacked or side by side diff view">
</div>
<i class="bi bi-hr"></i><span class="fs-6 mx-1">Stacked</span>
</div>
</div>
<div class="row" id="diffs">
{% set patchHunks = patchInfo.patch.diffs %}
{% for hunk in patchHunks %}
<div class=hunk>
<span class="font-monospace fw-bold"><a href="{{reposPath}}/{{patchInfo.repoName | slugify}}/branches/{{patchInfo.branchName | slugify}}/files/{{ hunk.file | slugify}}.html">{{ hunk.file }}:{{ hunk.lineNumber }}</a></span>
<div class="diff d-flex">
<div class="flex-grow-1 diff-left pe-2">
<span class='font-monospace text-secondary'>Before</span>
<div class="row">
<div class="col-auto border-end">
<code>
{%- for lineNumber in hunk.previousText | lineNumbers -%}
{{ lineNumber + hunk.lineNumber - 1}}
{% endfor -%}
</code>
</div>
<div class="col overflow-scroll">
<pre data-start="{{hunk.lineNumber}}"><code data-type="before" class="line-numbers language-{{hunk.file | languageExtension(patchInfo.repoName)}}">{{hunk.previousText | safe}}</code></pre>
</div>
</div>
</div>
<div class="diff-right flex-grow-1 ps-2 border-start">
<span class='font-monospace text-secondary'>After</span>
<div class="row">
<div class="col-auto border-end">
<code>
{%- for lineNumber in hunk.afterText | lineNumbers -%}
{{ lineNumber + hunk.lineNumber - 1}}
{% endfor -%}
</code>
</div>
<div class="col overflow-scroll">
<pre data-start="{{hunk.lineNumber}}"><code data-type="after" class="line-numbers language-{{hunk.file | languageExtension(patchInfo.repoName)}}">{{ hunk.afterText | safe}}</code></pre>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<script>
const copyCommand = () => {
const text = document.getElementById("clone-command").innerText
const button = document.getElementById("clone-button")
navigator.clipboard.writeText(text).then(() => {
button.innerText = "Copied"
})
}
</script>
0
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
<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="{{reposPath}}/{{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="{{reposPath}}/{{patchPage.repoName | slugify}}/branches/{{patchPage.branchName}}/patches/page{{pageObj.pageNumber}}">{{ pageObj.pageNumber }}</a>
</li>
{% endfor %}
</ul>
</nav>
0
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
38
39
40
<div class="row">
<div class="col-md-8 col-sm-12 order-md-1 order-sm-2">
{{ branch.repoName | getReadMe(branch.branchName) | renderContent("md") | safe }}
</div>
<div class="col-md-4 col-sm-12 order-md-2 order-sm-1">
<div class="row">
<div class="col">
<div class="row align-items-center">
<div class="col-auto">
<h2 class="fs-6 my-0">Recent patches in {{branch.branchName}}</h2>
</div>
<div class="col-auto">
<a href="{{reposPath}}/{{ branch.repoName | slugify }}/branches/{{ branch.branchName | slugify }}/patches.xml" class="initialism">RSS<i class="bi bi-rss-fill ms-2" style="color: orange;"></i></a>
</div>
</div>
{% for patch in repos[branch.repoName].branches[branch.branchName].patches | batch(3) | first %}
<div class="card mt-2 mb-4">
<div class="card-body">
<a href="{{reposPath}}/{{branch.repoName | slugify}}/branches/{{branch.branchName | slugify}}/patches/{{patch.hash}}" class="text-primary d-inline-block card-title fs-5">{{patch.name}}</a>
<p class="card-subtitle fs-6 mb-2 text-body-secondary">{{patch.date}}</p>
<p class="card-subtitle fs-6 mb-2 text-body-secondary">{{patch.author}}</p>
<p class="card-text">{{patch.description | truncate(150)}}</p>
</div>
<div class="card-footer">
{% if reposConfig.repos[branch.repoName]._type == "darcs" %}
<button data-hash="{{patch.hash}}" data-vcs="darcs" class="copy-btn btn btn-sm btn-outline-primary ms-2">
<i class="bi-copy bi me-1"></i>darcs pull {{patch.hash | truncate(6, true, "")}}
</button>
{% elif reposConfig.repos[branch.repoName]._type == "git" %}
<button data-hash="{{patch.hash}}" data-vcs="git" class="copy-btn btn btn-sm btn-outline-primary">
{{patch.hash | truncate(8, true, "")}} <i class="bi-copy bi me-1"></i>
</button>
{% endif %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
0
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pre {
font-size: 14px !important;
}
code {
white-space: pre;
}
blockquote {
margin-left: 0.25rem;
padding-left: 0.5rem;
border-left: 3px solid royalblue;
background: rgba(125, 125, 125, 0.07);
overflow: hidden;
}
blockquote p {
margin: 0.5rem;
}
.hunk {
box-sizing: border-box;
margin-bottom: 25px;
}
[data-type=before] mark {
background-color: rgba(252, 78, 78, .15);
}
[data-type=after] mark {
background-color: rgba(151, 247, 203, .4);
}
[data-bs-theme=dark] [data-type=after] mark {
background-color: rgba(51, 247, 160, .1); /* different green for dark mode; looks better */
}
.unified .diff {
flex-wrap: wrap;
}
.diff-left, .diff-right {
flex: 1;
overflow: hidden;
}
.unified .diff-left, .unified .diff-right {
flex-basis: 100%;
}
.patch {
margin: 12px 0;
}
.patch-name {
font-size: 18px;
font-weight: bold;
}
.patch-hash {
font-size: 14px;
margin: 6px 0;
}
.clone {
font-family: monospace;
font-size: 12px;
}
.popover {
max-width: 100%;
}
0
0
1
2
3
/* PrismJS 1.30.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript&plugins=line-numbers+keep-markup */
code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:none}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}
0
0
1
2
3
/* PrismJS 1.30.0
https://prismjs.com/download.html#themes=prism-okaidia&languages=markup+css+clike+javascript&plugins=line-numbers+keep-markup */
code[class*=language-],pre[class*=language-]{color:#f8f8f2;background:0 0;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background:none}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#8292a2}.token.punctuation{color:#f8f8f2}.token.namespace{opacity:.7}.token.constant,.token.deleted,.token.property,.token.symbol,.token.tag{color:#f92672}.token.boolean,.token.number{color:#ae81ff}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#a6e22e}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#f8f8f2}.token.atrule,.token.attr-value,.token.class-name,.token.function{color:#e6db74}.token.keyword{color:#66d9ef}.token.important,.token.regex{color:#fd971f}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}