-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommandList.js
More file actions
55 lines (48 loc) · 1.79 KB
/
commandList.js
File metadata and controls
55 lines (48 loc) · 1.79 KB
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
"use strict";
function gatherCommands(contentAggregateItem) {
// Here we collect the tags
const collectedTagsByPrefix = {};
// Sort the prefixes and create an object for each in the collectedTagsByPrefix object
let fileContent = "";
contentAggregateItem.files.forEach((file) => {
if (file.path.includes(".adoc")) {
console.log("Checking " + file.path);
const buffer = Buffer.from(file._contents);
const previousTextOfFile = buffer.toString("utf-8");
if (previousTextOfFile.match(/page-en\: commands\/[a-zA-Z0-9]+\r?\n/)) {
const commandName = file.path
.replaceAll("\\", "/")
.split("/")
.reverse()[0]
.replace(".adoc", "");
fileContent += `* xref:/commands/${commandName}.adoc[${commandName}]\n`;
}
}
});
return fileContent;
}
function generateFile(contentAggregateItem, fileContent) {
const file = contentAggregateItem.files.find((file) => {
const buffer = Buffer.from(file._contents);
const previousTextOfFile = buffer.toString("utf-8");
return previousTextOfFile.match("page-en: commands/All_Commands");
});
console.log("Updating " + file?.path);
if (!file) {
return;
}
const buffer = Buffer.from(file._contents);
const previousTextOfFile = buffer.toString("utf-8");
// Combine the previous content with the newly generated tags
const content = `${previousTextOfFile}\n\n` + `${fileContent}`;
const _contents = Buffer.from(content, "utf-8");
file._contents = _contents;
}
module.exports.register = function () {
this.once("contentAggregated", ({ contentAggregate }) => {
contentAggregate.forEach((contentAggregateItem, index) => {
const fileContent = gatherCommands(contentAggregateItem);
generateFile(contentAggregateItem, fileContent);
});
});
};