Skip to content

Commit

Permalink
add changes from bartholomej#46 and prepare package
Browse files Browse the repository at this point in the history
  • Loading branch information
fxxmr committed Aug 10, 2024
1 parent 78bd56f commit c771832
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
[![Package License](https://img.shields.io/npm/l/svelte-sitemap.svg)](https://www.npmjs.com/svelte-sitemap)
[![Build & Publish](https://github.com/bartholomej/svelte-sitemap/workflows/Build%20&%20Publish/badge.svg)](https://github.com/bartholomej/svelte-sitemap/actions)

# Temporary Workaround until https://github.com/bartholomej/svelte-sitemap/pull/46 is merged

Chnages from #46 are added to this fork

## install:

`npm install 'https://gitpkg.vercel.app/fxxmr/svelte-sitemap/dist?master' --save-dev`

# Svelte `sitemap.xml` generator

> Small helper which scans your Svelte routes and generates _sitemap.xml_
Expand Down
8 changes: 8 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
[![Package License](https://img.shields.io/npm/l/svelte-sitemap.svg)](https://www.npmjs.com/svelte-sitemap)
[![Build & Publish](https://github.com/bartholomej/svelte-sitemap/workflows/Build%20&%20Publish/badge.svg)](https://github.com/bartholomej/svelte-sitemap/actions)

# Temporary Workaround until https://github.com/bartholomej/svelte-sitemap/pull/46 is merged

Chnages from #46 are added to this fork

## install:

`npm install 'https://gitpkg.vercel.app/fxxmr/svelte-sitemap/dist?master' --save-dev`

# Svelte `sitemap.xml` generator

> Small helper which scans your Svelte routes and generates _sitemap.xml_
Expand Down
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const index_1 = require("./src/index");
const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';
let stop = false;
const args = (0, minimist_1.default)(process.argv.slice(2), {
string: ['domain', 'out-dir', 'ignore', 'change-freq'],
string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],
boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],
default: { attribution: true, 'trailing-slashes': false, default: false },
alias: {
Expand All @@ -29,7 +29,9 @@ const args = (0, minimist_1.default)(process.argv.slice(2), {
i: 'ignore',
I: 'ignore',
t: 'trailing-slashes',
T: 'trailing-slashes'
T: 'trailing-slashes',
a: 'additional',
A: 'additional'
},
unknown: (err) => {
console.log('⚠ Those arguments are not supported:', err);
Expand All @@ -49,6 +51,7 @@ if (args.help || args.version === '' || args.version === true) {
log(' -d, --domain Use your domain (eg. https://example.com)');
log(' -o, --out-dir Custom output dir');
log(' -i, --ignore Exclude some pages or folders');
log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');
log(' -t, --trailing-slashes Do you like trailing slashes?');
log(' -r, --reset-time Set modified time to now');
log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');
Expand All @@ -71,6 +74,11 @@ else if (stop) {
else {
const domain = args.domain ? args.domain : undefined;
const debug = args.debug === '' || args.debug === true ? true : false;
const additional = Array.isArray(args['additional'])
? args['additional']
: args.additional
? [args.additional]
: [];
const resetTime = args['reset-time'] === '' || args['reset-time'] === true ? true : false;
const trailingSlashes = args['trailing-slashes'] === '' || args['trailing-slashes'] === true ? true : false;
const changeFreq = args['change-freq'];
Expand All @@ -84,7 +92,8 @@ else {
outDir,
attribution,
ignore,
trailingSlashes
trailingSlashes,
additional
};
(0, index_1.createSitemap)(domain, options);
}
5 changes: 5 additions & 0 deletions dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const createSitemap = async (domain = vars_1.DOMAIN, options) => {
console.log('OPTIONS', options);
}
const json = await (0, global_helper_1.prepareData)(domain, options);
options.additional.forEach((url) => {
json.push({
page: `${domain}${url}`
});
});
if (options === null || options === void 0 ? void 0 : options.debug) {
console.log('RESULT', json);
}
Expand Down
3 changes: 2 additions & 1 deletion dist/src/interfaces/global.interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Options {
changeFreq?: ChangeFreq;
resetTime?: boolean;
outDir?: string;
additional?: string[];
attribution?: boolean;
ignore?: string | string[];
trailingSlashes?: boolean;
Expand All @@ -20,4 +21,4 @@ export declare const changeFreq: readonly ["always", "hourly", "daily", "weekly"
/**
* Specs: https://www.sitemaps.org/protocol.html
*/
export type ChangeFreq = typeof changeFreq[number];
export type ChangeFreq = (typeof changeFreq)[number];
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';
let stop = false;

const args = minimist(process.argv.slice(2), {
string: ['domain', 'out-dir', 'ignore', 'change-freq'],
string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],
boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],
default: { attribution: true, 'trailing-slashes': false, default: false },
alias: {
Expand All @@ -29,7 +29,9 @@ const args = minimist(process.argv.slice(2), {
i: 'ignore',
I: 'ignore',
t: 'trailing-slashes',
T: 'trailing-slashes'
T: 'trailing-slashes',
a: 'additional',
A: 'additional'
},
unknown: (err: string) => {
console.log('⚠ Those arguments are not supported:', err);
Expand All @@ -50,6 +52,7 @@ if (args.help || args.version === '' || args.version === true) {
log(' -d, --domain Use your domain (eg. https://example.com)');
log(' -o, --out-dir Custom output dir');
log(' -i, --ignore Exclude some pages or folders');
log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');
log(' -t, --trailing-slashes Do you like trailing slashes?');
log(' -r, --reset-time Set modified time to now');
log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');
Expand All @@ -72,6 +75,11 @@ if (args.help || args.version === '' || args.version === true) {
} else {
const domain: string = args.domain ? args.domain : undefined;
const debug: boolean = args.debug === '' || args.debug === true ? true : false;
const additional = Array.isArray(args['additional'])
? args['additional']
: args.additional
? [args.additional]
: [];
const resetTime: boolean =
args['reset-time'] === '' || args['reset-time'] === true ? true : false;
const trailingSlashes: boolean =
Expand All @@ -88,7 +96,8 @@ if (args.help || args.version === '' || args.version === true) {
outDir,
attribution,
ignore,
trailingSlashes
trailingSlashes,
additional
};

createSitemap(domain, options);
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export const createSitemap = async (domain: string = DOMAIN, options?: Options):

const json = await prepareData(domain, options);

options.additional.forEach((url) => {
json.push({
page: `${domain}${url}`
});
});

if (options?.debug) {
console.log('RESULT', json);
}
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/global.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Options {
changeFreq?: ChangeFreq;
resetTime?: boolean;
outDir?: string;
additional?: string[];
attribution?: boolean;
ignore?: string | string[];
trailingSlashes?: boolean;
Expand All @@ -32,4 +33,4 @@ export const changeFreq = [
/**
* Specs: https://www.sitemaps.org/protocol.html
*/
export type ChangeFreq = typeof changeFreq[number];
export type ChangeFreq = (typeof changeFreq)[number];

0 comments on commit c771832

Please sign in to comment.