diff --git a/GNUmakefile b/GNUmakefile index f534db5..87abc07 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -19,13 +19,14 @@ # DEALINGS IN THE SOFTWARE. MARKER = node compile +SITEMAPGEN = node sitemap-gen BUILD_DIR = ./build SRC_DIRS = ./docs MARKDOWN_L = $(patsubst %.md,%.html,$(shell find $(SRC_DIRS) -name "*.md")) COPY_L = $(patsubst %.css,%.justcopytobuilddir,$(shell find $(SRC_DIRS) -name "*.css")) -all: $(MARKDOWN_L) $(COPY_L) +all: $(MARKDOWN_L) $(COPY_L) make_sitemap $(MARKDOWN_L): %.html: %.md $(COPY_L): %.justcopytobuilddir: %.css @@ -38,4 +39,7 @@ $(COPY_L): %.justcopytobuilddir: %.css %.justcopytobuilddir: cp -f $< $(BUILD_DIR) +make_sitemap: + $(SITEMAPGEN) $(BUILD_DIR) $(subst $(SRC_DIRS),$(BUILD_DIR),$(MARKDOWN_L)) + # end of GNUmakefile diff --git a/README.md b/README.md index 5b9fcb8..7bf147d 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ for the `yiki.css` and the `index.html` files. Example: `gmake VPREFIX:="/yiki/"` +`DOMAIN` Specifiy the domain name that your sitemap.xml links to. + +Example `gmake DOMAIN:="example.com"` + ## Contributing I request (but not require) that you modify files without Carriage Returns, diff --git a/package-lock.json b/package-lock.json index 04126d0..39bdae6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "yiki", - "version": "0.0.6", + "version": "0.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "yiki", - "version": "0.0.6", + "version": "0.0.7", "license": "MIT", "dependencies": { "@liquify/prettify": "^0.5.5-beta.1", diff --git a/package.json b/package.json index f3d2270..1c51b4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yiki", - "version": "0.0.6", + "version": "0.0.7", "description": "The yellows111 wiki system", "main": "compile.js", "scripts": { diff --git a/sitemap-gen.js b/sitemap-gen.js new file mode 100644 index 0000000..785e60f --- /dev/null +++ b/sitemap-gen.js @@ -0,0 +1,58 @@ +// 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. + +// natives +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"]; +} +rootPrefix = rootPrefix.substring(0, rootPrefix.length - 1); +var targetDomain = "localhost"; +if(process.env["DOMAIN"]) { + targetDomain = process.env["DOMAIN"]; +} +var outputTemp = ""; + +function renderSiteMap() { + return ( /* eslint-disable indent */ +` + +${outputTemp} + +` + ); /* eslint-enable indent */ +} + +for (let file of fileList) { + outputTemp = outputTemp.concat( /* eslint-disable indent */ +` + https://${targetDomain}${rootPrefix}${file.replace(currentDir, "")} + ${Filesystem.statSync(file).mtime.toISOString().substring(0, 10)} + ` + ); /* eslint-enable indent */ +} + +Filesystem.writeFileSync(`${Process.argv[2]}/sitemap.xml`, renderSiteMap());