Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
xast-util-sitemap
Advanced tools
xast utility to build a sitemap.xml
.
This package helps you build a sitemap.xml
.
It supports localization as suggested by Google.
This package focusses on a small set of widely used parts of sitemaps. It has a few good options instead of overwhelming with everything that could be done. If you do need more things, well: this utility gives you a syntax tree, which you can change.
This proejct is intended for sites with up to 50k URLs and a resulting serialized contents of up to 50MB. Wrapping this project into something that generates sitemap index files is left as an exercise to the reader.
You don’t always need a sitemap. See Google’s recommendations for whether you need a sitemap
You should place sitemaps in the root of your site and reference them in
robots.txt
.
You might also report
sitemap changes to Google.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install xast-util-sitemap
In Deno with esm.sh
:
import {sitemap} from 'https://esm.sh/xast-util-sitemap@2'
In browsers with esm.sh
:
<script type="module">
import {sitemap} from 'https://esm.sh/xast-util-sitemap@2?bundle'
</script>
import {sitemap} from 'xast-util-sitemap'
import {toXml} from 'xast-util-to-xml'
const tree = sitemap([
'https://example.com/alpha/',
{url: 'https://example.com/bravo/'},
{url: 'https://example.com/charlie/', modified: new Date(2018, 1, 2, 3)},
{
url: 'https://example.com/delta/',
lang: 'en',
alternate: {
nl: 'https://example.com/dirk/',
'fr-BE': 'https://example.com/désiré/'
}
}
])
console.log(toXml(tree))
Yields (pretty printed):
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://example.com/alpha/</loc>
</url>
<url>
<loc>https://example.com/bravo/</loc>
</url>
<url>
<loc>https://example.com/charlie/</loc>
<lastmod>2018-02-02T02:00:00.000Z</lastmod>
</url>
<url>
<loc>https://example.com/delta/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/delta/" />
<xhtml:link rel="alternate" hreflang="nl" href="https://example.com/dirk/" />
<xhtml:link rel="alternate" hreflang="fr-BE" href="https://example.com/d%C3%A9sir%C3%A9/" />
</url>
<url>
<loc>https://example.com/dirk/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/delta/" />
<xhtml:link rel="alternate" hreflang="nl" href="https://example.com/dirk/" />
<xhtml:link rel="alternate" hreflang="fr-BE" href="https://example.com/d%C3%A9sir%C3%A9/" />
</url>
<url>
<loc>https://example.com/d%C3%A9sir%C3%A9/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/delta/" />
<xhtml:link rel="alternate" hreflang="nl" href="https://example.com/dirk/" />
<xhtml:link rel="alternate" hreflang="fr-BE" href="https://example.com/d%C3%A9sir%C3%A9/" />
</url>
</urlset>
This package exports the identifier sitemap
.
There is no default export.
sitemap(data)
Build a sitemap.
data
(Array<Entry | string>
)
— entries to build a sitemap for
(see Entry
, strings are equivalent to {url: string}
)Sitemap (Root
).
Entry
Entries represent a single URL and describe them with metadata (TypeScript type).
url
Full URL (<loc>
; string
, required, example: https://example.org/
).
modified
Value indicating when the page last changed (<lastmod>
; Date
or
value for new Date(x)
, optional).
lang
BCP 47 tag indicating the language of the page (string
, required w/
alternate
, example: 'en-GB'
).
alternate
Translations of the page, where each key is a BCP 47 tag and each
value an Alternate
(Record<string, Alternate>
, optional,
example: {nl: 'https://example.nl/'}
).
Alternate resources “inherit” fields (modified
) from the entry they are
described in.
Alternate
Alternative content, typically a translation (TypeScript type).
To define different fields, either use a full entry object:
[
{
url: 'https://example.com/delta/',
modified: '05 October 2011 14:48 UTC',
lang: 'en',
alternate: {nl: {url: 'https://example.com/dirk/', modified: '20 January 2020 00:00 UTC'}}
}
]
…or define them separately:
[
{
url: 'https://example.com/delta/',
modified: '05 October 2011 14:48 UTC',
lang: 'en',
alternate: {nl: 'https://example.com/dirk/'}
},
{
url: 'https://example.com/dirk/',
modified: '20 January 2020 00:00 UTC',
// `xast-util-sitemap` is smart enough to know about the next two already,
// but they’re shown here for clarity.
lang: 'nl',
alternate: {en: 'https://example.com/delta/'}
}
]
type Alternate = Omit<Entry, 'alternate' | 'lang'> | string
This package is fully typed with TypeScript.
It exports the additional types Alternate
and
Entry
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, xast-util-sitemap@^2
,
compatible with Node.js 16.
XML can be a dangerous language: don’t trust user-provided data.
Sitemaps also indicate “ownership” of URLs: crawlers assume that the origin
of the sitemap.xml
file is also an owner
xast-util-to-xml
— serialize xast to XMLxast-util-feed
— build feeds (RSS, Atom)xastscript
— create xast treesSee contributing.md
in syntax-tree/.github
for
ways to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
xast utility to build a sitemap
The npm package xast-util-sitemap receives a total of 102 weekly downloads. As such, xast-util-sitemap popularity was classified as not popular.
We found that xast-util-sitemap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.