Compare commits

...

22 Commits

Author SHA1 Message Date
74c73e05f2 update description 2024-05-29 14:16:14 +02:00
849b4f6447 update tsconfig 2024-04-14 18:19:14 +02:00
a5edc242cd update tsconfig 2024-04-01 21:41:01 +02:00
de9f8191c3 update npmextra.json: githost 2024-04-01 19:59:39 +02:00
9802b660f9 update npmextra.json: githost 2024-03-30 21:48:39 +01:00
6d1725ed53 2.0.3 2023-10-20 17:55:03 +02:00
028acc0218 fix(core): update 2023-10-20 17:55:02 +02:00
ea2e3f9f7b 2.0.2 2023-07-27 16:16:37 +02:00
8909652860 fix(core): update 2023-07-27 16:16:37 +02:00
38d1d4ae0c 2.0.1 2022-03-25 00:19:11 +01:00
d8a21a0c0a fix(core): update 2022-03-25 00:19:10 +01:00
f2e96640fa 2.0.0 2022-03-25 00:15:10 +01:00
72cd9f1a00 1.0.15 2022-03-25 00:14:35 +01:00
2e9394c330 fix(core): update 2022-03-25 00:14:34 +01:00
f8241b49fb 1.0.14 2021-01-03 14:28:29 +00:00
7adc7b9fb1 fix(core): update 2021-01-03 14:28:29 +00:00
aabb8265cd 1.0.13 2021-01-03 02:48:45 +00:00
b8befa85fa fix(core): update 2021-01-03 02:48:45 +00:00
114cd1900b 1.0.12 2021-01-03 02:08:01 +00:00
17d8cd6585 fix(core): update 2021-01-03 02:08:00 +00:00
87cdc5bb5f 1.0.11 2020-10-28 17:43:59 +00:00
d03b37690f fix(core): update 2020-10-28 17:43:58 +00:00
20 changed files with 6252 additions and 11348 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -1,137 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
"type": "node-terminal"
}
]
}

View File

@ -2,17 +2,33 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartsitemap",
"shortDescription": "a sitemap module",
"npmPackagename": "@pushrocks/smartsitemap",
"description": "A module for generating and managing sitemaps, supporting dynamic sitemap generation from feeds.",
"npmPackagename": "@push.rocks/smartsitemap",
"license": "MIT",
"projectDomain": "push.rocks"
"projectDomain": "push.rocks",
"keywords": [
"sitemap generator",
"RSS feeds",
"news sitemap",
"XML sitemap",
"website indexing",
"search engine optimization",
"SEO",
"web crawling",
"dynamic sitemap creation",
"TypeScript",
"node.js"
]
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
}
}

11078
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,30 +1,34 @@
{
"name": "@pushrocks/smartsitemap",
"version": "1.0.10",
"name": "@push.rocks/smartsitemap",
"version": "2.0.3",
"private": false,
"description": "a sitemap module",
"description": "A module for generating and managing sitemaps, supporting dynamic sitemap generation from feeds.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsbundle": "^2.0.8",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/smartenv": "^5.0.10",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7"
},
"dependencies": {
"@pushrocks/smartcache": "^1.0.13",
"@pushrocks/smartfeed": "^1.0.5",
"@pushrocks/smartxml": "^1.0.6",
"@pushrocks/smartyaml": "^2.0.5"
"@push.rocks/smartcache": "^1.0.16",
"@push.rocks/smartfeed": "^1.0.11",
"@push.rocks/smartxml": "^1.0.8",
"@push.rocks/smartyaml": "^2.0.5",
"@push.rocks/webrequest": "^3.0.33",
"@tsclass/tsclass": "^4.0.46"
},
"browserslist": [
"last 1 chrome versions"
@ -40,5 +44,23 @@
"cli.js",
"npmextra.json",
"readme.md"
]
}
],
"keywords": [
"sitemap generator",
"RSS feeds",
"news sitemap",
"XML sitemap",
"website indexing",
"search engine optimization",
"SEO",
"web crawling",
"dynamic sitemap creation",
"TypeScript",
"node.js"
],
"homepage": "https://code.foss.global/push.rocks/smartsitemap",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartsitemap.git"
}
}

5719
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

133
readme.md
View File

