0.1.0: introducing ymake

`ymake` is an alternative to `gmake` for node22+ using the new glob method.
This commit is contained in:
yellows111 2024-05-09 12:14:50 +01:00
parent c91c09e606
commit 95d0a3a106
6 changed files with 150 additions and 23 deletions

View File

@ -20,31 +20,60 @@ MIT. Review the `LICENSE` file if required.
## How to use ## How to use
You need a copy of GNU make (GPL-3 licensed software). `node ymake`, set options using `export` commands.
Use the `gmake` (or if it's the system makefile parser, `make`) command An alternative makefile for GNU make is avaliable if it is prefered.
after writing Markdown (\*.md) files to the `docs` directory.
Afterwards, check the `build` directory for the `.html` files. Either way, you'll want to write Markdown (\*.md) files to the
`docs` (which is the default `SRC_DIRS`) directory.
Afterwards, check the `build` (`BUILD_DIR`) directory for the `.html` files.
Otherwise, if you just want to use `yiki` to render one file: Otherwise, if you just want to use `yiki` to render one file:
`node compile source.md target.htm` `node compile source.md target.htm`
## Options ## Options
`SRC_DIRS` Specify the directory which `yiki` compiles files from.
ymake: `export SRC_DIRS="./input"`
GMake: `gmake SRC_DIRS="./input"`
`BUILD_DIR` Specify the directory which `yiki` compiles files into.
ymake: `export BUILD_DIR="./output"`
GMake: `gmake BUILD_DIR="./output"`
`WIKINAME` Specify what the "A new yiki!" text should be replaced with. `WIKINAME` Specify what the "A new yiki!" text should be replaced with.
Example: `gmake WIKINAME="I love options!"` ymake: `export WIKINAME="I love options!"`
GMake: `gmake WIKINAME="I love options!"`
`VPREFIX` Specify the virtual root of that the default template links to `VPREFIX` Specify the virtual root of that the default template links to
for the `yiki.css` and the `index.html` files. for the `yiki.css` and the `index.html` files.
Example: `gmake VPREFIX:="/yiki/"` ymake: `export VPREFIX="/yiki/"`
GMake: `gmake VPREFIX:="/yiki/"`
`DOMAIN` Specifiy the domain name that your sitemap.xml links to. `DOMAIN` Specifiy the domain name that your sitemap.xml links to.
Example `gmake DOMAIN:="example.com"` ymake: `export DOMAIN="example.com"`
GMake: `gmake DOMAIN:="example.com"`
## Contributing ## Contributing

View File

@ -32,12 +32,12 @@ const Process = require("process");
const Filesystem = require("fs"); const Filesystem = require("fs");
const Path = require("path"); const Path = require("path");
if(Process.argv.length < 4) { if(Process.argv.length < 4 && require.main === module) {
console.error("You need a source.md and target.htm path!"); console.error("You need a source.md and target.htm path!");
Process.exit(1); Process.exit(1);
} }
function render(input, options) { function markup(input, options) {
let tableOfContents = new Remarkable().use(TOCGenerator.plugin(options)).render(input); let tableOfContents = new Remarkable().use(TOCGenerator.plugin(options)).render(input);
let output = new Remarkable().use(RemarkableHeaderIDs()).render("# Table of contents:\n"+tableOfContents.content+"\n"+input); let output = new Remarkable().use(RemarkableHeaderIDs()).render("# Table of contents:\n"+tableOfContents.content+"\n"+input);
return output; return output;
@ -105,5 +105,9 @@ function format(data, name) {
); /* eslint-enable indent */ ); /* eslint-enable indent */
} }
let content = render(Filesystem.readFileSync(Process.argv[2]).toString()); module.exports = {"markup": markup, "format": format};
Filesystem.writeFileSync(Process.argv[3], format(content, Path.basename(Process.argv[3], ".html").replace(/_/g, " ")));
if(require.main === module) {
let content = markup(Filesystem.readFileSync(Process.argv[2]).toString());
Filesystem.writeFileSync(Process.argv[3], format(content, Path.basename(Process.argv[3], ".html").replace(/_/g, " ")));
}

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "yiki", "name": "yiki",
"version": "0.0.7", "version": "0.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "yiki", "name": "yiki",
"version": "0.0.7", "version": "0.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@liquify/prettify": "^0.5.5-beta.1", "@liquify/prettify": "^0.5.5-beta.1",

View File

