Move parseSitemapXml into helper file

This commit is contained in:
Sam Carlton 2022-06-11 18:04:36 -05:00
parent 79640781bc
commit 45bfe1c2fa
2 changed files with 79 additions and 9 deletions

View file

@ -1,13 +1,13 @@
import fs from 'fs-extra'
import 'dotenv/config'
import axios from 'axios'
import { parse } from 'fast-xml-parser'
import {
sitemapLocation,
sitemapIndexFileName,
} from '~/helpers/constants.js'
import { parseSitemapXml } from '~/helpers/api/sitemap/parse.js'
;(async () => {
@ -22,14 +22,7 @@ import {
const sitemapIndexFilePath = `${ sitemapLocation }${ sitemapIndexFileName }`
await fs.writeFile( sitemapIndexFilePath, sitemapIndexXML )
// Get URLs from index
const { sitemapindex } = parse( sitemapIndexXML )
const {
sitemap
} = sitemapindex
const urlEntries = Array.isArray( sitemap ) ? sitemap : [ sitemap ]
const urlEntries = parseSitemapXml( sitemapIndexXML )
// Fetch each sitemap
@ -44,6 +37,10 @@ import {
// Fetch Sitemap Index
const sitemapXML = await axios.get( apiSitemapUrl.href ).then( response => response.data )
// const sitemap = parse( sitemapXML )
// console.log( 'sitemap', sitemap )
// console.log( 'apiSitemapUrl', apiSitemapUrl )
const sitemapFileName = apiSitemapUrl.pathname.split('/')[1]