-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocsparser.js
288 lines (271 loc) · 8.65 KB
/
docsparser.js
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
const fs = require("fs");
const path = require("path");
const jsonPath = path.join(__dirname, "modules.json");
if (!fs.existsSync(jsonPath)) {
console.log("modules.json not found, skipping site generation.");
process.exit(0);
}
function slugify(str) {
return str.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
}
const rawData = fs.readFileSync(jsonPath, "utf8");
const modules = JSON.parse(rawData);
const docsDir = path.join(__dirname, "docs");
if (!fs.existsSync(docsDir)) {
fs.mkdirSync(docsDir);
}
const primaryColor = "rgb(37, 116, 108)";
const hoverColor = "rgb(29, 95, 88)";
const buttonColor = "rgb(37, 116, 108)";
const buttonHoverColor = "rgb(29, 95, 88)";
const darkBackgroundColor = "#1f1f1f";
const darkTextColor = "#e0e0e0";
const indexHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lilia Modules</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; background-color: ${darkBackgroundColor}; color: ${darkTextColor}; }
.header { display: flex; align-items: center; background-color: ${primaryColor}; color: #fff; padding: 10px 20px; justify-content: space-between; }
.modules-link { color: #fff; text-decoration: none; font-weight: bold; margin-right: 20px; font-size: 1.1rem; }
.modules-link:hover { text-decoration: underline; }
.search-bar { position: relative; }
.search-bar input {
padding: 6px 8px;
border-radius: 4px;
border: none;
outline: none;
background-color: #333;
color: #fff;
}
main { max-width: 1200px; margin: 20px auto; padding: 0 20px; }
.plugin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media(max-width: 800px) { .plugin-grid { grid-template-columns: 1fr; } }
.plugin-card {
background-color: #2e2e2e;
border-radius: 4px;
padding: 25px 15px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
justify-content: center;
font-size: 1.1rem;
}
.plugin-card-header { margin-bottom: 10px; }
.plugin-card-title { font-size: 1.2rem; font-weight: bold; color: ${darkTextColor}; }
.plugin-card-author { font-size: 1rem; color: #bbb; margin-top: 10px; }
.plugin-card-version { font-size: 1rem; color: #bbb; margin-top: 5px; }
.view-button {
margin-top: 15px;
padding: 14px 28px;
background-color: ${buttonColor};
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 1.4rem;
}
.view-button:hover { background-color: ${buttonHoverColor}; }
.pagination { display: flex; justify-content: center; margin: 20px 0; gap: 5px; }
.pagination button {
background-color: #2e2e2e;
border: 1px solid #555;
border-radius: 4px;
padding: 12px 24px;
cursor: pointer;
color: ${darkTextColor};
font-size: 1.1rem;
}
.pagination button.active {
background-color: ${primaryColor};
color: #fff;
border-color: ${primaryColor};
}
.pagination button:hover { background-color: #444; }
</style>
</head>
<body>
<header class="header">
<a href="index.html" class="modules-link"></a>
<div class="search-bar">
<input type="text" id="search" placeholder="Search by Title...">
</div>
</header>
<main>
<div class="plugin-grid" id="pluginGrid"></div>
<div class="pagination" id="pagination"></div>
</main>
<script>
const modules = ${JSON.stringify(modules, null, 2)};
const pageSize = 8;
let currentPage = 1;
let filteredModules = [...modules];
const pluginGrid = document.getElementById("pluginGrid");
const pagination = document.getElementById("pagination");
const searchInput = document.getElementById("search");
searchInput.addEventListener("input", () => {
const query = searchInput.value.trim().toLowerCase();
filteredModules = modules.filter(m => m.name.toLowerCase().includes(query));
currentPage = 1;
render();
});
function render() {
renderGrid();
renderPagination();
}
function renderGrid() {
pluginGrid.innerHTML = "";
const startIndex = (currentPage - 1) * pageSize;
const endIndex = startIndex + pageSize;
const pageItems = filteredModules.slice(startIndex, endIndex);
pageItems.forEach((mod) => {
const card = document.createElement("div");
card.className = "plugin-card";
card.innerHTML = \`
<div class="plugin-card-header">
<div class="plugin-card-title">\${mod.name}</div>
<div class="plugin-card-author"><strong>Author:</strong> \${mod.author || "Unknown"}</div>
<div class="plugin-card-version"><strong>Version:</strong> \${mod.version || "N/A"}</div>
</div>
<button class="view-button">View</button>
\`;
const viewBtn = card.querySelector(".view-button");
viewBtn.addEventListener("click", () => {
const slug = slugify(mod.name);
window.location.href = slug + ".html";
});
pluginGrid.appendChild(card);
});
}
function renderPagination() {
pagination.innerHTML = "";
const totalItems = filteredModules.length;
const totalPages = Math.ceil(totalItems / pageSize);
if (totalPages <= 1) return;
for (let p = 1; p <= totalPages; p++) {
const btn = document.createElement("button");
btn.textContent = p;
if (p === currentPage) btn.classList.add("active");
btn.addEventListener("click", () => {
currentPage = p;
render();
});
pagination.appendChild(btn);
}
}
function slugify(str) {
return str.toLowerCase().replace(/\\s+/g, '-').replace(/[^a-z0-9-]/g, '');
}
render();
</script>
</body>
</html>
`;
fs.writeFileSync(path.join(docsDir, "index.html"), indexHtml, "utf8");
modules.forEach(mod => {
const slug = slugify(mod.name);
let workshopHtml = "None";
if (Array.isArray(mod.workshop) && mod.workshop.length > 0) {
workshopHtml = mod.workshop.map(id => `https://steamcommunity.com/sharedfiles/filedetails/?id=${id}`).join("<br>");
}
const detailHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${mod.name || "Module Detail"}</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: ${darkBackgroundColor};
color: ${darkTextColor};
margin: 0;
padding: 0;
}
.container {
max-width: 900px;
margin: 40px auto;
background-color: #333;
padding: 25px 35px;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.header {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.header-left {
max-width: 60%;
}
.header-left h1 {
margin: 0 0 10px 0;
font-size: 2rem;
color: ${darkTextColor};
}
.header-right {
text-align: center;
width: 40%;
}
.action-button {
display: block;
background-color: ${buttonColor};
color: #fff;
padding: 20px 40px;
border-radius: 8px;
text-decoration: none;
font-weight: bold;
font-size: 1.4rem;
margin: 0 auto 15px auto;
}
.action-button:hover {
background-color: ${buttonHoverColor};
}
.info-block {
margin-top: 30px;
line-height: 1.8;
font-size: 1.3rem;
background-color: #3a3a3a;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}
.info-block p {
margin-bottom: 20px;
}
.back-link {
display: inline-block;
margin-bottom: 25px;
color: ${primaryColor};
text-decoration: none;
font-weight: bold;
}
.back-link:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<a class="back-link" href="index.html">← Modules</a>
<div class="header">
<div class="header-left">
<h1>${mod.name || "Untitled Module"}</h1>
</div>
<div class="header-right">
<a class="action-button" href="${mod.download}">Download via GitHub</a>
<a class="action-button" href="${mod.source}">View Source</a>
</div>
</div>
<div class="info-block">
<p><strong>Author:</strong> ${mod.author || "Unknown"}</p>
<p><strong>Version:</strong> ${mod.version || "N/A"}</p>
<p><strong>Description:</strong><br>${mod.description || "No description provided."}</p>
<p><strong>Workshop:</strong><br>${workshopHtml}</p>
</div>
</div>
</body>
</html>`;
fs.writeFileSync(path.join(docsDir, `${slug}.html`), detailHtml, "utf8");
});