@ -1,10 +1,10 @@
{ {
"name": "yiki", "name": "yiki",
"version": "0.0.7", "version": "0.1.0",
"description": "The yellows111 wiki system", "description": "The yellows111 wiki system",
"main": "compile.js", "main": "compile.js",
"scripts": { "scripts": {
"build": "gmake" "build": "node ymake"
}, },
"keywords": [ "keywords": [
"markdown" "markdown"

View File

@ -23,8 +23,7 @@ const Process = require("process");
const Filesystem = require("fs"); const Filesystem = require("fs");
// required vars // required vars
const fileList = Process.argv.slice(3);
const currentDir = Process.argv[2];
var rootPrefix = "/"; var rootPrefix = "/";
if(process.env["VPREFIX"]) { if(process.env["VPREFIX"]) {
rootPrefix = process.env["VPREFIX"]; rootPrefix = process.env["VPREFIX"];
@ -40,19 +39,33 @@ function renderSiteMap() {
return ( /* eslint-disable indent */ return ( /* eslint-disable indent */
`<?xml version="1.0" encoding="UTF-8"?> `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${outputTemp} ${outputTemp}</urlset>
</urlset>
` `
); /* eslint-enable indent */ ); /* eslint-enable indent */
} }
for (let file of fileList) { function makeSitemapChunk(file, outputDir) {
outputTemp = outputTemp.concat( /* eslint-disable indent */ outputTemp = outputTemp.concat( /* eslint-disable indent */
` <url> ` <url>
<loc>https://${targetDomain}${rootPrefix}${file.replace(currentDir, "")}</loc> <loc>https://${targetDomain}${rootPrefix}${file.replace(outputDir, "")}</loc>
<lastmod>${Filesystem.statSync(file).mtime.toISOString().substring(0, 10)}</lastmod> <lastmod>${Filesystem.statSync(file).mtime.toISOString().substring(0, 10)}</lastmod>
</url>` </url>
`
); /* eslint-enable indent */ ); /* eslint-enable indent */
} }
Filesystem.writeFileSync(`${Process.argv[2]}/sitemap.xml`, renderSiteMap()); if(require.main === module) {
const fileList = Process.argv.slice(3);
const currentDir = Process.argv[2];
for (let file of fileList) {
makeSitemapChunk(file, currentDir);
}
Filesystem.writeFileSync(`${Process.argv[2]}/sitemap.xml`, renderSiteMap());
}
module.exports = function(fileList, filter) {
for (let file of fileList) {
makeSitemapChunk(file, filter);
}
return renderSiteMap();
}

81
ymake.js Normal file
View File

@ -0,0 +1,81 @@
// Copyright (c) 2024 yellows111
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
const Process = require("node:process");
const Filesystem = require("node:fs");
const Path = require("node:path");
// yellows111 make - yiki makefile, v1
const Compiler = require("./compile.js")
var BUILD_DIR = "./build";
var SRC_DIRS = "./docs";
if(process.env["BUILD_DIR"]) {
BUILD_DIR = process.env["BUILD_DIR"];
}
if(process.env["SRC_DIRS"]) {
SRC_DIRS = process.env["SRC_DIRS"];
}
const MARKDOWN_L = Filesystem.globSync(`${SRC_DIRS}/**/*.md`);
MARKDOWN_L.forEach(function(file) {
console.log("MARKER: "+file);
try {
Filesystem.statSync(
Path.dirname(
file.replace(Path.normalize(SRC_DIRS), Path.normalize(BUILD_DIR))
)
);
} catch(err) {
if(err.code === "ENOENT") {
let rpath = Path.dirname(file.replace(Path.normalize(SRC_DIRS), Path.normalize(BUILD_DIR)));
console.log(`creating ${rpath}/`);
Filesystem.mkdirSync(rpath, {"recursive": true});
} else {
throw err;
}
};
Filesystem.writeFileSync(
file.replace(Path.normalize(SRC_DIRS), Path.normalize(BUILD_DIR)).replace(".md", ".html"),
Compiler.format(
Compiler.markup(Filesystem.readFileSync(file).toString()),
Path.basename(file, ".md").replace(/_/g, " ")
)
);
});
Filesystem.globSync(`${SRC_DIRS}/**/*.css`).forEach(function(file) {
console.log("COPY: "+file);
Filesystem.copyFileSync(file, file.replace(/docs/, "build"));
});
Filesystem.writeFileSync(Path.normalize(BUILD_DIR+"/sitemap.xml"),
require("./sitemap-gen.js")(
MARKDOWN_L.map(function(filename){
return Path.dirname(filename).replace(/\\/g, "/").replace(/\.md/g, ".html")
}),
Path.normalize(SRC_DIRS)
)
);
console.log(`SMAP: ${Path.normalize(BUILD_DIR+"/sitemap.xml")}`);