add sitemap #17
							
								
								
									
										36
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								index.js
									
									
									
									
									
								
							@@ -1,13 +1,15 @@
 | 
				
			|||||||
import { load } from "cheerio";
 | 
					import { load } from "cheerio";
 | 
				
			||||||
import { readFile, writeFileSync, mkdirSync, cpSync, rmSync } from "fs";
 | 
					import { readFile, writeFileSync, mkdirSync, cpSync, rmSync } from "fs";
 | 
				
			||||||
import process from "child_process";
 | 
					import process from "child_process";
 | 
				
			||||||
 | 
					import { simpleSitemapAndIndex } from "sitemap";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import stores from "./stores.json" with { type: "json" };
 | 
					import stores from "./stores.json" with { type: "json" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function mkDir(path) {
 | 
					function mkDir(path) {
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    return mkdirSync(path)
 | 
					    return mkdirSync(path);
 | 
				
			||||||
  } catch (err) {
 | 
					  } catch (err) {
 | 
				
			||||||
    if (err.code !== 'EEXIST') throw err
 | 
					    if (err.code !== "EEXIST") throw err;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,10 +43,15 @@ function cleanWebsite(str) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function metaDescription({ name, meta, description }) {
 | 
					function metaDescription({ name, meta, description }) {
 | 
				
			||||||
  if (meta && (meta.length > 155 || meta.length < 145 && meta.length !== 0)) {
 | 
					  if (meta && (meta.length > 155 || (meta.length < 145 && meta.length !== 0))) {
 | 
				
			||||||
    console.log(`warning: meta tag for ${name} is invalid: 145/${meta.length}/155`)
 | 
					    console.log(
 | 
				
			||||||
 | 
					      `warning: meta tag for ${name} is invalid: 145/${meta.length}/155`
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return meta || description.length > 155 ? description.slice(0, 153) + "..." : description || "A guide to and map of every independent bookstore in New York City. We have a complete list of community bookstores in NYC with locations and descriptions."
 | 
					  return meta || description.length > 155
 | 
				
			||||||
 | 
					    ? description.slice(0, 153) + "..."
 | 
				
			||||||
 | 
					    : description ||
 | 
				
			||||||
 | 
					        "A guide to and map of every independent bookstore in New York City. We have a complete list of community bookstores in NYC with locations and descriptions.";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function GetRecentChanges() {
 | 
					function GetRecentChanges() {
 | 
				
			||||||
@@ -176,15 +183,17 @@ readFile("./index.tmpl.html", function (err, data) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  rmSync("./build", { recursive: true, force: true });
 | 
					  rmSync("./build", { recursive: true, force: true });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mkDir("./build")
 | 
					  mkDir("./build");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  writeFile("./build/index.html", $.html())
 | 
					  writeFile("./build/index.html", $.html());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cpSync("./site.css", "./build/site.css");
 | 
					  cpSync("./site.css", "./build/site.css");
 | 
				
			||||||
  cpSync("./robots.txt", "./build/robots.txt");
 | 
					  cpSync("./robots.txt", "./build/robots.txt");
 | 
				
			||||||
  cpSync("./img", "./build/img", {recursive: true});
 | 
					  cpSync("./img", "./build/img", { recursive: true });
 | 
				
			||||||
  cpSync("./stores.json", "./build/stores.json");
 | 
					  cpSync("./stores.json", "./build/stores.json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let pages = [{ url: `/`, changefreq: "weekly", priority: 1.0 }];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  stores.forEach((store) => {
 | 
					  stores.forEach((store) => {
 | 
				
			||||||
    $("#selected").html(SelectedStoreTemplate(store));
 | 
					    $("#selected").html(SelectedStoreTemplate(store));
 | 
				
			||||||
    $("#info").addClass("hidden");
 | 
					    $("#info").addClass("hidden");
 | 
				
			||||||
@@ -194,5 +203,16 @@ readFile("./index.tmpl.html", function (err, data) {
 | 
				
			|||||||
    $("meta[name='description']").attr("content", metaDescription(store));
 | 
					    $("meta[name='description']").attr("content", metaDescription(store));
 | 
				
			||||||
    mkDir(`./build/${slugify(store.name)}`);
 | 
					    mkDir(`./build/${slugify(store.name)}`);
 | 
				
			||||||
    writeFile(`./build/${slugify(store.name)}/index.html`, $.html());
 | 
					    writeFile(`./build/${slugify(store.name)}/index.html`, $.html());
 | 
				
			||||||
 | 
					    pages.push({
 | 
				
			||||||
 | 
					      url: `/${slugify(store.name)}/`,
 | 
				
			||||||
 | 
					      changefreq: "monthly",
 | 
				
			||||||
 | 
					      priority: 0.5,
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  simpleSitemapAndIndex({
 | 
				
			||||||
 | 
					    hostname: "https://nycbookstores.org/",
 | 
				
			||||||
 | 
					    destinationDir: `./build/`,
 | 
				
			||||||
 | 
					    sourceData: pages,
 | 
				
			||||||
 | 
					    gzip: false,
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										97
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										97
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -9,9 +9,31 @@
 | 
				
			|||||||
      "version": "1.0.0",
 | 
					      "version": "1.0.0",
 | 
				
			||||||
      "license": "BSD-3-Clause",
 | 
					      "license": "BSD-3-Clause",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "cheerio": "^1.0.0-rc.12"
 | 
					        "cheerio": "^1.0.0",
 | 
				
			||||||
 | 
					        "sitemap": "^8.0.0"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/@types/node": {
 | 
				
			||||||
 | 
					      "version": "17.0.45",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==",
 | 
				
			||||||
 | 
					      "license": "MIT"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/@types/sax": {
 | 
				
			||||||
 | 
					      "version": "1.2.7",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==",
 | 
				
			||||||
 | 
					      "license": "MIT",
 | 
				
			||||||
 | 
					      "dependencies": {
 | 
				
			||||||
 | 
					        "@types/node": "*"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/arg": {
 | 
				
			||||||
 | 
					      "version": "5.0.2",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==",
 | 
				
			||||||
 | 
					      "license": "MIT"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "node_modules/boolbase": {
 | 
					    "node_modules/boolbase": {
 | 
				
			||||||
      "version": "1.0.0",
 | 
					      "version": "1.0.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
 | 
				
			||||||
@@ -21,6 +43,7 @@
 | 
				
			|||||||
      "version": "1.0.0",
 | 
					      "version": "1.0.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz",
 | 
				
			||||||
      "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==",
 | 
					      "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==",
 | 
				
			||||||
 | 
					      "license": "MIT",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "cheerio-select": "^2.1.0",
 | 
					        "cheerio-select": "^2.1.0",
 | 
				
			||||||
        "dom-serializer": "^2.0.0",
 | 
					        "dom-serializer": "^2.0.0",
 | 
				
			||||||
@@ -236,10 +259,36 @@
 | 
				
			|||||||
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
 | 
					      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/sax": {
 | 
				
			||||||
 | 
					      "version": "1.4.1",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==",
 | 
				
			||||||
 | 
					      "license": "ISC"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "node_modules/sitemap": {
 | 
				
			||||||
 | 
					      "version": "8.0.0",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-8.0.0.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==",
 | 
				
			||||||
 | 
					      "license": "MIT",
 | 
				
			||||||
 | 
					      "dependencies": {
 | 
				
			||||||
 | 
					        "@types/node": "^17.0.5",
 | 
				
			||||||
 | 
					        "@types/sax": "^1.2.1",
 | 
				
			||||||
 | 
					        "arg": "^5.0.0",
 | 
				
			||||||
 | 
					        "sax": "^1.2.4"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      "bin": {
 | 
				
			||||||
 | 
					        "sitemap": "dist/cli.js"
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      "engines": {
 | 
				
			||||||
 | 
					        "node": ">=14.0.0",
 | 
				
			||||||
 | 
					        "npm": ">=6.0.0"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "node_modules/undici": {
 | 
					    "node_modules/undici": {
 | 
				
			||||||
      "version": "6.19.7",
 | 
					      "version": "6.21.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==",
 | 
					      "integrity": "sha512-uROZWze0R0itiAKVPsYhFov9LxrPMHLMEQFszeI2gCN6bnIIZ8twzBCJcN2LJrBBLfrP0t1FW0g+JmKVl8Vk1g==",
 | 
				
			||||||
 | 
					      "license": "MIT",
 | 
				
			||||||
      "engines": {
 | 
					      "engines": {
 | 
				
			||||||
        "node": ">=18.17"
 | 
					        "node": ">=18.17"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -265,6 +314,24 @@
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@types/node": {
 | 
				
			||||||
 | 
					      "version": "17.0.45",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw=="
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "@types/sax": {
 | 
				
			||||||
 | 
					      "version": "1.2.7",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==",
 | 
				
			||||||
 | 
					      "requires": {
 | 
				
			||||||
 | 
					        "@types/node": "*"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "arg": {
 | 
				
			||||||
 | 
					      "version": "5.0.2",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg=="
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "boolbase": {
 | 
					    "boolbase": {
 | 
				
			||||||
      "version": "1.0.0",
 | 
					      "version": "1.0.0",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
 | 
				
			||||||
@@ -422,10 +489,26 @@
 | 
				
			|||||||
      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
 | 
					      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "sax": {
 | 
				
			||||||
 | 
					      "version": "1.4.1",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg=="
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "sitemap": {
 | 
				
			||||||
 | 
					      "version": "8.0.0",
 | 
				
			||||||
 | 
					      "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-8.0.0.tgz",
 | 
				
			||||||
 | 
					      "integrity": "sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==",
 | 
				
			||||||
 | 
					      "requires": {
 | 
				
			||||||
 | 
					        "@types/node": "^17.0.5",
 | 
				
			||||||
 | 
					        "@types/sax": "^1.2.1",
 | 
				
			||||||
 | 
					        "arg": "^5.0.0",
 | 
				
			||||||
 | 
					        "sax": "^1.2.4"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "undici": {
 | 
					    "undici": {
 | 
				
			||||||
      "version": "6.19.7",
 | 
					      "version": "6.21.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/undici/-/undici-6.21.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A=="
 | 
					      "integrity": "sha512-uROZWze0R0itiAKVPsYhFov9LxrPMHLMEQFszeI2gCN6bnIIZ8twzBCJcN2LJrBBLfrP0t1FW0g+JmKVl8Vk1g=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "whatwg-encoding": {
 | 
					    "whatwg-encoding": {
 | 
				
			||||||
      "version": "3.1.1",
 | 
					      "version": "3.1.1",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,8 @@
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  "homepage": "https://www.nycbookstores.org/",
 | 
					  "homepage": "https://www.nycbookstores.org/",
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "cheerio": "^1.0.0-rc.12"
 | 
					    "cheerio": "^1.0.0",
 | 
				
			||||||
 | 
					    "sitemap": "^8.0.0"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "type": "module"
 | 
					  "type": "module"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					Sitemap: https://nycbookstores.org/sitemap-index.xml
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user