mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 23:42:59 +00:00
website: update all 11ty file to .mjs / ESM modules
This commit is contained in:
parent
1f8ad8e106
commit
39bba6bef1
11 changed files with 76 additions and 92 deletions
|
@ -1,13 +1,15 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
const fs = require("fs");
|
import columnify from "columnify";
|
||||||
const path = require("path");
|
import htmlentities from "html-entities";
|
||||||
|
|
||||||
const columnify = require("columnify");
|
import a from "./lib/Ansi.mjs";
|
||||||
const htmlentities = require("html-entities");
|
import parse_sections from "./lib/parse_sections.mjs";
|
||||||
|
|
||||||
const a = require("./lib/Ansi.js");
|
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
||||||
const parse_sections = require("./lib/parse_sections.js");
|
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
|
||||||
|
|
||||||
let { sections, categories } = parse_sections(fs.readFileSync(
|
let { sections, categories } = parse_sections(fs.readFileSync(
|
||||||
path.resolve(
|
path.resolve(
|
||||||
|
@ -36,7 +38,7 @@ console.log(columnify(Array.from(categories).map(el => { return {
|
||||||
colour: el[1]
|
colour: el[1]
|
||||||
} })));
|
} })));
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
layout: "theme.njk",
|
layout: "theme.njk",
|
||||||
title: "Reference",
|
title: "Reference",
|
||||||
tags: "navigable",
|
tags: "navigable",
|
|
@ -1,6 +1,11 @@
|
||||||
const fs = require("fs");
|
"use strict";
|
||||||
const path = require("path");
|
|
||||||
const htmlentities = require("html-entities");
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import htmlentities from 'html-entities';
|
||||||
|
|
||||||
|
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
||||||
|
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
|
||||||
|
|
||||||
function read_contributors() {
|
function read_contributors() {
|
||||||
return fs.readFileSync(path.resolve(__dirname, "../../CONTRIBUTORS.tsv"), "utf-8")
|
return fs.readFileSync(path.resolve(__dirname, "../../CONTRIBUTORS.tsv"), "utf-8")
|
||||||
|
@ -20,4 +25,4 @@ const contributors = read_contributors();
|
||||||
|
|
||||||
console.log(`CONTRIBUTORS`, contributors);
|
console.log(`CONTRIBUTORS`, contributors);
|
||||||
|
|
||||||
module.exports = contributors;
|
export default contributors;
|
|
@ -10,11 +10,9 @@ import phin from "phin";
|
||||||
import CleanCSS from "clean-css";
|
import CleanCSS from "clean-css";
|
||||||
import { minify as minify_html } from "html-minifier-terser";
|
import { minify as minify_html } from "html-minifier-terser";
|
||||||
|
|
||||||
import UpgradeHelper from "@11ty/eleventy-upgrade-help";
|
import moondoc_runner from "./lib/moondoc_runner.mjs";
|
||||||
|
import HTMLPicture from "./lib/HTMLPicture.mjs";
|
||||||
import moondoc_runner from "./lib/moondoc_runner.js";
|
import FileFetcher from "./lib/FileFetcher.mjs";
|
||||||
import HTMLPicture from "./lib/HTMLPicture.js";
|
|
||||||
import FileFetcher from "./lib/FileFetcher.js";
|
|
||||||
const file_fetcher = new FileFetcher();
|
const file_fetcher = new FileFetcher();
|
||||||
|
|
||||||
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
||||||
|
@ -129,7 +127,6 @@ export default function config(eleventyConfig) {
|
||||||
path.resolve(__dirname, "_site/api/index.html")
|
path.resolve(__dirname, "_site/api/index.html")
|
||||||
);
|
);
|
||||||
|
|
||||||
eleventyConfig.addPlugin(UpgradeHelper);
|
|
||||||
eleventyConfig.addTransform("cssmin", do_minify_css);
|
eleventyConfig.addTransform("cssmin", do_minify_css);
|
||||||
eleventyConfig.addTransform("htmlmin", do_minify_html);
|
eleventyConfig.addTransform("htmlmin", do_minify_html);
|
||||||
|
|
||||||
|
|
9
.docs/eslint.config.mjs
Normal file
9
.docs/eslint.config.mjs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
|
||||||
|
rules: {
|
||||||
|
"prefer-const": "warn",
|
||||||
|
"no-constant-binary-expression": "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
|
@ -85,4 +85,4 @@ class Ansi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new Ansi();
|
export default new Ansi();
|
|
@ -1,12 +1,16 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
import fs from "fs";
|
||||||
const fs = require("fs");
|
import path from "path";
|
||||||
const os = require("os");
|
import os from "os";
|
||||||
|
|
||||||
const phin = require("phin");
|
import phin from "phin";
|
||||||
|
|
||||||
|
import a from "./Ansi.mjs";
|
||||||
|
|
||||||
|
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
||||||
|
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
|
||||||
|
|
||||||
const a = require("./Ansi.js");
|
|
||||||
var pretty_ms = null;
|
var pretty_ms = null;
|
||||||
|
|
||||||
class FileFetcher {
|
class FileFetcher {
|
||||||
|
@ -19,7 +23,7 @@ class FileFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_file(url) {
|
fetch_file(url) {
|
||||||
let target_client = path.join(`/img`, path.basename(url));
|
const target_client = path.join(`/img`, path.basename(url));
|
||||||
|
|
||||||
if(this.#cache.includes(url)) return target_client;
|
if(this.#cache.includes(url)) return target_client;
|
||||||
|
|
||||||
|
@ -37,11 +41,11 @@ class FileFetcher {
|
||||||
|
|
||||||
if(this.#pkg_obj === null) {
|
if(this.#pkg_obj === null) {
|
||||||
this.#pkg_obj = JSON.parse(await fs.promises.readFile(
|
this.#pkg_obj = JSON.parse(await fs.promises.readFile(
|
||||||
path.join(path.dirname(__dirname), "package.json"), "utf8"
|
path.resolve(path.dirname(__dirname), "package.json"), "utf8"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_download = path.join(`_site/img`, path.basename(url));
|
const target_download = path.join(`_site/img`, path.basename(url));
|
||||||
|
|
||||||
const response = await phin({
|
const response = await phin({
|
||||||
url,
|
url,
|
||||||
|
@ -64,4 +68,4 @@ class FileFetcher {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = FileFetcher;
|
export default FileFetcher;
|
|
@ -1,14 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const os = require(`os`);
|
import os from 'os';
|
||||||
const fs = require("fs");
|
import fs from 'fs';
|
||||||
const path = require("path");
|
import path from 'path';
|
||||||
|
|
||||||
const debug = require("debug")("image");
|
import imagickal from 'imagickal';
|
||||||
const imagickal = require("imagickal");
|
import htmlentities from "html-entities";
|
||||||
const htmlentities = require("html-entities");
|
import PQueue from "p-queue";
|
||||||
|
import pMemoize from "p-memoize";
|
||||||
|
import pretty_ms from "pretty-ms";
|
||||||
|
import Debug from 'debug';
|
||||||
|
const debug = Debug("image");
|
||||||
|
|
||||||
const a = require("./Ansi.js");
|
import a from './Ansi.mjs';
|
||||||
|
|
||||||
function calculate_size(width, height, size_spec) {
|
function calculate_size(width, height, size_spec) {
|
||||||
if(size_spec.indexOf("%") > -1) {
|
if(size_spec.indexOf("%") > -1) {
|
||||||
|
@ -34,7 +38,6 @@ var queue = null;
|
||||||
|
|
||||||
async function make_queue() {
|
async function make_queue() {
|
||||||
// 1: Setup task queue
|
// 1: Setup task queue
|
||||||
const PQueue = (await import("p-queue")).default;
|
|
||||||
let concurrency = os.cpus().length;
|
let concurrency = os.cpus().length;
|
||||||
if(process.env["MAX_CONCURRENT"])
|
if(process.env["MAX_CONCURRENT"])
|
||||||
concurrency = parseInt(process.env["MAX_CONCURRENT"], 10);
|
concurrency = parseInt(process.env["MAX_CONCURRENT"], 10);
|
||||||
|
@ -142,16 +145,8 @@ async function picture(source_image, alt, target_dir, urlpath, formats = "__AUTO
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var picture_memoize = null;
|
var picture_memoize = pMemoize(picture);
|
||||||
var pretty_ms;
|
|
||||||
|
|
||||||
async function setup_memoize() {
|
export default async function(...args) {
|
||||||
const pMemoize = (await import("p-memoize")).default;
|
|
||||||
picture_memoize = pMemoize(picture);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = async function(...args) {
|
|
||||||
if(picture_memoize === null) await setup_memoize();
|
|
||||||
pretty_ms = (await import("pretty-ms")).default;
|
|
||||||
return await picture_memoize(...args);
|
return await picture_memoize(...args);
|
||||||
};
|
};
|
|
@ -1,14 +1,17 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const promisify = require("util").promisify;
|
import { promisify } from "util";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const child_process = require("child_process");
|
import child_process from "child_process";
|
||||||
|
|
||||||
|
// HACK: Make sure __dirname is defined when using es6 modules. I forget where I found this - a PR with a source URL would be great!
|
||||||
|
const __dirname = import.meta.url.slice(7, import.meta.url.lastIndexOf("/"));
|
||||||
|
|
||||||
const filepath_moondoc = path.resolve(__dirname, `../node_modules/.bin/moondoc`);
|
const filepath_moondoc = path.resolve(__dirname, `../node_modules/.bin/moondoc`);
|
||||||
const dirpath_root = path.resolve(__dirname, `../..`);
|
const dirpath_root = path.resolve(__dirname, `../..`);
|
||||||
|
|
||||||
module.exports = function moondoc_runner(filepath_output) {
|
export default function moondoc_runner(filepath_output) {
|
||||||
const dirpath = path.dirname(filepath_output);
|
const dirpath = path.dirname(filepath_output);
|
||||||
if(!fs.existsSync(dirpath)) {
|
if(!fs.existsSync(dirpath)) {
|
||||||
fs.mkdirSync(dirpath, { recursive: true });
|
fs.mkdirSync(dirpath, { recursive: true });
|
|
@ -1,14 +1,18 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const crypto = require("crypto");
|
import crypto from "crypto";
|
||||||
|
|
||||||
const htmlentities = require("html-entities");
|
import htmlentities from "html-entities";
|
||||||
const markdown = require("markdown-it")({
|
import MarkdownIt from "markdown-it";
|
||||||
|
import chroma from "chroma-js";
|
||||||
|
|
||||||
|
import markdown_prism from "markdown-it-prism";
|
||||||
|
import markdown_alerts from "markdown-it-github-alerts";
|
||||||
|
|
||||||
|
const markdown = new MarkdownIt({
|
||||||
xhtmlOut: true
|
xhtmlOut: true
|
||||||
});
|
});
|
||||||
const chroma = require("chroma-js");
|
|
||||||
|
|
||||||
const markdown_prism = require("markdown-it-prism");
|
|
||||||
markdown.use(markdown_prism, {
|
markdown.use(markdown_prism, {
|
||||||
init: (Prism) => {
|
init: (Prism) => {
|
||||||
Prism.languages.weacmd = {
|
Prism.languages.weacmd = {
|
||||||
|
@ -21,8 +25,7 @@ markdown.use(markdown_prism, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const alerts = require("markdown-it-github-alerts");
|
markdown.use(markdown_alerts);
|
||||||
markdown.use(alerts);
|
|
||||||
|
|
||||||
function extract_title(line) {
|
function extract_title(line) {
|
||||||
return line.match(/#+\s+(.+)\s*/)[1].replace(/^`*|`*$/g, "")
|
return line.match(/#+\s+(.+)\s*/)[1].replace(/^`*|`*$/g, "")
|
||||||
|
@ -47,7 +50,7 @@ function make_section(acc, cat_current, cats) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function parse_sections(source) {
|
export default function parse_sections(source) {
|
||||||
const cats = new Map();
|
const cats = new Map();
|
||||||
source.match(/^##\s+.*$/gm)
|
source.match(/^##\s+.*$/gm)
|
||||||
.map(extract_title)
|
.map(extract_title)
|
33
.docs/package-lock.json
generated
33
.docs/package-lock.json
generated
|
@ -10,7 +10,6 @@
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@11ty/eleventy": "^3.0.0",
|
"@11ty/eleventy": "^3.0.0",
|
||||||
"@11ty/eleventy-upgrade-help": "^3.0.1",
|
|
||||||
"chroma-js": "^3.1.1",
|
"chroma-js": "^3.1.1",
|
||||||
"clean-css": "^5.3.2",
|
"clean-css": "^5.3.2",
|
||||||
"columnify": "^1.6.0",
|
"columnify": "^1.6.0",
|
||||||
|
@ -163,26 +162,6 @@
|
||||||
"url": "https://opencollective.com/11ty"
|
"url": "https://opencollective.com/11ty"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@11ty/eleventy-upgrade-help": {
|
|
||||||
"version": "3.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@11ty/eleventy-upgrade-help/-/eleventy-upgrade-help-3.0.1.tgz",
|
|
||||||
"integrity": "sha512-69CttBBfplByurn5vW7eRiLPywZZZHCH6B68Ib3t3348PaHHG9RysVPRqPQzMrGIEEbXg+0+ICm+R8sAkgjfPQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"fast-glob": "^3.3.2",
|
|
||||||
"kleur": "^4.1.5",
|
|
||||||
"minimist": "^1.2.8",
|
|
||||||
"posthtml-match-helper": "^2.0.2",
|
|
||||||
"semver": "^7.6.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/11ty"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@11ty/eleventy-utils": {
|
"node_modules/@11ty/eleventy-utils": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@11ty/eleventy-utils/-/eleventy-utils-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@11ty/eleventy-utils/-/eleventy-utils-1.0.3.tgz",
|
||||||
|
@ -3351,18 +3330,6 @@
|
||||||
"posthtml-match-helper": "^2.0.2"
|
"posthtml-match-helper": "^2.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@11ty/eleventy-upgrade-help": {
|
|
||||||
"version": "3.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@11ty/eleventy-upgrade-help/-/eleventy-upgrade-help-3.0.1.tgz",
|
|
||||||
"integrity": "sha512-69CttBBfplByurn5vW7eRiLPywZZZHCH6B68Ib3t3348PaHHG9RysVPRqPQzMrGIEEbXg+0+ICm+R8sAkgjfPQ==",
|
|
||||||
"requires": {
|
|
||||||
"fast-glob": "^3.3.2",
|
|
||||||
"kleur": "^4.1.5",
|
|
||||||
"minimist": "^1.2.8",
|
|
||||||
"posthtml-match-helper": "^2.0.2",
|
|
||||||
"semver": "^7.6.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@11ty/eleventy-utils": {
|
"@11ty/eleventy-utils": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@11ty/eleventy-utils/-/eleventy-utils-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@11ty/eleventy-utils/-/eleventy-utils-1.0.3.tgz",
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
"homepage": "https://github.com/sbrl/Minetest-WorldEditAdditions#readme",
|
"homepage": "https://github.com/sbrl/Minetest-WorldEditAdditions#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@11ty/eleventy": "^3.0.0",
|
"@11ty/eleventy": "^3.0.0",
|
||||||
"@11ty/eleventy-upgrade-help": "^3.0.1",
|
|
||||||
"chroma-js": "^3.1.1",
|
"chroma-js": "^3.1.1",
|
||||||
"clean-css": "^5.3.2",
|
"clean-css": "^5.3.2",
|
||||||
"columnify": "^1.6.0",
|
"columnify": "^1.6.0",
|
||||||
|
|
Loading…
Reference in a new issue