From a529873fd594c406a34f27aa6cddc50e1b42740d Mon Sep 17 00:00:00 2001 From: Jitin Saxena Date: Tue, 16 Sep 2025 01:12:04 +0530 Subject: [PATCH] Fix: Pagefind search integration in Nextra --- next-env.d.ts | 19 ------------------- next.config.mjs | 16 +++++++++++++++- package-lock.json | 15 ++++++++++++--- package.json | 3 ++- types/pagefind.d.ts | 4 ++++ 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 types/pagefind.d.ts diff --git a/next-env.d.ts b/next-env.d.ts index b699436..3cd7048 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,22 +1,3 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - /// /// /// diff --git a/next.config.mjs b/next.config.mjs index 710f6e4..75b3d0c 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -52,4 +52,18 @@ export default withNextra( maxInactiveAge: 25 * 1000, pagesBufferLength: 2, }, - })); + + // 🔑 Add this to ensure Pagefind files are accessible + async headers() { + return [ + { + source: '/_pagefind/:path*', + headers: [ + { key: 'Access-Control-Allow-Origin', value: '*' }, + { key: 'Cache-Control', value: 'public, max-age=3600, immutable' }, + ], + }, + ]; + }, + }) +); diff --git a/package-lock.json b/package-lock.json index 04ddf2f..0f836eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@ai-sdk/react": "^1.2.12", "@codemirror/lang-javascript": "^6.2.4", "@codemirror/lang-python": "^6.2.1", + "@codemirror/view": "^6.37.2", "@floating-ui/react-dom": "^2.0.0", "@gfazioli/mantine-marquee": "^2.2.7", "@gfazioli/mantine-text-animate": "^1.0.3", @@ -21,6 +22,7 @@ "@mdx-js/react": "^3.1.0", "@next/bundle-analyzer": "^15.3.1", "@octokit/rest": "^22.0.0", + "@pagefind/default-ui": "^1.4.0", "@tabler/icons-react": "^3.31.0", "@uiw/codemirror-theme-vscode": "^4.23.12", "@uiw/react-codemirror": "^4.23.12", @@ -2248,12 +2250,13 @@ } }, "node_modules/@codemirror/view": { - "version": "6.36.8", - "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.36.8.tgz", - "integrity": "sha512-yoRo4f+FdnD01fFt4XpfpMCcCAo9QvZOtbrXExn4SqzH32YC6LgzqxfLZw/r6Ge65xyY03mK/UfUqrVw1gFiFg==", + "version": "6.38.2", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.38.2.tgz", + "integrity": "sha512-bTWAJxL6EOFLPzTx+O5P5xAO3gTqpatQ2b/ARQ8itfU/v2LlpS3pH2fkL0A3E/Fx8Y2St2KES7ZEV0sHTsSW/A==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.5.0", + "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } @@ -4908,6 +4911,12 @@ "darwin" ] }, + "node_modules/@pagefind/default-ui": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@pagefind/default-ui/-/default-ui-1.4.0.tgz", + "integrity": "sha512-wie82VWn3cnGEdIjh4YwNESyS1G6vRHwL6cNjy9CFgNnWW/PGRjsLq300xjVH5sfPFK3iK36UxvIBymtQIEiSQ==", + "license": "MIT" + }, "node_modules/@pagefind/linux-arm64": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.3.0.tgz", diff --git a/package.json b/package.json index aa99e17..35528a0 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build && npm run build:pagefind", "build:pagefind": "pagefind --site .next/server/app --output-path public/_pagefind", "analyze": "ANALYZE=true next build", "start": "next start", @@ -35,6 +35,7 @@ "@mdx-js/react": "^3.1.0", "@next/bundle-analyzer": "^15.3.1", "@octokit/rest": "^22.0.0", + "@pagefind/default-ui": "^1.4.0", "@tabler/icons-react": "^3.31.0", "@uiw/codemirror-theme-vscode": "^4.23.12", "@uiw/react-codemirror": "^4.23.12", diff --git a/types/pagefind.d.ts b/types/pagefind.d.ts new file mode 100644 index 0000000..cf0b78d --- /dev/null +++ b/types/pagefind.d.ts @@ -0,0 +1,4 @@ +declare module '@pagefind/default-ui' { + const PagefindUI: any; + export default PagefindUI; +}