0.0.7 - "now we have sitemaps"

AC: "wish i'd done this in 0.0.6 but too late now"
This commit is contained in:
yellows111 2024-04-22 14:48:59 +01:00
parent f2fc7e360c
commit c91c09e606
5 changed files with 70 additions and 4 deletions

View File

@ -19,13 +19,14 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
MARKER = node compile MARKER = node compile
SITEMAPGEN = node sitemap-gen
BUILD_DIR = ./build BUILD_DIR = ./build
SRC_DIRS = ./docs SRC_DIRS = ./docs
MARKDOWN_L = $(patsubst %.md,%.html,$(shell find $(SRC_DIRS) -name "*.md")) MARKDOWN_L = $(patsubst %.md,%.html,$(shell find $(SRC_DIRS) -name "*.md"))
COPY_L = $(patsubst %.css,%.justcopytobuilddir,$(shell find $(SRC_DIRS) -name "*.css")) 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 $(MARKDOWN_L): %.html: %.md
$(COPY_L): %.justcopytobuilddir: %.css $(COPY_L): %.justcopytobuilddir: %.css
@ -38,4 +39,7 @@ $(COPY_L): %.justcopytobuilddir: %.css
%.justcopytobuilddir: %.justcopytobuilddir:
cp -f $< $(BUILD_DIR) cp -f $< $(BUILD_DIR)
make_sitemap:
$(SITEMAPGEN) $(BUILD_DIR) $(subst $(SRC_DIRS),$(BUILD_DIR),$(MARKDOWN_L))
# end of GNUmakefile # end of GNUmakefile

View File

@ -42,6 +42,10 @@ for the `yiki.css` and the `index.html` files.
Example: `gmake VPREFIX:="/yiki/"` Example: `gmake VPREFIX:="/yiki/"`
`DOMAIN` Specifiy the domain name that your sitemap.xml links to.
Example `gmake DOMAIN:="example.com"`
## Contributing ## Contributing
I request (but not require) that you modify files without Carriage Returns, I request (but not require) that you modify files without Carriage Returns,

4
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "yiki", "name": "yiki",
"version": "0.0.6", "version": "0.0.7",
"description": "The yellows111 wiki system", "description": "The yellows111 wiki system",
"main": "compile.js", "main": "compile.js",
"scripts": { "scripts": {

58
sitemap-gen.js Normal file
View File

@ -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 */
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${outputTemp}
</urlset>
`
); /* eslint-enable indent */
}
for (let file of fileList) {
outputTemp = outputTemp.concat( /* eslint-disable indent */
` <url>
<loc>https://${targetDomain}${rootPrefix}${file.replace(currentDir, "")}</loc>
<lastmod>${Filesystem.statSync(file).mtime.toISOString().substring(0, 10)}</lastmod>
</url>`
); /* eslint-enable indent */
}
Filesystem.writeFileSync(`${Process.argv[2]}/sitemap.xml`, renderSiteMap());