-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathgulpfile.js
333 lines (300 loc) · 9.46 KB
/
gulpfile.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
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
const gulp = require("gulp");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
const nunjucksRender = require("gulp-nunjucks-render");
const axios = require("axios");
const fs = require('fs');
const path = require('path');
const { Transform } = require("stream");
const File = require("vinyl");
const { existsSync } = require("fs");
const workingGroups = require('./config/working-groups');
// Dynamically generate working group structure and repo topics
var structure = {
index: ["index.html"],
events: ["index.html"],
education: ["index.html"],
schemas: ["index.html"],
"working-groups": ["index.html"]
};
// Helper function to normalize slugs
function normalizeSlug(id) {
// Handle both hyphenated and underscore formats
return id.replace(/_/g, '-').replace(/\s+/g, '-').toLowerCase();
}
// Dynamically add working group pages to structure
for (const [id, group] of Object.entries(workingGroups)) {
const slug = normalizeSlug(id);
structure["working-groups"].push(`${slug}.html`);
}
// Dynamically generate repoTopics from working group repoTags
var repoTopics = {};
for (const [id, group] of Object.entries(workingGroups)) {
if (group.repoTag) {
repoTopics[group.repoTag] = 1;
}
}
var assets = {
js: [
"docs/js/jquery-3.2.1.min.js",
"docs/js/jquery-migrate-3.0.0.min.js",
"docs/plugins/bootstrap/js/popper.min.js",
"docs/plugins/bootstrap/js/bootstrap.min.js",
"docs/js/custom.js",
],
};
var compiledRepos = null;
async function iterateRepos(fn, page = 1) {
return axios
.get(
`https://api.github.com/users/decentralized-identity/repos?type=public&per_page=100&page=${
page || 1
}`,
{
headers: { Accept: "application/vnd.github.mercy-preview+json" },
}
)
.then((response) => {
let repos = response.data;
if (repos && repos.length) {
fn(repos);
if (repos.length === 100) {
return iterateRepos(fn, ++page);
}
}
})
.catch((e) => console.log(e));
}
async function compileRepos() {
if (compiledRepos) return compiledRepos;
compiledRepos = {};
try {
await iterateRepos((repos) => {
repos.forEach((repo) => {
if (repo.topics)
repo.topics.forEach((topic) => {
if (repoTopics[topic]) {
let list = compiledRepos[topic] || (compiledRepos[topic] = []);
list.push(repo);
}
});
});
});
return compiledRepos;
} catch (error) {
return compiledRepos;
}
}
const repoCompilation = compileRepos();
gulp.task("assets", function () {
return gulp
.src(assets.js)
.pipe(uglify())
.pipe(concat("base.js"))
.pipe(gulp.dest("docs/js"));
});
gulp.task("assetsCopy", () => {
return gulp.src([
"assets/**/*",
"assets/favicon.ico",
"assets/favicon.png",
"static/docs/**/*",
".well-known/**/*",
"CNAME"
]).pipe(gulp.dest("docs"));
});
// Add this new function to determine if a working group is archived
function isArchived(group) {
// Check for explicit archived flag first
if (group.archived === true) return true;
return false;
}
// Add this to your "templates" task to make working group navigation data available
gulp.task("templates", async () => {
// Create working group navigation data structure
const activeWGs = [];
const archivedWGs = [];
// Sort working groups into active and archived
for (const [id, group] of Object.entries(workingGroups)) {
const slug = normalizeSlug(id);
const navItem = {
id: id,
name: group.name,
slug: slug,
url: `/working-groups/${slug}.html`
};
if (isArchived(group)) {
archivedWGs.push(navItem);
} else {
activeWGs.push(navItem);
}
}
// Sort alphabetically by name
activeWGs.sort((a, b) => a.name.localeCompare(b.name));
archivedWGs.sort((a, b) => a.name.localeCompare(b.name));
return gulp
.src(["templates/pages/**/*.html.njk", "templates/pages/**/*.html"])
.pipe(
nunjucksRender({
path: ["templates", "templates/partials", "templates/pages"],
data: {
repos: compiledRepos || (await compileRepos()),
workingGroups: workingGroups,
navigation: {
activeWorkingGroups: activeWGs,
archivedWorkingGroups: archivedWGs
}
},
}).on("error", (e) => {
console.log(
`Error in ${
e.fileName ? e.fileName : "(filename not available)"
}: ${e.message.toString()}`
);
})
)
.pipe(
new Transform({
objectMode: true,
transform(file, enc, callback) {
if (file instanceof File) {
if (file.path.endsWith(".html.html")) {
file.path = file.path.slice(0, -5);
}
callback(null, file);
} else {
console.log(file);
callback(
new Error("Error, unexpected type received in pipe"),
null
);
}
},
})
)
.pipe(gulp.dest("./docs"));
});
gulp.task("repoCompilation", (done) => {
repoCompilation.then((z) => done());
});
// Generate working group template files from config
gulp.task("generate-wg-templates", function(done) {
// Load the working groups config
const templateDir = './templates/pages/working-groups';
// Create the directory if it doesn't exist
if (!fs.existsSync(templateDir)) {
fs.mkdirSync(templateDir, { recursive: true });
}
// Generate index file
const indexTemplate = `{% extends "default.html.njk" %}
{% set title = "Working Groups" %}
{% set css = ['directory'] %}
{% block content %}
<section class="page-title theme-bg">
<div class="container">
<h1>Working Groups</h1>
</div>
</section>
<section>
<div class="container">
<!-- Active Working Groups -->
<div class="row mb-5">
<div class="col-md-12">
<h2>Active Working Groups</h2>
<div class="row">
{% for id, group in workingGroups %}
{% if group.status != "archived" %}
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<svg class="me-3"><use xlink:href="/images/icons.svg#{{ group.logo }}"></use></svg>
<h3 class="card-title mb-0">{{ group.name }}</h3>
</div>
{% if group.shortform %}
<p class="text-muted">{{ group.shortform }}</p>
{% endif %}
<p>{{ group.scope | truncate(150) }}</p>
<a href="/working-groups/{{ id | replace("_", "-") }}.html" class="btn btn-primary">Learn More</a>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>
<!-- Archived Working Groups -->
<div class="row">
<div class="col-md-12">
<h2>Completed or Archived Working Groups</h2>
<div class="row">
{% for id, group in workingGroups %}
{% if group.status == "archived" %}
<div class="col-md-6 mb-4">
<div class="card h-100 bg-light">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<svg class="me-3"><use xlink:href="/images/icons.svg#{{ group.logo }}"></use></svg>
<h3 class="card-title mb-0">{{ group.name }}</h3>
</div>
{% if group.shortform %}
<p class="text-muted">{{ group.shortform }}</p>
{% endif %}
<p>{{ group.scope | truncate(150) }}</p>
<a href="/working-groups/{{ id | replace("_", "-") }}.html" class="btn btn-secondary">View Archive</a>
</div>
</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
</section>
{% endblock %}
`;
fs.writeFileSync(path.join(templateDir, `index.html.njk`), indexTemplate);
console.log('Generated working groups index page');
// Generate a template file for each working group
for (const [id, group] of Object.entries(workingGroups)) {
const slug = normalizeSlug(id);
// Simply set the ID to be used to look up the data
const templateContent = `{% extends "wg_base.html.njk" %}
{% set wg_id = "${id}" %}
{% set name = workingGroups[wg_id].name %}
{% set logo = workingGroups[wg_id].logo %}
{% set title = workingGroups[wg_id].title %}
{% set scope = workingGroups[wg_id].scope %}
{% set shortform = workingGroups[wg_id].shortform %}
{% set charters = workingGroups[wg_id].charters %}
{% set projects = workingGroups[wg_id].projects %}
{% set chairs = workingGroups[wg_id].chairs %}
{% set liaison = workingGroups[wg_id].liaison %}
{% set editors = workingGroups[wg_id].editors %}
{% set status = workingGroups[wg_id].status %}
{% set type = workingGroups[wg_id].type %}
{% set repoTag = workingGroups[wg_id].repoTag %}
{% set repoTopics = workingGroups[wg_id].repoTopics %}
{% set meetings = workingGroups[wg_id].meetings %}
`;
fs.writeFileSync(path.join(templateDir, `${slug}.html.njk`), templateContent);
console.log(`Generated template for ${group.name}`);
}
done();
});
gulp.task(
"build",
gulp.series(
"generate-wg-templates",
"repoCompilation",
gulp.parallel("assets", "assetsCopy", "templates")
)
);
gulp.task("watch", () =>
gulp.watch(
["templates/**/*", "docs/js/**/*", "!docs/js/base.js"],
gulp.parallel("build")
)
);