Skip to content

Commit

Permalink
Add sort feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodevx committed Mar 14, 2022
1 parent 359430b commit f68fc3d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ async function generateUrls(opts) {
const files = await getFiles(opts)
const iterator = (f) => transformUrl(f, opts)
const urls = await pool(opts.concurrent, files, iterator)
return urls.filter((i) => i)
return urls
.filter((i) => i)
.sort(({ loc: a }, { loc: b }) => {
const depth = (url) => url.split('/').length
if (depth(a) === depth(b)) {
return a < b ? -1 : 1
} else {
return depth(a) < depth(b) ? -1 : 1
}
})
}

function generateTxtSitemap(urls) {
Expand Down

0 comments on commit f68fc3d

Please sign in to comment.