-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
96 lines (82 loc) · 3.09 KB
/
mod.ts
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
import { slugify } from "https://deno.land/x/slugify/mod.ts";
// Change a few settings of slugify to match with how CF generates slugs.
slugify.extend({ "&": "", "-": "-", ".": "-" });
export function extractModListFromFile(file: string): Array<string> {
// Turn string into array where each element is a an
// individual mod and the mark-up surrounding it
const modsMarkUpRaw = file.split("\r\n");
// Return the filtered mod list
return modsMarkUpRaw.filter((line) => {
return (!line.includes("<ul>") && !line.includes("</ul>") && line != "");
});
}
/**
* Takes filtered mod list array and returns the mods' CF page URL
* that actually work.
*
* @param modList the contents of the `modlist.html` file.
* @param sort whether or not to sort the mod list alphabetically.
*
* @returns an array of mod urls.
*/
export function extractModUrlsFromModList(
modList: Array<string>,
sort: boolean,
): Array<string> {
// Create the mod CurseForge URLs using the given mod list
const modUrls = modList.map((mod) => {
// A variable to store the mod name
let modName;
// Find the mod name within the HTML mark-up
modName = mod.substring(
mod.indexOf('">') + 2,
mod.indexOf("(by"),
);
// Slugify the mod name
modName = slugify(modName, { remove: /[^a-zA-Z\d\s\-]/, lower: true });
// Remove trailing dashes
modName = modName.replace(/\-+$/, "");
// Fix all the edge cases that slugify fails to slug correctly
// Submit PR for missing entries.
if (modName === "minetogether") modName = "creeperhost-minetogether";
if (modName === "foamfix") modName = "foamfix-optimization-mod";
if (modName === "bonsai-trees-2") modName = "bonsai-trees";
if (modName === "accidentally-circumstantial-eventsace") {
modName = "accidentally-circumstantial-events-ace";
}
if (modName === "infinibows-infinity-bow-fix") modName = "infinibows";
if (modName === "shut-the-fdollarpercent-up") modName = "shut-the-f-up";
if (modName === "sprinklesforvanilla") modName = "sprinkles_for_vanilla";
// Return the full URL using the slug-ified mod name
return "https://curseforge.com/minecraft/mc-mods/" + modName;
});
return sort ? modUrls.sort() : modUrls;
}
export function extractModNamesFromModList(
modList: Array<string>,
sort: boolean,
): Array<string> {
// Extract the mod names using the given mod list
const modNames = modList.map((mod) => {
// Find the mod name within the HTML mark-up
return mod.substring(
mod.indexOf('">') + 2,
mod.indexOf("(by"),
);
});
return sort ? modNames.sort() : modNames;
}
export function extractModAuthorsFromModList(
modList: Array<string>,
sort: boolean,
): Array<string> {
// Extract the mod authors using the given mod list
const modAuthors = modList.map((mod) => {
// Find the mod name within the HTML mark-up
return mod.substring(
mod.indexOf("(by"),
mod.indexOf(")</a></li>") + 1,
);
});
return sort ? modAuthors.sort() : modAuthors;
}