vite-plugin-svelte-sitemap
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,61 +0,60 @@ | ||
// plugin.ts | ||
import { writeFile } from "fs/promises"; | ||
import glob from "glob"; | ||
import { existsSync, mkdirSync } from "fs"; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.Sitemap = void 0; | ||
var promises_1 = require("fs/promises"); | ||
var glob_1 = require("glob"); | ||
var fs_1 = require("fs"); | ||
function sanify_path(path) { | ||
let path_array = path.split("/"); | ||
path_array.pop(); | ||
if (path_array.join("/") == "") | ||
return `/${path_array.join("/")}`; | ||
else | ||
return `${path_array.join("/")}`; | ||
var path_array = path.split("/"); | ||
path_array.pop(); // Remove +page.svelte | ||
if (path_array.join("/") == "") // If path is index | ||
return "/".concat(path_array.join("/")); // Add a trailing slash | ||
else | ||
return "".concat(path_array.join("/")); // Don't add anything | ||
} | ||
function gen_sitemap(paths, baseurl) { | ||
let xml = `<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`; | ||
for (let path of paths) { | ||
xml += ` | ||
<url> | ||
<loc>${baseurl + sanify_path(path)}</loc> | ||
<lastmod>${new Date().toISOString().split("T")[0]}</lastmod> | ||
</url> | ||
`; | ||
} | ||
xml += `</urlset>`; | ||
if (!existsSync("static")) | ||
mkdirSync("static"); | ||
writeFile("static/sitemap.xml", xml); | ||
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"; | ||
for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) { // Convert JS date to W3C date format | ||
var path = paths_1[_i]; | ||
xml += "\n <url>\n <loc>".concat(baseurl + sanify_path(path), "</loc>\n <lastmod>").concat(new Date().toISOString().split("T")[0], "</lastmod>\n </url>\n"); | ||
} | ||
xml += "</urlset>"; | ||
if (!(0, fs_1.existsSync)("static")) // Put it in static | ||
(0, fs_1.mkdirSync)("static"); | ||
(0, promises_1.writeFile)("static/sitemap.xml", xml); | ||
} | ||
function getDirectories(src, callback) { | ||
glob(src + "/**/*", callback); | ||
(0, glob_1["default"])(src + '/**/*', callback); | ||
} | ||
; | ||
function makeListFromDirectory(baseurl) { | ||
console.log("\x1B[32mGenerating sitemap..."); | ||
getDirectories("./", function(err, res) { | ||
if (err) { | ||
console.log("Error", err); | ||
} else { | ||
let paths = Array.from(res); | ||
paths = paths.filter((path) => !path.includes("node")); | ||
paths = paths.filter((path) => path.includes("+page.svelte")); | ||
paths = paths.map((path) => path.replace("./demo/", "").replace("./src/routes", "")); | ||
gen_sitemap(paths, baseurl); | ||
} | ||
}); | ||
console.log("\x1b[32mGenerating sitemap..."); | ||
getDirectories('./', function (err, res) { | ||
if (err) { | ||
console.log('Error', err); | ||
} | ||
else { | ||
var paths = Array.from(res); | ||
paths = paths.filter(function (path) { return !path.includes("node"); }); // Filter node modules | ||
paths = paths.filter(function (path) { return path.includes("+page.svelte"); }); // Get only pages, not layouts | ||
paths = paths.map(function (path) { return path.replace("./demo/", "").replace("./src/routes", ""); }); // Remove src/routes | ||
gen_sitemap(paths, baseurl); | ||
} | ||
}); | ||
} | ||
function Sitemap({ baseurl }) { | ||
const plugin = { | ||
name: "vite-plugin-svelte-sitemap", | ||
apply: "serve", | ||
handleHotUpdate(ctx) { | ||
if (ctx.file.split("/")[ctx.file.split("/").length - 1] == "sitemap.xml") | ||
return; | ||
makeListFromDirectory(baseurl); | ||
} | ||
}; | ||
makeListFromDirectory(baseurl); | ||
return plugin; | ||
function Sitemap(_a) { | ||
var baseurl = _a.baseurl; | ||
var plugin = { | ||
name: 'vite-plugin-svelte-sitemap', | ||
// only apply during dev | ||
apply: 'serve', | ||
handleHotUpdate: function (ctx) { | ||
if (ctx.file.split("/")[ctx.file.split("/").length - 1] == "sitemap.xml") | ||
return; | ||
makeListFromDirectory(baseurl); | ||
} | ||
}; | ||
makeListFromDirectory(baseurl); | ||
return plugin; | ||
} | ||
export { | ||
Sitemap | ||
}; | ||
exports.Sitemap = Sitemap; |
{ | ||
"name": "vite-plugin-svelte-sitemap", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A Vite plugin to generate sitemap from sveltekit project", | ||
@@ -10,14 +10,5 @@ "homepage": "https://github.com/Andrea055/sveltekit-sitemap-generator", | ||
], | ||
"main": "./dist/plugin.cjs", | ||
"module": "./dist/plugin.mjs", | ||
"types": "./dist/plugin.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/plugin.cjs", | ||
"import": "./dist/plugin.mjs", | ||
"types": "./dist/plugin.d.ts" | ||
} | ||
}, | ||
"main": "./dist/plugin.js", | ||
"scripts": { | ||
"build:tsup": "tsup plugin.ts --dts --format esm,cjs", | ||
"build:tsup": "mkdir dist && tsc plugin.ts --outDir dist && cp plugin.ts dist/plugin.ts", | ||
"demo": "vite demo", | ||
@@ -24,0 +15,0 @@ "dev": "vite dev", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
6010
4
122
1