New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

astro-sitemap

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-sitemap - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

35

dist/index.js

@@ -290,3 +290,2 @@ // src/index.ts

import { promises as fs2 } from "fs";
import { parse, HTMLElement } from "node-html-parser";
var addTailSlash = (s) => s.endsWith("/") ? s : s + "/";

@@ -301,23 +300,21 @@ var removeHeadingSlash = (s) => s.replace(/^\/+/, "");

var getFileFile = (pathname) => pathname ? `${removeTrailingSlash(pathname)}.html` : "index.html";
async function processPages(pages, dir, headHTML, buildFormat) {
if (pages.length === 0) {
return;
}
async function processPages(pages, dir, headHTML, buildFormat, logger2) {
if (buildFormat !== "directory" && buildFormat !== "file") {
throw new Error(`Unsupported build.format: '${buildFormat}' in your astro.config`);
}
let insertedCount = 0;
const HEAD_END_TAG = "</head>";
for (const page of pages) {
const fileUrl = new URL(buildFormat === "directory" ? getFileDir(page.pathname) : getFileFile(page.pathname), dir);
const html = await fs2.readFile(fileUrl, "utf-8");
const root = parse(html);
let head = root.querySelector("head");
if (!head) {
head = new HTMLElement("head", {}, "", root);
root.appendChild(head);
console.warn(`No <head> found in \`${fileUrl.pathname}\`. <head> will be created.`);
const content = await fs2.readFile(fileUrl, "utf-8");
const index = content.indexOf(HEAD_END_TAG);
if (index === -1) {
logger2.info(`Cannot insert links. Reason: no <head> section in \`${fileUrl.pathname}\`.`);
} else {
const inlined = content.substring(0, index) + headHTML + content.substring(index);
await fs2.writeFile(fileUrl, inlined, "utf-8");
insertedCount += 1;
}
head.innerHTML = head.innerHTML + headHTML;
const inlined = root.toString();
await fs2.writeFile(fileUrl, inlined, "utf-8");
}
return insertedCount;
}

@@ -436,7 +433,9 @@

logger.success(`${fileNames.map((name) => `\`${name}\``).join(", ")} are created.`, `Total entries: ${urlData.length}.`);
if (createLinkInHead) {
if (createLinkInHead && srcPages.length > 0) {
const sitemapHref = path.posix.join(config.base, fileNames[0]);
const headHTML = `<link rel="sitemap" type="application/xml" href="${sitemapHref}">`;
await processPages(srcPages, dir, headHTML, config.build.format);
logger.success("Sitemap links are inserted into <head> section of generated pages.");
const insertedCount = await processPages(srcPages, dir, headHTML, config.build.format, logger);
if (insertedCount > 0) {
logger.success(`Sitemap links are inserted into <head> section of generated pages (${insertedCount} of ${srcPages.length}).`);
}
}

@@ -443,0 +442,0 @@ } catch (err) {

{
"name": "astro-sitemap",
"version": "0.3.0",
"version": "0.4.0",
"description": "Generate a sitemap for Astro with more control",

@@ -37,15 +37,14 @@ "keywords": [

"minimatch": "^5.1.0",
"node-html-parser": "^5.3.3",
"sitemap": "^7.1.1",
"zod": "^3.17.10"
"zod": "^3.18.0"
},
"devDependencies": {
"@types/minimatch": "^3.0.5",
"@types/node": "^18.6.1",
"astro": "^1.0.0-rc.1",
"@types/node": "^18.7.11",
"astro": "^1.0.7",
"at-scripts": "0.0.4",
"c8": "^7.12.0",
"typescript": "^4.7.4",
"vite": "^3.0.3",
"vitest": "^0.19.1"
"vite": "^3.0.9",
"vitest": "^0.22.1"
},

@@ -52,0 +51,0 @@ "publishConfig": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc