diff --git a/.node-version b/.node-version
index cabf43b..8fdd954 100755
--- a/.node-version
+++ b/.node-version
@@ -1 +1 @@
-24
\ No newline at end of file
+22
\ No newline at end of file
diff --git a/README.md b/README.md
index 50971d8..631e7b3 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,7 @@ Nooxy provides sophisticated URL rewriting that handles:
### Prerequisites
-- Node.js
+- Node.js 18.17.0 or higher
- A Cloudflare account (for deployment)
- A custom domain (optional, for production)
@@ -230,7 +230,7 @@ export const SITE_CONFIG = {
// Optional: 404 page configuration
// fof: {
// page: "NOTION_PAGE_ID",
- // slug: "404", // default
+ // slug: "/404", // default
// },
// Optional: Subdomain redirects
@@ -660,7 +660,7 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md) for full guidelines, development s
**Solution**:
-- Ensure you're using Node.js 22.0.0 or higher
+- Ensure you're using Node.js 18.17.0 or higher
- Check that your `wrangler.toml` is configured correctly
- Verify your Notion pages are accessible
diff --git a/examples/cloudflare/nooxy/config.js b/examples/cloudflare/nooxy/config.js
index 8544642..4fdf149 100644
--- a/examples/cloudflare/nooxy/config.js
+++ b/examples/cloudflare/nooxy/config.js
@@ -42,7 +42,7 @@ export const SITE_CONFIG = {
// If you don't have one, the default 404 page will be used
// fof: {
// page: "NOTION_PAGE_ID",
- // slug: "404", // default
+ // slug: "/404", // default
// },
// Subdomain redirects are optional
// But it is recommended to have one for www
diff --git a/package.json b/package.json
index 5a632c7..e2fd15d 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"email": "david@draphy.org"
},
"engines": {
- "node": ">=22.0.0"
+ "node": ">=18.17.0"
},
"license": "MIT",
"publishConfig": {
@@ -63,7 +63,7 @@
}
},
"scripts": {
- "prebuild": "node converter.js && pnpm biome:fix ",
+ "prebuild": "node converter.js && pnpm biome:fix",
"build": "pnpm run prebuild && tsup src/index.ts --format esm --dts-resolve --clean --sourcemap --out-dir dist && pnpm run build:cli",
"build:cli": "tsup src/cli/index.ts --format esm --clean --out-dir dist/cli && cp -r src/cli/templates dist/cli/",
"biome:lint": "biome lint .",
diff --git a/src/cli/templates/config.js b/src/cli/templates/config.js
index 8544642..4fdf149 100644
--- a/src/cli/templates/config.js
+++ b/src/cli/templates/config.js
@@ -42,7 +42,7 @@ export const SITE_CONFIG = {
// If you don't have one, the default 404 page will be used
// fof: {
// page: "NOTION_PAGE_ID",
- // slug: "404", // default
+ // slug: "/404", // default
// },
// Subdomain redirects are optional
// But it is recommended to have one for www
diff --git a/src/handlers/handle-sitemap.ts b/src/handlers/handle-sitemap.ts
index 994071f..f18c708 100644
--- a/src/handlers/handle-sitemap.ts
+++ b/src/handlers/handle-sitemap.ts
@@ -5,7 +5,7 @@ export function handleSitemap(siteConfig: NooxySiteConfigFull, protocol: string)
let sitemap = '';
slugs.forEach((slug) => {
- sitemap += `${protocol}//${domain}/${slug}`;
+ sitemap += `${protocol}//${domain}${slug}`;
});
sitemap += '';
diff --git a/src/helpers/config-loader.ts b/src/helpers/config-loader.ts
index ed2fe9a..cfd98c1 100644
--- a/src/helpers/config-loader.ts
+++ b/src/helpers/config-loader.ts
@@ -40,11 +40,11 @@ export class ConfigManager {
siteConfig.fof = {
page: siteConfig.fof?.page,
- slug: siteConfig.fof?.slug || '404',
+ slug: siteConfig.fof?.slug || '/404',
};
if (siteConfig.fof.page?.length) {
- siteConfig.slugToPage[siteConfig.fof.slug ?? ''] = siteConfig.fof.page;
+ siteConfig.slugToPage[siteConfig.fof.slug ?? '/404'] = siteConfig.fof.page;
}
// Build helper indexes
diff --git a/src/helpers/index.ts b/src/helpers/index.ts
index c14ef54..07d8b8d 100644
--- a/src/helpers/index.ts
+++ b/src/helpers/index.ts
@@ -88,16 +88,15 @@ export function isNotion404(pathname: string, slugToPage: Record
) {
return false;
}
- const lastSlashIndex = pathname.lastIndexOf('/');
- const slugSlash = lastSlashIndex === -1 ? pathname : pathname.slice(lastSlashIndex + 1);
- const lastHyphenIndex = slugSlash.lastIndexOf('-');
- const slug = lastHyphenIndex === -1 ? slugSlash : slugSlash.slice(lastHyphenIndex + 1);
- if (!slug) {
+ const lastSlash = pathname.slice(pathname.lastIndexOf('/') + 1);
+ const pageId = lastSlash.slice(lastSlash.lastIndexOf('-') + 1);
+ const slug = extractSlug(pathname);
+ if (!pageId && !slug) {
return false;
}
- const page = slugToPage[`/${slug}`];
- const notValidSlug = slug.length !== 32;
- if (!page && notValidSlug) {
+ const page = slugToPage[slug ?? ''];
+ const validPageId = pageId.length === 32;
+ if (!page && !validPageId) {
return true;
}
return false;
diff --git a/src/types.ts b/src/types.ts
index 981cdf2..c6a8a04 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -20,7 +20,7 @@ export interface NooxySiteConfigFull {
// Use the value from your Notion like example.notion.site
notionDomain: string
- // 404 Notion page to display to visitors, the default slug is '404'
+ // 404 Notion page to display to visitors, the default slug is '/404'
fof?: {
page: string | undefined
slug: string | undefined
diff --git a/tsconfig.json b/tsconfig.json
index aca5164..96b3f0d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,7 +3,8 @@
"_version": "22.0.0",
"compilerOptions": {
"lib": [
- "es2023"
+ "ES2021",
+ "DOM"
],
"strict": true,
"moduleResolution": "bundler",
@@ -16,7 +17,7 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
- "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
+ "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -29,7 +30,7 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
- "module": "ESNext", /* Specify what module code is generated. */
+ "module": "ES2022", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */