Skip to content

Commit

Permalink
set defaults when generating from sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskalmar committed Jan 14, 2024
1 parent fc68cdd commit 76c2dc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MaskSchema = z.object({

export type Mask = z.infer<typeof MaskSchema>;

const PageScreenshotParameterSchema = z.object({
export const PageScreenshotParameterSchema = z.object({
/**
* Path to the page to take a screenshot of (e.g. /login)
*/
Expand Down
19 changes: 12 additions & 7 deletions src/generatePagesFromSitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { parseStringPromise } from 'xml2js';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { log } from './log';
import { type PageScreenshotParameter } from './config';
import {
PageScreenshotParameterSchema,
type PageScreenshotParameter,
} from './config';

type SitemapParserOptions = {
outputPath: string;
Expand Down Expand Up @@ -57,12 +60,14 @@ async function generatePagesFileFromSitemap(
const urls = await parseSitemap(sitemapContent);

const pages: PageScreenshotParameter[] = urls.map((url) => {
const page: PageScreenshotParameter = {
path: new URL(url).pathname, // Extract the path from the URL
name: url
.replace(/^https?:\/\/(www\.)?|^www\./g, '')
.replace(/\//g, '_'), // Create a unique name
};
const page: PageScreenshotParameter = PageScreenshotParameterSchema.parse(
{
path: new URL(url).pathname, // Extract the path from the URL
name: url
.replace(/^https?:\/\/(www\.)?|^www\./g, '')
.replace(/\//g, '_'), // Create a unique name
},
);

return page;
});
Expand Down

0 comments on commit 76c2dc3

Please sign in to comment.