Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KishiTheMechanic committed Oct 27, 2024
1 parent 8604d6c commit b715f63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 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.1",
"version": "0.7.2",
"description": "Lightweight global state management library for Fresh framework using Preact signals.",
"runtimes": ["deno", "browser"],
"exports": "./mod.ts",
Expand Down
21 changes: 11 additions & 10 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,37 +111,38 @@ async function generateSitemap(
const relPath = distDirectory === '.'
? path
: path.substring(distDirectory.length)
const segments = normalize(`/${relPath}`).split(SEPARATOR).map((
segment,
) => segment.replace(/\.tsx$/, ''))
const segments = normalize(`/${relPath}`).split(SEPARATOR)

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

if (filteredSegments.length === 0) continue // Skip if no valid segments remain

// Construct valid pathname
const pathname = `/${filteredSegments.join('/')}`
.replace(/\/+/g, '/') // Replace multiple slashes with a single slash

// Apply include/exclude filters if specified
const isExcluded = exclude && exclude.test(pathname.substring(1))
const isIncluded = !include || include.test(pathname.substring(1))
if (isExcluded || !isIncluded) continue

const { mtime } = await Deno.stat(path)
sitemap.push({
loc: basename.replace(/\/+$/, '') + pathname,
loc: `${basename.replace(/\/+$/, '')}${pathname}`,
lastmod: (mtime ?? new Date()).toISOString(),
})

// Add paths for each specified language, if applicable
options.languages?.forEach((lang) => {
if (lang !== options.defaultLanguage) {
sitemap.push({
loc: `${basename}/${lang}${pathname}`.replace(/\/+/g, '/'),
loc: `${basename}/${lang}${pathname}`,
lastmod: (mtime ?? new Date()).toISOString(),
})
}
Expand Down

0 comments on commit b715f63

Please sign in to comment.