@ -1,39 +1,118 @@
# @pushrocks/smartsitemap
# @push.rocks/smartsitemap
a sitemap module
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartsitemap)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartsitemap)
* [github.com (source mirror)](https://github.com/pushrocks/smartsitemap)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartsitemap/)
## Install
## Status for master
To install `@push.rocks/smartsitemap`, use npm or yarn:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartsitemap/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartsitemap/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartsitemap)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartsitemap)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartsitemap)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartsitemap)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartsitemap)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
```bash
npm install @push.rocks/smartsitemap --save
# or
yarn add @push.rocks/smartsitemap
```
This will add `@push.rocks/smartsitemap` to your project's dependencies.
## Usage
Use TypeScript for best in class intellisense
`@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.
## Contribution
### Creating a News Sitemap from an RSS Feed
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
To generate a sitemap for news articles based on an RSS feed URL, you can use the `createSitemapNewsFromFeedUrl` method:
For further information read the linked docs at the top of this readme.
```typescript
import { SmartSitemap } from '@push.rocks/smartsitemap';
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
async function generateNewsSitemap() {
const sitemapGenerator = new SmartSitemap();
const sitemapXml = await sitemapGenerator.createSitemapNewsFromFeedUrl('https://yourwebsite.com/feed');
console.log(sitemapXml);
}
generateNewsSitemap();
```
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
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:
```typescript
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`:
```typescript
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`:
```typescript
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.
## License and Legal Information
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](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.

View File

@ -1,16 +1,23 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartsitemap from '../ts/index';
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartsitemap from '../ts/index.js';
let testSmartsitemap: smartsitemap.SmartSitemap;
tap.test('should create an instance of Smartsitemap', async () => {
testSmartsitemap = new smartsitemap.SmartSitemap();
expect(testSmartsitemap).to.be.instanceOf(smartsitemap.SmartSitemap);
expect(testSmartsitemap).toBeInstanceOf(smartsitemap.SmartSitemap);
});
tap.test('should create a sitemap from feed', async () => {
const sitemapString = await testSmartsitemap.createSitemapNewsFromFeedUrl('https://www.theverge.com/rss/index.xml');
const sitemapString = await testSmartsitemap.createSitemapNewsFromFeedUrl(
'https://central.eu/feed'
);
console.log(sitemapString);
});
tap.test('should parse a sitemap', async () => {
const result = await testSmartsitemap.parseSitemapUrl('https://www.theverge.com/sitemaps/google_news');
// console.log(result.urlset.url);
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartsitemap',
version: '2.0.3',
description: 'a sitemap module'
}

View File

@ -1,3 +1,3 @@
export * from './smartsitemap.classes.smartsitemap';
export * from './smartsitemap.classes.sitemapnews';
export * from './smartsitemap.classes.sitemapwebsite';
export * from './smartsitemap.classes.smartsitemap.js';
export * from './smartsitemap.classes.sitemapnews.js';
export * from './smartsitemap.classes.sitemapwebsite.js';

View File

@ -1,3 +1,42 @@
export interface ISitemapYaml {
daily: string[];
}
}
export interface IRssItem {
[key: string]: any;
link?: string;
guid?: string;
title?: string;
pubDate?: string;
creator?: string;
content?: string;
isoDate?: string;
categories?: string[];
contentSnippet?: string;
enclosure?: any;
}
export interface IParsedSiteMap {
urlset: {
url:
| {
loc: string;
lastmod: string;
changefreq: string;
}
| {
loc: string;
lastmod: string;
changefreq: string;
}[]
| {
loc: string;
'news:news': {
'news:publication': [];
'news:keywords': string;
'news:publication_date': string;
'news:title': string;
};
}[];
};
}

View File

@ -1,20 +1,34 @@
import * as plugins from './smartsitemap.plugins';
import * as plugins from './smartsitemap.plugins.js';
import * as interfaces from './interfaces/index.js';
export class SitemapNews {
public items: any[] = [];
public rssItems: interfaces.IRssItem[] = [];
constructor(optionsArg: {}) {}
public async readAndAddFromRssFeedString(feedStringArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromString(feedStringArg);
this.items = this.items.concat(parsedFeed.items);
this.rssItems = this.rssItems.concat(parsedFeed.items);
}
public async readAndAddFromRssFeedUrl(urlArg: string) {
const smartfeedInstance = new plugins.smartfeed.Smartfeed();
const parsedFeed = await smartfeedInstance.parseFeedFromUrl(urlArg);
this.items = this.items.concat(parsedFeed.items);
this.rssItems = this.rssItems.concat(parsedFeed.items);
}
public async readAndParseArticles(articleArrayArg: plugins.tsclass.content.IArticle[]) {
const rssItemArray = articleArrayArg.map((articleArg): interfaces.IRssItem => {
return {
title: articleArg.title,
content: articleArg.content,
isoDate: new Date(/* TODO: put article timestamp here */).toISOString(),
link: articleArg.url,
};
});
this.rssItems = this.rssItems.concat(rssItemArray);
}
public exportSitemapXml() {
@ -25,24 +39,25 @@ export class SitemapNews {
'news:name': string;
'news:language': string;
};
"news:publication_date" : string;
"news:keywords": string;
"news:title": string;
'news:publication_date': string;
'news:keywords': string;
'news:title': string;
};
}[] = [];
for (const itemArg of this.items) {
for (const itemArg of this.rssItems) {
console.log(itemArg);
urls.push({
loc: itemArg.link,
"news:news": {
"news:publication": {
"news:language": 'en',
"news:name": 'some name'
'news:news': {
'news:publication': {
'news:language': 'en',
'news:name': 'some name',
},
"news:keywords": '',
"news:publication_date": itemArg.isoDate,
"news:title": itemArg.title
}
})
'news:keywords': '',
'news:publication_date': itemArg.isoDate,
'news:title': itemArg.title,
},
});
}
const sitemapObject: any = {
urlset: {

View File

@ -1,4 +1,4 @@
import * as plugins from './smartsitemap.plugins';
import * as plugins from './smartsitemap.plugins.js';
export type TUpdateFrequency = 'never' | 'daily' | 'weekly' | 'monthly' | 'yearly';
@ -26,7 +26,7 @@ export class SitemapWebsite {
urls.push({
loc: urlInfoArg.url,
lastmod: new Date(urlInfoArg.timestamp).toISOString(),
changefreq: urlInfoArg.frequency ? urlInfoArg.frequency : 'weekly'
changefreq: urlInfoArg.frequency ? urlInfoArg.frequency : 'weekly',
});
}
const sitemapObject: any = {
@ -39,4 +39,4 @@ export class SitemapWebsite {
const sitemapString = smartxmlInstance.createXmlFromObject(sitemapObject);
return sitemapString;
}
}
}

View File

@ -1,7 +1,7 @@
import { SitemapNews } from './smartsitemap.classes.sitemapnews';
import { IUrlInfo, SitemapWebsite } from './smartsitemap.classes.sitemapwebsite';
import * as plugins from './smartsitemap.plugins';
import * as interfaces from './interfaces';
import { SitemapNews } from './smartsitemap.classes.sitemapnews.js';
import { type IUrlInfo, SitemapWebsite } from './smartsitemap.classes.sitemapwebsite.js';
import * as plugins from './smartsitemap.plugins.js';
import * as interfaces from './interfaces/index.js';
export class SmartSitemap {
constructor() {}
@ -15,17 +15,39 @@ export class SmartSitemap {
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a sitemap for news from feedxmlstring
*/
public async createSitemapNewsFromAFeedStringArg(feedStringArg: string): Promise<string> {
const sitemapNewsInstance = new SitemapNews({});
await sitemapNewsInstance.readAndAddFromRssFeedString(feedStringArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a sitemap for news from an array of articles
*/
public async createSitemapNewsFromArticleArray(
articleArrayArg: plugins.tsclass.content.IArticle[]
): Promise<string> {
const sitemapNewsInstance = new SitemapNews({});
await sitemapNewsInstance.readAndParseArticles(articleArrayArg);
return sitemapNewsInstance.exportSitemapXml();
}
/**
* creates a normal sitemap from a list of urls
*/
public async createSitemapFromYmlString(yamlString: string): Promise<string> {
const yamlObject: interfaces.ISitemapYaml = await plugins.smartyaml.yamlStringToObject(yamlString);
const yamlObject: interfaces.ISitemapYaml = await plugins.smartyaml.yamlStringToObject(
yamlString
);
const sitemapWebsite = new SitemapWebsite();
for(const urlArg of yamlObject.daily) {
for (const urlArg of yamlObject.daily) {
sitemapWebsite.addUrl({
url: urlArg,
timestamp: Date.now() - 10000,
frequency: 'daily'
frequency: 'daily',
});
}
return sitemapWebsite.exportSitemapXml();
@ -36,9 +58,30 @@ export class SmartSitemap {
*/
public async createSitemapFromUrlInfoArray(urlInfosArg: IUrlInfo[]) {
const sitemapWebsite = new SitemapWebsite();
for(const urlInfo of urlInfosArg) {
for (const urlInfo of urlInfosArg) {
sitemapWebsite.addUrl(urlInfo);
}
return sitemapWebsite.exportSitemapXml();
}
/**
* parses a sitemap url
*/
public async parseSitemapUrl(urlArg: string) {
const sitemapXml = await (
await new plugins.webrequest.WebRequest().request(urlArg, {
method: 'GET',
})
).text();
const parsedSitemap = await this.parseSitemap(sitemapXml);
return parsedSitemap;
}
/**
* parses a sitemap
*/
public async parseSitemap(sitemapXmlArg: string): Promise<interfaces.IParsedSiteMap> {
return new plugins.smartxml.SmartXml().parseXmlToObject(sitemapXmlArg);
}
}

View File

@ -1,12 +1,13 @@
// pushrocks scope
import * as smartcache from '@pushrocks/smartcache';
import * as smartfeed from '@pushrocks/smartfeed';
import * as smartxml from '@pushrocks/smartxml';
import * as smartyaml from '@pushrocks/smartyaml';
import * as smartcache from '@push.rocks/smartcache';
import * as smartfeed from '@push.rocks/smartfeed';
import * as smartxml from '@push.rocks/smartxml';
import * as smartyaml from '@push.rocks/smartyaml';
import * as webrequest from '@push.rocks/webrequest';
export {
smartcache,
smartfeed,
smartxml,
smartyaml
};
export { smartcache, smartfeed, smartxml, smartyaml, webrequest };
// tsclass
import * as tsclass from '@tsclass/tsclass';
export { tsclass };

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}