Skip to content

Commit

Permalink
fix output paths
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 27, 2024
1 parent 26acb24 commit 968f12a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elsoul/fresh-sitemap",
"version": "0.6.0",
"version": "0.7.0",
"description": "Lightweight global state management library for Fresh framework using Preact signals.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
19 changes: 14 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,22 @@ async function generateSitemap(
const relPath = distDirectory === '.'
? path
: path.substring(distDirectory.length)
let pathname = normalize(`/${relPath}`).split(SEPARATOR).join('/')
const segments = normalize(`/${relPath}`).split(SEPARATOR).map((
segment,
) => segment.replace(/\.tsx$/, ''))

// Check each segment and filter out unwanted segments
const filteredSegments = segments.filter((segment) => {
return !(
segment.startsWith('_') || // Ignore files that start with '_'
segment === 'index' || // Ignore 'index' files
segment.match(/\(.*?\)/) // Ignore segments with '(...)'
)
})

// Exclude grouping and dynamic directories, _-prefixed files, and index files
pathname = pathname.replace(/\(.*?\)/g, '') // Remove content within parentheses
if (pathname.includes('_') || pathname.endsWith('index')) continue
pathname = pathname.replace(/\.tsx$/, '')
if (filteredSegments.length === 0) continue // Skip if no valid segments remain

const pathname = `/${filteredSegments.join('/')}`
const isExcluded = exclude && exclude.test(pathname.substring(1))
const isIncluded = !include || include.test(pathname.substring(1))
if (isExcluded || !isIncluded) continue
Expand Down

0 comments on commit 968f12a

Please sign in to comment.