Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

static-sitemap-cli

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

static-sitemap-cli

Simple CLI to pre-generate XML sitemaps for static sites locally.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
257
increased by84.89%
Maintainers
1
Weekly downloads
 
Created
Source

npm npm

static-sitemap-cli

Simple CLI to pre-generate XML sitemaps for static sites locally.

Built in 10 minutes. :stuck_out_tongue_winking_eye:

Install

npm i -g static-sitemap-cli

Usage

Syntax: static-sitemap-cli <BASEURL> [options]

At its simplest, just go to your dist folder and run:

static-sitemap-cli https://example.com > sitemap.xml

Or, because it's quite a mouthful:

sscli https://example.com > sitemap.xml

Where sscli is just an alias of static-sitemap-cli. CLI by default outputs to stdout - so that you can pipe it to do other cool stuff. CLI also allows you to pipe in BASEURL via stdin.

Arguments

ArgumentDescription
BASEURLBase URL that is prefixed to all location entries. For example: https://example.com/

Options

OptionLongDescription
-h--helpshow CLI help
-V--versionshow CLI version
-r--root[default: current dir] root directory to start from
-m--match[default: **/*.html,!404.html] list of globs to match
-p--priorityglob-priority pair (eg: foo/*.html=0.1)
-f--changefreqglob-changefreq pair (eg: foo/*.html=daily)
-n--no-cleandisable clean URLs
-s--slashadd trailing slash to all URLs
-t--textoutput as .TXT instead
-v--verbosebe more verbose
Clean URLs

Whether or not to include the .html extension. By default, something like:

rootDir/foo/index.html becomes https://example.com/foo.

rootDir/foo/bar/foobar.html becomes https://example.com/foo/bar/foobar.

Pass -n option to disable this behavior.

Trailing Slashes

Controls whether or not URLs should include trailing slashes. For example:

rootDir/bar/index.html becomes https://example.com/bar/.

For obvious reasons, this cannot be used together with -n.

Ignore Some Files

The -m flag allows multiple entries to be input. By default it's set to the following globs: **/*.html and !404.html. You can change the glob pattern matches to suit your use-case, like:

sscli https://example.com -m '**/*.html' -m '!404.html' -m '!**/ignore/**' -m '!this/other/specific/file.html'

Glob-* Pairs

The -p and -c flags allow multiple entries and accept glob-* pairs as input. A glob-* pair is input as <glob-pattern>=<value>, where = is used as the separator. For example, a glob-frequency pair should be input as events/**/*.html=daily.

Latter entries will override the former. So for example in

sscli https://example.com -f '**/*=weekly' -f 'events/**=daily'

all URL entries will contain <changefreq>weekly</changefreq> while pages that match event/** will contain <changefreq>daily</changefreq>.

Output as Text

Sitemaps can be formatted as a simple text file as well, where each line contains exactly one URL. Pass the option -t to do so. In this case, --priority and --changefreq are redundant and ignored.

Examples

Create sitemap for dist folder

static-sitemap-cli https://example.com -r dist > dist/sitemap.xml

OR

sscli https://example.com -r dist > dist/sitemap.xml

Ignore a bunch of files

sscli https://example.com -m '**/*.html' '!404.html' '!**/ignore/**' '!this/other/specific/file.html' > sm.xml

Set priority of certain pages

By default, the optional <priority> label (protocol reference) is excluded, so every pages' default is 0.5. To change the relative priority of certain pages:

sscli https://example.com -p '**/{foo,bar}/**=0.1' '**/important/**=0.9' > sm.xml

Set changefreq of all pages to weekly, and some to daily

sscli https://example.com -f '**/*=weekly' -f 'events/**=daily' > sm.xml

Pipe in the base URL

echo https://example.com | sscli > sm.xml

To-do

Add tests! :sweat_smile:

Tests

Run npm run test.

Changelog

v1.0.1 - 2019-08-16:

  • Bugfix - empty line at EOF in text mode.

v1.0.0 - 2019-08-15:

  • BREAKING: --ignore is deprecated. Use --match instead.
  • BREAKING: Glob-* pairs are no longer comma-seperated. Use = instead.
  • BREAKING: Logic for multiple glob-* pairs changed. Later pairs override the earlier ones now.
  • Major refactor of original codebase; discontinued usage of globby and sitemap in favour of fast-glob, micromatch, and js2xmlparser.
  • Resulting code should be much easier to reason with and maintain now.
  • Add feature to output as text (one URL per line).
  • Add verbose mode to see some console feedback.
  • And finally, add tests with ~95% coverage.

v0.2.0 - 2019-07-31:

  • Allow BASEURL to be piped in also.
  • Refactor some dependencies.

v0.1.1 - 2019-07-27:

  • Bugfix: properly check rootDir before replacing.
  • Add new alias sscli because the original is quite a mouthful.

v0.1.0 - 2019-07-26:

  • Initial release.
  • Built in 10 minutes. :stuck_out_tongue_winking_eye:

Keywords

FAQs

Package last updated on 16 Aug 2019

Did you know?

Socket

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.

Install

Related posts

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