Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ekalinin/sitemap.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6.3.6
Choose a base ref
...
head repository: ekalinin/sitemap.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6.4.0
Choose a head ref
  • 4 commits
  • 17 files changed
  • 2 contributors

Commits on Feb 17, 2021

  1. Add errorHandler option

    marcoreni committed Feb 17, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    renovate-bot Mend Renovate
    Copy the full SHA
    a9cdd26 View commit details
  2. Merge pull request #349 from marcoreni/feature/custom-error-handler

    Add errorHandler option
    derduher authored Feb 17, 2021
    Copy the full SHA
    30c392d View commit details
  3. Copy the full SHA
    4ae411f View commit details
  4. Merge pull request #350 from ekalinin/content_loc

    added support for content_loc, uploader info, error handler in sitema…
    derduher authored Feb 17, 2021
    Copy the full SHA
    0921341 View commit details
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.4.0

- added support for content_loc parsing #347 and uploader info attr
- added error handler option to sitemapstream #349 Thanks @marcoreni

## 6.3.6

- bump dependencies
36 changes: 19 additions & 17 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# API

- [SitemapStream](#sitemapstream)
- [XMLToSitemapItemStream](#XMLToSitemapItemStream)
- [sitemapAndIndexStream](#sitemapandindexstream)
- [createSitemapsAndIndex](#createsitemapsandindex)
- [SitemapIndexStream](#SitemapIndexStream)
- [xmlLint](#xmllint)
- [parseSitemap](#parsesitemap)
- [lineSeparatedURLsToSitemapOptions](#lineseparatedurlstositemapoptions)
- [streamToPromise](#streamtopromise)
- [ObjectStreamToJSON](#objectstreamtojson)
- [SitemapItemStream](#SitemapItemStream)
- [Sitemap Item Options](#sitemap-item-options)
- [SitemapImage](#sitemapimage)
- [VideoItem](#videoitem)
- [LinkItem](#linkitem)
- [NewsItem](#newsitem)
- [API](#api)
- [SitemapStream](#sitemapstream)
- [XMLToSitemapItemStream](#xmltositemapitemstream)
- [sitemapAndIndexStream](#sitemapandindexstream)
- [createSitemapsAndIndex](#createsitemapsandindex)
- [SitemapIndexStream](#sitemapindexstream)
- [xmlLint](#xmllint)
- [parseSitemap](#parsesitemap)
- [lineSeparatedURLsToSitemapOptions](#lineseparatedurlstositemapoptions)
- [streamToPromise](#streamtopromise)
- [ObjectStreamToJSON](#objectstreamtojson)
- [SitemapItemStream](#sitemapitemstream)
- [Sitemap Item Options](#sitemap-item-options)
- [SitemapImage](#sitemapimage)
- [VideoItem](#videoitem)
- [ILinkItem](#ilinkitem)
- [NewsItem](#newsitem)

## SitemapStream

@@ -32,7 +33,8 @@ const sms = new SitemapStream({
image: true,
video: true,
// custom: ['xmlns:custom="https://example.com"']
}
},
errorHandler: undefined // defaults to a standard errorLogger that logs to console or throws if the errorLevel is set to throw
})
const readable = // a readable stream of objects
readable.pipe(sms).pipe(process.stdout)
8 changes: 7 additions & 1 deletion lib/sitemap-item-stream.ts
Original file line number Diff line number Diff line change
@@ -187,7 +187,13 @@ export class SitemapItemStream extends Transform {
}

if (video.uploader) {
this.push(element(TagNames['video:uploader'], video.uploader));
this.push(
element(
TagNames['video:uploader'],
attrBuilder(video, 'uploader:info'),
video.uploader
)
);
}

if (video.platform) {
10 changes: 10 additions & 0 deletions lib/sitemap-parser.ts
Original file line number Diff line number Diff line change
@@ -172,6 +172,9 @@ export class XMLToSitemapItemStream extends Transform {
case TagNames['video:player_loc']:
currentVideo.player_loc = text;
break;
case TagNames['video:content_loc']:
currentVideo.content_loc = text;
break;
case TagNames['video:requires_subscription']:
if (isValidYesNo(text)) {
currentVideo.requires_subscription = text;
@@ -410,6 +413,13 @@ export class XMLToSitemapItemStream extends Transform {
);
}
break;
case TagNames['video:uploader']:
if (attr.name === 'info') {
currentVideo['uploader:info'] = attr.value;
} else {
this.logger('log', 'unhandled attr for video:uploader', attr.name);
}
break;
default:
this.logger('log', 'unhandled attr', currentTag, attr.name);
}
8 changes: 6 additions & 2 deletions lib/sitemap-stream.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import {
Readable,
Writable,
} from 'stream';
import { SitemapItemLoose, ErrorLevel } from './types';
import { SitemapItemLoose, ErrorLevel, ErrorHandler } from './types';
import { validateSMIOptions, normalizeURL } from './utils';
import { SitemapItemStream } from './sitemap-item-stream';
import { EmptyStream, EmptySitemap } from './errors';
@@ -69,6 +69,7 @@ export interface SitemapStreamOptions extends TransformOptions {
lastmodDateOnly?: boolean;
xmlns?: NSArgs;
xslUrl?: string;
errorHandler?: ErrorHandler;
}
const defaultXMLNS: NSArgs = {
news: true,
@@ -92,6 +93,7 @@ export class SitemapStream extends Transform {
hasHeadOutput: boolean;
xmlNS: NSArgs;
xslUrl?: string;
errorHandler?: ErrorHandler;
private smiStream: SitemapItemStream;
lastmodDateOnly: boolean;
constructor(opts = defaultStreamOpts) {
@@ -100,6 +102,7 @@ export class SitemapStream extends Transform {
this.hasHeadOutput = false;
this.hostname = opts.hostname;
this.level = opts.level || ErrorLevel.WARN;
this.errorHandler = opts.errorHandler;
this.smiStream = new SitemapItemStream({ level: opts.level });
this.smiStream.on('data', (data) => this.push(data));
this.lastmodDateOnly = opts.lastmodDateOnly || false;
@@ -119,7 +122,8 @@ export class SitemapStream extends Transform {
this.smiStream.write(
validateSMIOptions(
normalizeURL(item, this.hostname, this.lastmodDateOnly),
this.level
this.level,
this.errorHandler
)
);
callback();
8 changes: 8 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -208,6 +208,12 @@ interface VideoItemBase {
*/
'restriction:relationship'?: EnumAllowDeny;
gallery_loc?: string;
/**
* [Optional] Specifies the URL of a webpage with additional information about this uploader. This URL must be in the same domain as the <loc> tag.
* @see https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps
* @example http://www.example.com/users/grillymcgrillerson
*/
'uploader:info'?: string;
'gallery_loc:title'?: string;
/**
* The price to download or view the video. Omit this tag for free videos.
@@ -368,6 +374,8 @@ export enum ErrorLevel {
THROW = 'throw',
}

export type ErrorHandler = (error: Error, level: ErrorLevel) => void;

export enum TagNames {
url = 'url',
loc = 'loc',
3 changes: 2 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import {
isPriceType,
isResolution,
NewsItem,
ErrorHandler,
} from './types';
import {
ChangeFreqInvalidError,
@@ -83,7 +84,7 @@ function handleError(error: Error, level: ErrorLevel): void {
export function validateSMIOptions(
conf: SitemapItem,
level = ErrorLevel.WARN,
errorHandler = handleError
errorHandler: ErrorHandler = handleError
): SitemapItem {
if (!conf) {
throw new NoConfigError();
Loading