0.1.0: introducing ymake
`ymake` is an alternative to `gmake` for node22+ using the new glob method.
This commit is contained in:
parent
c91c09e606
commit
95d0a3a106
43
README.md
43
README.md
|
@ -20,31 +20,60 @@ MIT. Review the `LICENSE` file if required.
|
|||
|
||||
## 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
|
||||
after writing Markdown (\*.md) files to the `docs` directory.
|
||||
An alternative makefile for GNU make is avaliable if it is prefered.
|
||||
|
||||
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:
|
||||
|
||||
`node compile source.md target.htm`
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
Example `gmake DOMAIN:="example.com"`
|
||||
ymake: `export DOMAIN="example.com"`
|
||||
|
||||
GMake: `gmake DOMAIN:="example.com"`
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
10
compile.js
10
compile.js
|
@ -32,12 +32,12 @@ const Process = require("process");
|
|||
const Filesystem = require("fs");
|
||||
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!");
|
||||
Process.exit(1);
|
||||
}
|
||||
|
||||
function render(input, options) {
|
||||
function markup(input, options) {
|
||||
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);
|
||||
return output;
|
||||
|
@ -105,5 +105,9 @@ function format(data, name) {
|
|||
); /* eslint-enable indent */
|
||||
}
|
||||
|
||||
let content = render(Filesystem.readFileSync(Process.argv[2]).toString());
|
||||
module.exports = {"markup": markup, "format": format};
|
||||
|
||||
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, " ")));
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "yiki",
|
||||
"version": "0.0.7",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "yiki",
|
||||
"version": "0.0.7",
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@liquify/prettify": "^0.5.5-beta.1",
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "yiki",
|
||||
"version": "0.0.7",
|
||||
"version": "0.1.0",
|
||||
"description": "The yellows111 wiki system",
|
||||
"main": "compile.js",
|
||||
"scripts": {
|
||||
"build": "gmake"
|
||||
"build": "node ymake"
|
||||
},
|
||||
"keywords": [
|
||||
"markdown"
|
||||
|
|
|
@ -23,8 +23,7 @@ const Process = require("process");
|
|||
const Filesystem = require("fs");
|
||||
|
||||
// required vars
|
||||
const fileList = Process.argv.slice(3);
|
||||
const currentDir = Process.argv[2];
|
||||
|
||||
var rootPrefix = "/";
|
||||
if(process.env["VPREFIX"]) {
|
||||
rootPrefix = process.env["VPREFIX"];
|
||||
|
@ -40,19 +39,33 @@ function renderSiteMap() {
|
|||
return ( /* eslint-disable indent */
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
${outputTemp}
|
||||
</urlset>
|
||||
${outputTemp}</urlset>
|
||||
`
|
||||
); /* eslint-enable indent */
|
||||
}
|
||||
|
||||
for (let file of fileList) {
|
||||
function makeSitemapChunk(file, outputDir) {
|
||||
outputTemp = outputTemp.concat( /* eslint-disable indent */
|
||||
` <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>
|
||||
</url>`
|
||||
</url>
|
||||
`
|
||||
); /* eslint-enable indent */
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
|
@ -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")}`);
|
Loading…
Reference in New Issue