From 968f12afe60e31d6df7b276b857650ca3c2ead3b Mon Sep 17 00:00:00 2001 From: KishiTheMechanic Date: Mon, 28 Oct 2024 00:52:48 +0100 Subject: [PATCH] fix output paths --- deno.json | 2 +- mod.ts | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/deno.json b/deno.json index 5cb3044..802189a 100644 --- a/deno.json +++ b/deno.json @@ -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", diff --git a/mod.ts b/mod.ts index 41cc93a..0a14b2a 100644 --- a/mod.ts +++ b/mod.ts @@ -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