A module for generating and managing sitemaps, supporting dynamic sitemap generation from feeds.
Go to file
2024-05-29 14:16:14 +02:00
.gitea/workflows fix(core): update 2023-10-20 17:55:02 +02:00
.vscode fix(core): update 2023-07-27 16:16:37 +02:00
test fix(core): update 2023-07-27 16:16:37 +02:00
ts fix(core): update 2023-10-20 17:55:02 +02:00
.gitignore fix(core): update 2020-10-25 22:12:38 +00:00
license fix(core): update 2020-10-25 22:12:38 +00:00
npmextra.json update tsconfig 2024-04-14 18:19:14 +02:00
package.json update description 2024-05-29 14:16:14 +02:00
pnpm-lock.yaml fix(core): update 2023-10-20 17:55:02 +02:00
readme.hints.md update tsconfig 2024-04-14 18:19:14 +02:00
readme.md update tsconfig 2024-04-14 18:19:14 +02:00
tsconfig.json update tsconfig 2024-04-01 21:41:01 +02:00

@push.rocks/smartsitemap

a sitemap module

Install

To install @push.rocks/smartsitemap, use npm or yarn:

npm install @push.rocks/smartsitemap --save
# or
yarn add @push.rocks/smartsitemap

This will add @push.rocks/smartsitemap to your project's dependencies.

Usage

@push.rocks/smartsitemap provides a versatile way to create, manage, and parse sitemaps in TypeScript. Below are examples demonstrating how to utilize its capabilities in various scenarios. Please note that these examples are written using ESM syntax and TypeScript.

Creating a News Sitemap from an RSS Feed

To generate a sitemap for news articles based on an RSS feed URL, you can use the createSitemapNewsFromFeedUrl method:

import { SmartSitemap } from '@push.rocks/smartsitemap';

async function generateNewsSitemap() {
  const sitemapGenerator = new SmartSitemap();
  const sitemapXml = await sitemapGenerator.createSitemapNewsFromFeedUrl('https://yourwebsite.com/feed');
  console.log(sitemapXml);
}
generateNewsSitemap();

This function fetches the RSS feed, parses the articles, and generates a sitemap XML string suitable for news content.

Parsing a Sitemap

To parse an existing sitemap, employ the parseSitemapUrl method which accepts a sitemap URL and returns a parsed object:

import { SmartSitemap } from '@push.rocks/smartsitemap';

async function parseExistingSitemap() {
  const sitemapParser = new SmartSitemap();
  const parsedSitemap = await sitemapParser.parseSitemapUrl('https://yourwebsite.com/sitemap.xml');
  console.log(parsedSitemap);
}
parseExistingSitemap();

Creating a Website Sitemap from a YAML String

Generating a regular website sitemap from a YAML string, which lists URLs and their update frequencies, is straightforward with createSitemapFromYmlString:

import { SmartSitemap } from '@push.rocks/smartsitemap';

const yamlString = `
daily:
  - https://yourwebsite.com/
  - https://yourwebsite.com/about
`;

async function generateWebsiteSitemap() {
  const sitemapGenerator = new SmartSitemap();
  const sitemapXml = await sitemapGenerator.createSitemapFromYmlString(yamlString);
  console.log(sitemapXml);
}
generateWebsiteSitemap();

Creating a Website Sitemap from a URL Array

For more control, you can create a sitemap by providing an array of URL objects using createSitemapFromUrlInfoArray:

import { SmartSitemap, IUrlInfo } from '@push.rocks/smartsitemap';

const urlInfos: IUrlInfo[] = [
  { url: 'https://yourwebsite.com/', timestamp: Date.now(), frequency: 'daily' },
  { url: 'https://yourwebsite.com/about', timestamp: Date.now(), frequency: 'weekly' }
];

async function generateWebsiteSitemap() {
  const sitemapGenerator = new SmartSitemap();
  const sitemapXml = await sitemapGenerator.createSitemapFromUrlInfoArray(urlInfos);
  console.log(sitemapXml);
}
generateWebsiteSitemap();

Advanced Usage: Combining News and Website Sitemaps

For comprehensive sitemap management, including both regular webpage URLs and news articles, you can combine the methods shown above to fit your specific needs.

This module offers flexibility and ease of use for generating sitemaps compatible with search engines like Google, enhancing SEO by ensuring your site's content is fully indexed.

Always refer to the latest documentation and class references to utilize all features provided by @push.rocks/smartsitemap, as this guide focuses on fundamental usages and may not cover more advanced or newly introduced functionalities.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.