Sun Sep 28 2025
tucker <tucker@pangolin.lan>
b8418b27db08fabc7d2f862e39ef4e36f255177c
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
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)`);
// 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,
});
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
348
349
350
351
352
353
354
355
356
357
358
359
import { Ajv } from 'ajv';
import ConfigSchema from './schemas/ReposConfiguration.json' with { type: 'json' };
const ajv = new Ajv();
export default function repoViewer(eleventyConfig, reposConfiguration) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const validator = ajv.compile(ConfigSchema);
const valid = validator(reposConfiguration);
if (!valid) {
throw new Error(validator.errors.map(error => `config object at ${error.instancePath.replaceAll("/", ".")}: ${error.message}`).join("\n"));
}
const reposData = yield repos(reposConfiguration);
// TODO: make a better way of making this default to "" so that it doesn't have to
// be done again in src/repos.ts.
const reposPath = reposConfiguration.path || "";
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(this, [_a], void 0, function* ({ directories, results, runMode, outputMode }) {
const cwd = process.cwd();
// 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 = cwd + "/" + 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)`);
// If it is not there, do git clone
const originalLocation = cwd + "/" + 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) => {
var _a, _b;
const highlighter = (_b = (_a = eleventyConfig === null || eleventyConfig === void 0 ? void 0 : eleventyConfig.javascript) === null || _a === void 0 ? void 0 : _a.functions) === null || _b === void 0 ? void 0 : _b.highlight;
if (highlighter) {
return highlighter(language, code);
}
else {
return code;
}
eleventyConfig.addAsyncFilter("renderContentIfAvailable", (contentString, contentType) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const renderer = (_b = (_a = eleventyConfig === null || eleventyConfig === void 0 ? void 0 : eleventyConfig.javascript) === null || _a === void 0 ? void 0 : _a.functions) === null || _b === void 0 ? void 0 : _b.renderContent;
if (renderer) {
return yield renderer.bind({})(contentString, contentType);
else {
return `<pre>${contentString}</pre>`;
}));
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(this, 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(this, 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(this, 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(this, 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
// htmlBaseUrl is a function defined by the 11ty RSS plugin.
// Skip this virtual template if the 11ty RSS plugin is not being used.
let rssAvailable = false;
if ((_b = (_a = eleventyConfig === null || eleventyConfig === void 0 ? void 0 : eleventyConfig.javascript) === null || _a === void 0 ? void 0 : _a.functions) === null || _b === void 0 ? void 0 : _b.htmlBaseUrl) {
rssAvailable = true;
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,
});
}
// This is used to show/hide the RSS feed link on the landing page.
eleventyConfig.addGlobalData('rssAvailable', rssAvailable);
}
46
<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 %}
46
<a href="{% if reposPath == "" %}/{% else %}{{reposPath}}{% endif %}">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 %}
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
{
"$ref": "#/definitions/ReposConfiguration",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"DarcsConfig": {
"additionalProperties": false,
"description": "A configuration object for a darcs repository.",
"properties": {
"_type": {
"const": "darcs",
"description": "Must be set to `\"darcs\"`.",
"type": "string"
},
"branches": {
"additionalProperties": {
"additionalProperties": false,
"description": "Each key in this object will be the name that is used for that branch.",
"properties": {
"description": {
"description": "A description of this branch. You may want to clarify what this branch is used for here.",
"type": "string"
},
"location": {
"description": "The absolute path to the repository for this branch.",
"type": "string"
}
},
"required": [
"location"
],
"type": "object"
},
"description": "The branches of this repository to generate pages for. Since darcs doesn't have branches in the same way that other VCSs do, a \"branch\" in this case is an entirely separate repository. So, these \"branches\" are more like repos that are grouped under the same project name. That is why you need to specify a separate location for each branch.",
"type": "object"
},
"defaultBranch": {
"description": "The name of the default branch. Should match one of the keys in {@link DarcsConfig.branches } .",
"type": "string"
},
"languageExtensions": {
"additionalProperties": {
"type": "string"
},
"description": "If your repository has any uncommon file extensions that should be treated like a different type of file, list them here. If you include `{njk: \"html\"}` here, that will tell the syntax highlighter to highlight an `njk` file like an `html` file. The key is the file extension in your code, and the value is the file extension that the syntax highlighter will know about.",
"type": "object"
}
},
"required": [
"_type",
"defaultBranch",
"branches"
],
"type": "object"
},
"GitConfig": {
"additionalProperties": false,
"properties": {
"_type": {
"const": "git",
"type": "string"
},
"branchesToPull": {
"items": {
"type": "string"
},
"type": "array"
},
"defaultBranch": {
"type": "string"
},
"description": {
"type": "string"
},
"languageExtensions": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"location": {
"type": "string"
}
},
"required": [
"_type",
"location",
"defaultBranch",
"branchesToPull"
],
"type": "object"
},
"ReposConfiguration": {
"additionalProperties": false,
"description": "The ReposConfiguration object contains information about your local repositories, like their name and location on your local filesystem. Add repositories to this configuration object to make a static site for them.\n\nThis static site generator works with both git and darcs repositories. Because of the differences between these two version control systems, the configuration for them looks a little different. Both types of configuration objects can be nested underneath the {@link ReposConfiguration.repos } key.\n\nYou will also need to set the {@link ReposConfiguration.baseUrl } to the URL of your live website.",
"properties": {
"baseUrl": {
"description": "The root URL where this website will be. E.g.: https://blog.example.com/repos. This URL will be used when a clone or pull command is being shown on your site.",
"type": "string"
},
"path": {
"description": "The path to put the generated site in. All generated files will be put in this directory, repos for cloning will be put in this directory, and it will be added to the end of all URLs used by the default virtual template.",
"type": "string"
},
"repos": {
"additionalProperties": {
"anyOf": [
{
"$ref": "#/definitions/GitConfig"
},
{
"$ref": "#/definitions/DarcsConfig"
}
],
"description": "An object containing the configuration for your repositories. Each key in this object is a repository name, and the value has several config options for that repository. The required config options describe the path to the repository and which branches should be pulled. See the specific definitions of {@link GitConfig } and {@link DarcsConfig } for more details about what goes in these configuration objects."
},
"type": "object"
}
},
"required": [
"repos",
"baseUrl"
],
"type": "object"
}
}
}
48
cloneUrl: repoHelpers[repoType].cloneUrl(reposConfig.baseUrl + (reposConfig.path || "/repos"), repoName)
48
cloneUrl: repoHelpers[repoType].cloneUrl(reposConfig.baseUrl + (reposConfig.path || ""), repoName)
1
{{ branch.repoName | getReadMe(branch.branchName) | renderContent("md") | safe }}
1
{{ branch.repoName | getReadMe(branch.branchName) | renderContentIfAvailable("md") | safe }}
9
10
11
<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>
9
10
11
12
13
{% if rssAvailable %}
<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>
{% endif %}
12
"eleventy-plugin-repoviewer": "file:~/repos/eleventy-plugin-repoviewer"
12
"eleventy-plugin-repoviewer": "git+https://repos.tuckerm.us/eleventy-plugin-repoviewer.git#deploy/0.0.1-alpha.1"
562
"resolved": "file:..",
562
"resolved": "git+https://repos.tuckerm.us/eleventy-plugin-repoviewer.git#f03bd95a0c86f3612ad7c56e6269e872bf32734d",