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 87f0f4a commit 6d63214
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 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.14",
"version": "0.8.0",
"description": "Lightweight global state management library for Fresh framework using Preact signals.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
33 changes: 31 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,50 @@ async function generateSitemap(
}
}

function arrayToObject(arr: string[]): Record<string, number> {
const result: Record<string, number> = {}

for (const segment of arr) {
result[segment] = 1 // Set each segment as a key with value 1
}

return result
}

function checkSegments(
pathMap: Record<string, number>,
): Record<string, number> {
for (const key in pathMap) {
if (key.startsWith('(') && key.endsWith(')')) {
pathMap[key] = 0
}
}
return pathMap
}

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

// Populate sitemap entries based on pathMap
for (const path in pathMap) {
if (pathMap[path] === 1) {
const filePath = join(distDirectory, path) // Use original path for checking
const filePath = join(path) // Use original path for checking
if (!(await exists(filePath))) {
console.log(`File not found, skipping: ${filePath}`)
continue // Skip if file does not exist
}
const { mtime } = await Deno.stat(filePath)

// Clean the path for the sitemap
const cleanedPath = path.replace(/\/index\.tsx$/, '') // Remove '/index.tsx'
const pathSegments = path.split(SEPARATOR)

const segCheckObj = arrayToObject(pathSegments)

const checkedSegments = checkSegments(segCheckObj)

const cleanedPath = pathSegments
.filter((segment) => checkedSegments[segment] === 1)
.join('/')

// Add the cleaned path to the sitemap if valid
if (cleanedPath) {
Expand Down

0 comments on commit 6d63214

Please sign in to comment.