Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2.1 to 0.2.2

113

dist/index.js

@@ -1,21 +0,1 @@

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
// src/index.ts

@@ -28,26 +8,2 @@ import path from "path";

// ../utils/src/is-object-empty.ts
var isObjectEmpty = (o) => {
if (!o) {
return true;
}
if (Array.isArray(o)) {
return o.length === 0;
}
return Object.keys(o).length === 0 && Object.getPrototypeOf(o) === Object.prototype;
};
// ../utils/src/is-valid-url.ts
var isValidUrl = (s) => {
if (typeof s !== "string" || !s) {
return false;
}
try {
const dummy = new URL(s);
return true;
} catch {
return false;
}
};
// ../utils/src/logger.ts

@@ -120,19 +76,3 @@ var Logger = class {

// src/with-options.ts
var defaultOptions = {
createLinkInHead: true,
entryLimit: 45e3
};
var withOptions = (pluginOptions) => {
if (isObjectEmpty(pluginOptions)) {
return defaultOptions;
}
const options = __spreadProps(__spreadValues({}, pluginOptions), {
createLinkInHead: (pluginOptions == null ? void 0 : pluginOptions.createLinkInHead) ?? defaultOptions.createLinkInHead,
entryLimit: (pluginOptions == null ? void 0 : pluginOptions.entryLimit) || defaultOptions.entryLimit
});
return options;
};
// src/validate-opts.ts
// src/validate-options.ts
import { z as z2 } from "zod";

@@ -146,32 +86,43 @@

// src/config-defaults.ts
var SITEMAP_CONFIG_DEFAULTS = {
createLinkInHead: true,
entryLimit: 45e3
};
// src/schema.ts
var urlSchema = () => z.string().min(1).refine((val) => !val || isValidUrl(val), "Not valid url");
var localeKeySchema = () => z.string().min(1);
var isFunction = (fn) => fn instanceof Function;
var fnSchema = () => z.any().refine((val) => !val || isFunction(val), { message: "Not a function" }).optional();
var SitemapOptionsSchema = z.object({
filter: z.any().refine((val) => !val || isFunction(val), { message: "Not a function" }).optional(),
customPages: urlSchema().array().optional(),
canonicalURL: urlSchema().optional(),
filter: fnSchema(),
customPages: z.string().url().array().optional(),
canonicalURL: z.string().url().optional(),
i18n: z.object({
defaultLocale: localeKeySchema(),
locales: z.record(localeKeySchema(), z.string().min(2).regex(/^[a-zA-Z\-]+$/gm, { message: "Only English alphabet symbols and hyphen allowed" }))
}).refine(({ locales, defaultLocale }) => locales[defaultLocale], {
}).refine((val) => !val || val.locales[val.defaultLocale], {
message: "`defaultLocale` must exists in `locales` keys"
}).optional(),
createLinkInHead: z.boolean().optional(),
entryLimit: z.number().nonnegative().optional(),
serialize: z.any().refine((val) => !val || isFunction(val), { message: "Not a function" }).optional(),
createLinkInHead: z.boolean().default(SITEMAP_CONFIG_DEFAULTS.createLinkInHead),
entryLimit: z.number().nonnegative().default(SITEMAP_CONFIG_DEFAULTS.entryLimit),
serialize: fnSchema(),
changefreq: z.enum(changefreqValues).optional(),
lastmod: z.date().optional(),
priority: z.number().min(0).max(1).optional()
});
}).strict().default(SITEMAP_CONFIG_DEFAULTS);
// src/validate-opts.ts
var validateOpts = (site, opts) => {
const schema = SitemapOptionsSchema.extend({
site: z2.string().optional()
}).strict().refine(({ site: site2, canonicalURL }) => site2 || canonicalURL, {
// src/validate-options.ts
var validateOptions = (site, opts) => {
const result = SitemapOptionsSchema.parse(opts);
z2.object({
site: z2.string().optional(),
canonicalURL: z2.string().optional()
}).refine(({ site: site2, canonicalURL }) => site2 || canonicalURL, {
message: "Required `site` astro.config option or `canonicalURL` integration option"
}).parse({
site,
canonicalURL: result.canonicalURL
});
schema.parse(__spreadValues({ site: site || "" }, opts || {}));
return result;
};

@@ -212,3 +163,3 @@

function generateSitemap(pages, finalSiteUrl, opts) {
const { changefreq, priority: prioritySrc, lastmod: lastmodSrc, i18n } = opts || {};
const { changefreq, priority: prioritySrc, lastmod: lastmodSrc, i18n } = opts;
const urls = [...pages].filter((url) => !STATUS_CODE_PAGE_REGEXP.test(url));

@@ -310,5 +261,4 @@ urls.sort((a, b) => a.localeCompare(b, "en", { numeric: true }));

const merged = merge(external || {}, options || {});
const opts = withOptions(merged);
try {
validateOpts(config.site, opts);
const opts = validateOptions(config.site, merged);
const { filter, customPages, canonicalURL, serialize, createLinkInHead, entryLimit } = opts;

@@ -330,3 +280,3 @@ let finalSiteUrl;

if (filter) {
pageUrls = pageUrls.filter((url) => filter(url));
pageUrls = pageUrls.filter(filter);
}

@@ -347,6 +297,5 @@ } catch (err) {

let urlData = generateSitemap(pageUrls, finalSiteUrl.href, opts);
let serializedUrls;
if (serialize) {
serializedUrls = [];
try {
const serializedUrls = [];
for (const item of urlData) {

@@ -353,0 +302,0 @@ const serialized = await Promise.resolve(serialize(item));

{
"name": "astro-sitemap",
"version": "0.2.1",
"description": "Generate a sitemap with i18n capabilities for Astro",
"version": "0.2.2",
"description": "Generate a sitemap for Astro with more control",
"keywords": [

@@ -42,4 +42,4 @@ "astro",

"devDependencies": {
"@types/node": "^17.0.42",
"astro": "^1.0.0-beta.44",
"@types/node": "^17.0.43",
"astro": "^1.0.0-beta.46",
"at-scripts": "0.0.4",

@@ -49,3 +49,3 @@ "c8": "^7.11.3",

"vite": "^2.9.12",
"vitest": "^0.14.2"
"vitest": "^0.15.1"
},

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

@@ -136,3 +136,2 @@ [![Help Ukraine now!](https://raw.githubusercontent.com/alextim/help-ukraine-win-flag/master/stop-russian-agressian-help-ukraine-now-link.svg 'Help Ukraine now!')](https://bank.gov.ua/en/about/support-the-armed-forces)

You can also check [Astro Integration Documentation](https://docs.astro.build/en/guides/integrations-guide/) for more on integrations.

@@ -148,5 +147,5 @@

| `customPages` | `String[]` | No | undefined | The same as official. Absolute url list. It will be merged with generated pages urls. |
| `canonicalURL` | `String` | No | undefined | The same as official. Absolute url. The integration needs `site` from astro.config or `canonicalURL`. If both provided only `canonicalURL` will be used. |
| `canonicalURL` | `String` | No | undefined | The same as official. Absolute url. The integration needs `site` from astro.config or `canonicalURL`. If both values are provided then only `canonicalURL` will be used by the integration. |
| `entryLimit` | `Number` | No | 45000 | Number of entries per sitemap file, a sitemap index and multiple sitemaps are created if you have more entries. See more on [Google](https://developers.google.com/search/docs/advanced/sitemaps/large-sitemaps)|
| `createLinkInHead`| `Boolean` | No | true | Create a link on the sitemap in `<head>` of generated pages. |
| `createLinkInHead`| `Boolean` | No | true | Create a link on the sitemap in `<head>` of generated pages.<br/>The final output reprocessing is used for this. It could impact on a build time for large sites.|
| `serialize` | `(item: SitemapItem):<br />SitemapItem`| No | undefined | Function to process an array of SiteMap items just before writing to disk. Async or sync. |

@@ -179,3 +178,2 @@ | `changefreq` | `ChangeFreq` | No | undefined | Sitemap specific. Ignored by Google.<br/>How frequently the page is likely to change.<br/>Available values: `always` \| `hourly` \| `daily` \| `weekly` \| `monthly` \| `yearly` \| `never` |

| `url` | `String` | Yes | Absolute url |
| `lang` | `String` | Yes | example 'en' |
| `hreflang` | `String` | No | example 'en-us' |

@@ -182,0 +180,0 @@

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