GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — devjava-content/gulpfile.js at main · dancer1325/devjava-content Expand file tree/ Copy pathgulpfile.jsMore file actions 527 lines (441 loc) · 19.1 KB / Copy pathgulpfile.jsFile metadata and controls527 lines (441 loc) · 19.1 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 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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 const { watch, series, src, dest } = require('gulp'); var sass = require('gulp-sass')(require('sass')); var del = require('del'); var fs = require('fs'); var frontMatter = require('gulp-front-matter'); var toc = require('gulp-markdown-toc'); var markdown = require('gulp-markdown'); var wrap = require('gulp-wrap'); var swig = require('gulp-swig'); var data = require('gulp-data'); var browserSync = require('browser-sync').create(); const { DateTime } = require("luxon"); var yaml = require('js-yaml'); const nunjucks = require('nunjucks'); var tutorials = {}; var links = {}; var link_map = new Map(); var link_title_map = new Map(); var authorsMap = new Map(); var authorsArray = yaml.load(fs.readFileSync('app/data/authors.yaml', 'utf8')) for (const author of authorsArray) { authorsMap[getAuthorID(author.name)] = author; authorsMap[getAuthorID(author.name)].tutorials = []; } var javadoc = require('./app/data/javadoc.json') var javafxdoc = require('./app/data/javafxdoc.json') var jep = require('./app/data/jep.json') function getAuthorID(name) { return name.replace(/\s/g, '') } function copy_assets() { return src("app/assets/**/*.*") .pipe(dest("site/assets")); } function sassify() { return src("app/scss/*.scss") .pipe(sass()) .pipe(dest("site/assets/css")); } function pre_process_pages() { tutorials = { "tutorials": {} } links = { "links": {} } return src('app/pages/**/*.md', { silent: false, debug: false }) .pipe(frontMatter({ property: 'fm', remove: true })) .pipe(data(function (file) { if (file.fm.title) file.fm.title_html = markdown.marked.parseInline(file.fm.title) if (file.fm.description) file.fm.description_html = markdown.marked(file.fm.description) })) .pipe(data(function (file) { const type = file.fm.type; if (is_tutorial(file)) { const category = file.fm.category const category_order = file.fm.category_order const title = file.fm.title const title_html = file.fm.title_html const description = file.fm.description const description_html = file.fm.description_html const group = file.fm.group const id = file.fm.id if (!file.fm.slug) { console.log("Tutorial page " + id + " doesn't have a slug"); } const path = generate_url_structure(file).newrelative.replace(".md", ".html") const tutorial_json = { title, title_html, path, description, description_html, group, category_order } if (file.fm.id) { link_map.set(file.fm.id, path); } link_title_map.set(path, title); elements = path.split("/").filter(element => element.length > 0); if (path.endsWith("/")) { elements[elements.length - 1] += "/"; } links = []; for (i = 0; i < elements.length - 1; i++) { link = elements.slice(0, i + 1).join("/") + "/"; links.push(link); } link_titles = []; for (link of links) { link_title = link_title_map.get(link); if (link_title) { link_json = { link, link_title }; link_titles.push(link_json); } } if (type == "tutorial") { if (tutorials["tutorials"][category]) { tutorials["tutorials"][category].push(tutorial_json); } else { tutorials["tutorials"][category] = [tutorial_json]; } } if (group) { if (!tutorials["tutorials"][group]) { tutorials["tutorials"][group] = []; } if (type == "tutorial-group") { tutorials["tutorials"][group].push(tutorial_json); } else if (type == "tutorial") { tutorials["tutorials"][group]["parent_link"] = path; tutorials["tutorials"][group]["parent_title"] = file.fm.title; tutorials["tutorials"][group]["parent_title_html"] = file.fm.title_html; } tutorials["tutorials"][group][id] = []; tutorials["tutorials"][group][id]["breadcrumb"] = link_titles; } } if (file.fm.other_links) { const group = file.fm.group if (!tutorials["tutorials"][group]["doc_links"]) { tutorials["tutorials"][group]["doc_links"] = []; } if (!tutorials["tutorials"][group]["related_pages"]) { tutorials["tutorials"][group]["related_pages"] = []; } for (let link of file.fm.other_links) { let link_id = link.match(/doc:([\w|\.|-]+)/); if (link_id != null && javadoc[link_id[1]]) { let processedLink = processDocLink(javadoc[link_id[1]]["link"]); let text = javadoc[link_id[1]]["text"] tutorials["tutorials"][group]["doc_links"].push({ "path": processedLink, "title_html": text }) } else if (link_id != null && javafxdoc[link_id[1]]) { console.log(javafxdoc[link_id[1]]); let processedLink = processDocLink(javafxdoc[link_id[1]]["link"]); let text = javafxdoc[link_id[1]]["text"] tutorials["tutorials"][group]["doc_links"].push({ "path": processedLink, "title_html": text }) } let page_id = link.match(/related_page:([\w|\.|-]+)/); if (page_id != null && link_map.get(page_id[1])) { let linkPath = link_map.get(page_id[1]) let title = link_title_map.get(linkPath) tutorials["tutorials"][group]["related_pages"].push({ "path": linkPath, "title_html": title }) } } } })) .pipe(data(function (file) { if (file.fm.author) { if (file.fm.author.length > 1) { console.log("Adding tutorial " + file.fm.id + " to multiple authors: " + file.fm.author); for (const author of file.fm.author) { authorsMap[author].tutorials.push(file.fm.id); } } else { console.log("Adding tutorial " + file.fm.id + " to single author: " + file.fm.author); authorsMap[file.fm.author].tutorials.push(file.fm.id); } } })) } function pages() { const renderer = { link(href, title, text) { let processedHref = href; if (href.includes("id:")) { let page_id = href.match(/id:([\w|\.|-]+)/); if (page_id != null) { let anchor = href.match(/#[\w|-]+/); var link = ''; let page_link = link_map.get(page_id[1]); processedHref = "/" + page_link; if (processedHref.includes("undefined")) { console.log("Page " + page_id[1] + " resolved to undefined"); } if (anchor) { processedHref = processedHref + anchor; } } else { console.log("Null page id link for href " + href); } } if (href.includes("javadoc:")) { let javadoc_id = href.match(/javadoc:([\w\.\-(),]+)/) if (javadoc_id != null) { processedHref = processDocLink(javadoc["javadoc_root"] + javadoc[javadoc_id[1]]); if (processedHref.includes("undefined")) { console.log("Javadoc " + javadoc_id[1] + " resolved to undefined"); } return `<a href="${processedHref}" target="_blank" rel="noopener noreferrer">${text}</a>`; } } if (href.includes("javafxdoc:")) { let javafxdoc_id = href.match(/javafxdoc:([\w\.\-(),]+)/) if (javafxdoc_id != null) { processedHref = processJavaFxDocLink(javafxdoc["javafxdoc_root"] + javafxdoc[javafxdoc_id[1]]); if (processedHref.includes("undefined")) { console.log("JavaFX Javadoc " + javafxdoc_id[1] + " resolved to undefined"); } return `<a href="${processedHref}" target="_blank" rel="noopener noreferrer">${text}</a>`; } } if (href.includes("doc:")) { let doc_id = href.match(/doc:([\w\.\-(),]+)/); if (doc_id != null) { if (javadoc[doc_id[1]]["text"] != null) { processedHref = processDocLink("" + javadoc[doc_id[1]]["link"]) } else { processedHref = processDocLink("" + javadoc[doc_id[1]]) } if (processedHref.includes("undefined")) { console.log("Doc " + doc_id[1] + " resolved to undefined"); } return `<a href="${processedHref}" target="_blank" rel="noopener noreferrer">${text}</a>`; } } if (href.includes("jep:")) { let jep_id = href.match(/jep:([\d]+)/); if (jep_id != null) { if (jep[jep_id[1]] == undefined) { console.log("JEP " + jep_id[1] + " is not defined"); } else { processedHref = jep["root"] + jep_id[1]; let anchor = href.match(/#[\w|-]+/); if (anchor) { processedHref = processedHref + anchor; } if (jep[jep_id[1]]["status"] == "preview" && jep[jep_id[1]]["version"] != javadoc["current_release"]) { console.log( "Current release is " + javadoc["current_release"] + ", JEP " + jep_id[1] + " is a preview of " + jep[jep_id[1]]["version"] + " and still referenced"); } if (jep[jep_id[1]]["status"] == "incubator" && jep[jep_id[1]]["version"] != javadoc["current_release"]) { console.log( "Current release is " + javadoc["current_release"] + ", JEP " + jep_id[1] + " is an incubator of " + jep[jep_id[1]]["version"] + " and still referenced"); } if (jep[jep_id[1]]["title"]) { text = "JEP " + jep_id[1] + ": " + jep[jep_id[1]]["title"]; } else { text = "JEP " + jep_id[1] + ": " + jep[jep_id[1]]; } return `<a href="${processedHref}" target="_blank" rel="noopener noreferrer">${text}</a>`; } } } if (title) { link = `<a href="${processedHref}" title="${title}">${text}</a>`; } else { link = `<a href="${processedHref}">${text}</a>`; } return link; }, heading(text, level, raw, slugger) { const richHeader = parseRichHeader(text) text = richHeader.text if (this.options.headerIds) { const slug = richHeader.slug ?? this.options.headerPrefix + slugger.slug(raw) return '<h' + level + ' id="' + slug + '">' + text + '</h' + level + '>\n'; } return '<h' + level + '>' + text + '</h' + level + '>\n'; } }; markdown.marked.use({ headerIds: true, headerPrefix: '' }); markdown.marked.use({ renderer }); var mystream = src('app/pages/**/*.md', { silent: false, debug: false }) .pipe(frontMatter({ property: 'fm', remove: true })) .pipe(data(function (file) { if (file.fm.title) file.fm.title_html = markdown.marked.parseInline(file.fm.title) if (file.fm.description) file.fm.description_html = markdown.marked(file.fm.description) })) .pipe(data(process_last_update)) .pipe(data(function (file) { generate_url_structure(file); })) .pipe(data(function () { return tutorials })) .pipe(toc()) .pipe(data(function (file) { if (file.fm.toc) { const section_name_regex = /^[\s\w.,|]+[^{|^\s{]+/; const anchor_regex = /{([^{|^}]+)}/; file.fm.toc = file.fm.toc .map(entry => ({ sectionName: entry.match(section_name_regex)[0], anchorsArray: entry.match(anchor_regex) })) .map(({ sectionName, anchorsArray }, index) => ({ text: sectionName, html: sectionName, slug: (anchorsArray == null || anchorsArray.length == 0) ? `anchor_${index + 1}` : anchorsArray[1] })) } else { file.fm.toc = file.toc.json .filter(entry => entry.lvl === 2) .map(entry => { const richHeader = parseRichHeader(entry.content) return { text: richHeader.text, html: richHeader.html, slug: richHeader.slug ?? entry.slug } }) } if (file.fm.more_learning) { file.fm.toc.push({ text: "More Learning", html: "More Learning", slug: "more-learning" }); } })) .pipe(data(function () { let data = {} data.env = process.env; data.authorsMap = authorsMap; data.authorsArray = authorsArray; data.linkMap = link_map; data.linkTitleMap = link_title_map; return data; })) .pipe(swig({ defaults: { cache: false } })) .pipe(markdown()) .pipe(wrap(function (data) { return fs.readFileSync('app/templates/pages/' + data.file.fm.layout).toString() }, null, { engine: 'nunjucks' })) .pipe(data(function (file) { if (file.relative == "author/index.html") { var template = fs.readFileSync('app/templates/pages/authors/author.html').toString(); for (const author of authorsArray) { let nameId = getAuthorID(author.name); let authorPage = nunjucks.renderString(template, { author: author, file: file }); let newFilePath = file.cwd + "/site/author/" + nameId + "/index.html"; writeFile(newFilePath, authorPage, err => { if (err) { console.error(err); } }); } } })) .pipe(dest('site')) .pipe(browserSync.stream()); return mystream; } var getDirName = require('path').dirname; function writeFile(path, contents, cb) { fs.mkdir(getDirName(path), { recursive: true }, function (err) { if (err) return cb(err); fs.writeFile(path, contents, cb); }); } function processDocLink(link) { return link.replace("@@CURRENT_RELEASE@@", javadoc[`current_release`]); } function processJavaFxDocLink(link) { return link.replace("@@CURRENT_RELEASE@@", javafxdoc[`current_release`]).replace("@@RELEASE_UUID@@", javafxdoc[`release_uuid`]); } function is_tutorial(file) { return file.fm.type == "tutorial" || file.fm.type == "tutorial-group"; } function serve(done) { browserSync.init({ server: { baseDir: './site/' } }); watch("app/**/*.md", {interval: 1000, usePolling: true}, series(build)); watch("app/**/*.html", {interval: 1000, usePolling: true}, series(build)); watch("app/scss/*.scss", {interval: 1000, usePolling: true}, series(build)); watch("site/**/", {interval: 1000, usePolling: true}, browserSync.reload()); done(); } function cleanup() { return del([ 'site' ]); } function process_last_update(file) { const update = file.fm.last_update ?? new Date("2021-09-14") const review = file.fm.last_review const showReview = review && update < review const type = showReview ? "review" : "update" const date = DateTime .fromJSDate(showReview ? review : update) .setLocale('en-us') .toLocaleString(DateTime.DATE_FULL) file.fm.last_update = { type, date } } function parseRichHeader(header) { const parsed = header.match(/^(?<text>.*[^\}]) ?(?<config>\{#(?<slug>.+)\})?$/) if (parsed === null) throw new Error(`Illegal header "${header}" - check gulpfile.js for details.`) return { ...parsed.groups, html: markdown.marked.parseInline(parsed.groups.text) } } function generate_url_structure(file) { if (file.fm.slug) { file.basename = "index.html"; file.dirname = file.cwd + "/app/pages/" + file.fm.slug; file.newrelative = file.fm.slug + "/"; } else { const reg = /^\d+_/g; file.basename = file.basename.replace(reg, ""); const olddir = file.dirname.split('\\').join('/'); const newdir = olddir.split('/').map(element => element.replace(reg, "")).join('/'); file.dirname = newdir; const oldrelative = file.relative.split('\\').join('/') const newrelative = oldrelative.split('/').map(element => element.replace(reg, "")).join('/'); file.newrelative = newrelative } return file; } var build = series(cleanup, copy_assets, sassify, pre_process_pages, pages); var deploy = series(cleanup, build); // local development only (by typing `gulp`) exports.default = series(build, serve); // Export for use at the command line exports.serve = serve; exports.pages = pages; exports.clean = cleanup; exports.build = build; exports.deploy = deploy; |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |