astro-sitemap
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -22,2 +22,3 @@ var __defProp = Object.defineProperty; | ||
// src/index.ts | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
@@ -194,10 +195,10 @@ import { ZodError } from "zod"; | ||
if (localeCodes.some((key) => key === locale)) { | ||
let path = a.slice(2).join("/"); | ||
if (path === "//") { | ||
path = "/"; | ||
let path2 = a.slice(2).join("/"); | ||
if (path2 === "//") { | ||
path2 = "/"; | ||
} | ||
if (path !== "/" && !path.startsWith("/")) { | ||
path = "/" + path; | ||
if (path2 !== "/" && !path2.startsWith("/")) { | ||
path2 = "/" + path2; | ||
} | ||
return { locale, path }; | ||
return { locale, path: path2 }; | ||
} | ||
@@ -311,4 +312,15 @@ return { locale: defaultLocale, path: s }; | ||
const { filter, customPages, canonicalURL, serialize, createLinkInHead, entryLimit } = opts; | ||
const finalSiteUrl = canonicalURL || config.site || ""; | ||
let pageUrls = pages.map((p) => new URL(p.pathname, finalSiteUrl).href); | ||
let finalSiteUrl; | ||
if (canonicalURL) { | ||
finalSiteUrl = new URL(canonicalURL); | ||
if (!finalSiteUrl.pathname.endsWith("/")) { | ||
finalSiteUrl.pathname += "/"; | ||
} | ||
} else { | ||
finalSiteUrl = new URL(config.base, config.site); | ||
} | ||
let pageUrls = pages.map((p) => { | ||
const path2 = finalSiteUrl.pathname + p.pathname; | ||
return new URL(path2, finalSiteUrl).href; | ||
}); | ||
try { | ||
@@ -331,3 +343,3 @@ if (filter) { | ||
} | ||
let urlData = generateSitemap(pageUrls, finalSiteUrl, opts); | ||
let urlData = generateSitemap(pageUrls, finalSiteUrl.href, opts); | ||
let serializedUrls; | ||
@@ -349,3 +361,3 @@ if (serialize) { | ||
await simpleSitemapAndIndex({ | ||
hostname: finalSiteUrl, | ||
hostname: finalSiteUrl.href, | ||
destinationDir: fileURLToPath(dir), | ||
@@ -358,5 +370,6 @@ sourceData: urlData, | ||
if (createLinkInHead) { | ||
const headHTML = `<link rel="sitemap" type="application/xml" href="/${OUTFILE}">`; | ||
const sitemapHref = path.posix.join(config.base, OUTFILE); | ||
const headHTML = `<link rel="sitemap" type="application/xml" href="${sitemapHref}">`; | ||
await processPages(pages, dir, headHTML, config.build.format); | ||
logger.success("Links are created in <head> section of generated pages."); | ||
logger.success("Sitemap links are created in <head> section of generated pages."); | ||
} | ||
@@ -363,0 +376,0 @@ } catch (err) { |
{ | ||
"name": "astro-sitemap", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Generate a sitemap with i18n capabilities for Astro", | ||
@@ -42,4 +42,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/node": "^17.0.41", | ||
"astro": "^1.0.0-beta.43", | ||
"@types/node": "^17.0.42", | ||
"astro": "^1.0.0-beta.44", | ||
"at-scripts": "0.0.4", | ||
@@ -46,0 +46,0 @@ "c8": "^7.11.3", |
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
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
32758
391