mapify-cli
v2.0.0
Published
A CLI tool for generating `sitemap.xml` files for various frontend frameworks including Angular, React, and Vue. Automatically detects changes in project files to update the `lastmod` attribute and supports multiple build outputs.
Downloads
39
Maintainers
Readme
mapify-cli
mapify-cli
is a CLI tool for generating sitemap.xml
files for various frontend frameworks such as Angular, React, Vue, and more. It simplifies the creation of sitemaps by using a configuration file and automatically detects changes in your project files to update the lastmod
attribute.
Features
- Framework Agnostic: Works with Angular, React, Vue, and other frontend frameworks.
- Automatic Last Modified Dates: Detects the latest modifications of component files to update the
lastmod
attribute in your sitemap. - Customizable Config: Provides options to configure default change frequencies, priorities, and more.
- Multiple Builds Support: Handles multiple build outputs seamlessly. You can specify different output paths for various builds like SSR and serverless.
- Force Option: Allows you to bypass Git detection for
lastmod
updates.
Installation
To install mapify-cli
, run:
npm install -g mapify-cli
Usage
Commands
--init
: Initializes a sample config file (mapify.config.js
).--config <path>
: Uses a custom configuration file.--generate
: Generates thesitemap.xml
file based on the config.
Example
To generate the sitemap.xml
, use:
npx mapify-cli --generate
Configuration
Create a configuration file (mapify.config.js
) in your project root. The configuration should look like this:
/** @type {import('mapify-cli').MapifyConfig} */
module.exports = {
baseUrl: "http://example.com", // required
outputPaths: ['./dist/angular-ui/browser', './dist/angular-ui-serverless/browser'], // required
pages: [
{
path: '/', // required
priority: 1, // required
changeFreq: 'weekly', // (optional) default = monthly
componentPath: './src/app/pages/home/**' // (optional)
},
{
path: '/about',
priority: 0.8,
componentPath: './src/app/pages/about/**'
},
{
path: '/contact',
priority: 0.8,
componentPath: './src/app/pages/contact/**'
},
{
path: '/login',
priority: 0.9,
changeFreq: 'weekly',
componentPath: './src/app/pages/login/**'
}
],
defaultChangeFreq: 'monthly', // optional
defaultPriority: 0.5, // optional
forceLastModificationDate: false // optional
};
Options
baseUrl
(string): The base URL of your site.outputPaths
(string[]): Array of output paths where thesitemap.xml
will be saved. Supports multiple builds, such as SSR and serverless builds.pages
(IPage[]): Array of page configurations.path
(string): The URL path of the page.priority
(number): The priority of the page (0.0 to 1.0).changeFreq
(ChangeFreq): Optional. How frequently the page is likely to change (e.g., 'daily', 'weekly'). Defaults todefaultChangeFreq
.componentPath
(string): Optional. Path to the components used to detect the last modified date.
defaultChangeFreq
(ChangeFreq): Default change frequency for all pages.defaultPriority
(number): Default priority for all pages.forceLastModificationDate
(boolean): If true, skips Git detection forlastmod
and uses the current date.
GitHub Action
To automate sitemap generation using GitHub Actions, add the following workflow to your .github/workflows/
directory:
name: Generate Sitemap
on:
push:
branches:
- main
jobs:
generate-sitemap:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Sitemap
run: npx mapify-cli --generate
License
This project is licensed under the MIT License.
Contributing
We welcome contributions to improve mapify-cli
. Please see the CONTRIBUTING.md file for more information.
Support
For any issues or feature requests, please open an issue on the GitHub repository.
Code of Conduct
We are committed to providing a welcoming and inclusive environment for all contributors. Please review our Code of Conduct to understand our community standards and expectations.