Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 28, 2024
1 parent 8da9502 commit d72d9d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 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.7.9",
"version": "0.7.10",
"description": "Lightweight global state management library for Fresh framework using Preact signals.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
42 changes: 15 additions & 27 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,40 +104,45 @@ async function generateSitemap(
const sitemapSet = new Set<string>() // Collects unique paths
const pathMap: Record<string, number> = {} // Records path flags

// Logs each path segment during processing
// Process each path segment and set flags in pathMap
function processPathSegments(path: string): void {
// Ignore non-`.tsx` files
if (!path.endsWith('.tsx')) return

// Normalize path
const relPath = distDirectory === '.'
? path
: path.substring(distDirectory.length)
const segments = relPath.split(SEPARATOR).map((segment) =>
segment.replace(/\.tsx$/, '')
)
const normalizedPath = `/${segments.join('/')}`

// Ignore paths with `_` or `()` segments
// If any segment contains `_` or `()`, ignore the entire path
if (
segments.some((segment) =>
segment.startsWith('_') || segment.includes('(')
)
) {
pathMap[normalizedPath] = 0
console.log(
`Excluded by filter (_ or ()): ${normalizedPath}, pathMap state:`,
pathMap,
)
console.log(`Excluded due to _ or (): ${segments.join('/')}`)
return
}

// Initialize path in pathMap and log it
// Construct normalized path for inclusion
let normalizedPath = `/${segments.join('/')}`

// Remove `index` at the end of the path if present
if (normalizedPath.endsWith('/index')) {
normalizedPath = normalizedPath.replace(/\/index$/, '')
}

pathMap[normalizedPath] = 1
console.log(
`Path added to pathMap: ${normalizedPath}, pathMap state:`,
pathMap,
)
}

// Retrieves all paths and processes each segment
// Retrieve all paths and process segments
async function addDirectory(directory: string) {
for await (const path of stableRecurseFiles(directory)) {
processPathSegments(path)
Expand All @@ -148,23 +153,6 @@ async function generateSitemap(

console.log('Initial pathMap after processing all segments:', pathMap)

// Remove `index` as the last segment and log any adjustments
for (const path in pathMap) {
if (pathMap[path] === 1) {
const cleanedPath = path.replace(/\/index$/, '')
if (cleanedPath !== path) {
pathMap[cleanedPath] = 1
delete pathMap[path]
console.log(
`Adjusted for index removal: ${cleanedPath}, pathMap state:`,
pathMap,
)
}
}
}

console.log('PathMap after index removal:', pathMap)

// Add unique paths to the Sitemap array, logging each addition
for (const path in pathMap) {
if (pathMap[path] === 1) {
Expand Down

0 comments on commit d72d9d9

Please sign in to comment.