Skip to content

Commit b8c5347

Browse files
committed
Try fix search again
1 parent cfde894 commit b8c5347

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

web/astro.config.mjs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { defineConfig } from 'astro/config';
33
import starlight from '@astrojs/starlight';
44
import mtasaStarlightThemePlugin from '@multitheftauto/starlight-theme-mtasa';
55
import { SITE_TITLE, SITE_URL } from './src/content.constants';
6-
import fs from 'fs';
7-
import path from 'path';
6+
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, existsSync } from 'fs';
7+
import { join } from 'path';
8+
89

910
export default defineConfig({
1011
site: SITE_URL,
@@ -106,16 +107,52 @@ export default defineConfig({
106107
plugins: [
107108
{
108109
name: 'override-pagefind-config',
109-
closeBundle: async () => {
110-
const configPath = path.join('dist', 'pagefind', 'pagefind.json');
111-
112-
if (fs.existsSync(configPath)) {
113-
let config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
114-
config.source = 'pages';
115-
fs.writeFileSync(configPath, JSON.stringify(config));
110+
writeBundle: {
111+
sequential: true,
112+
order: 'post',
113+
handler: async () => {
114+
console.log('⏳ Konfiguruję PageFind...');
115+
116+
const targetDir = join('dist', 'pagefind');
117+
const sourceDir = join('dist', '_pagefind');
118+
119+
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
120+
121+
const filesToCopy = ['pagefind.js', 'pagefind.json', 'pagefind-*.wasm'];
122+
filesToCopy.forEach(pattern => {
123+
try {
124+
const sourcePath = join(sourceDir, pattern.replace('*', ''));
125+
if (existsSync(sourcePath)) {
126+
copyFileSync(
127+
sourcePath,
128+
join(targetDir, pattern.replace('*', ''))
129+
);
130+
console.log(`📁 Skopiowano ${pattern}`);
131+
}
132+
} catch (error) {
133+
console.warn(`⚠️ Nie udało się skopiować ${pattern}:`, error.message);
134+
}
135+
});
136+
137+
const configPath = join(targetDir, 'pagefind.json');
138+
if (existsSync(configPath)) {
139+
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
140+
config.source = 'pages';
141+
writeFileSync(configPath, JSON.stringify(config));
142+
console.log('⚙️ Zaktualizowano ścieżkę źródłową (pages)');
143+
} else {
144+
writeFileSync(configPath, JSON.stringify({
145+
source: 'pages',
146+
bundlePath: '/pagefind/'
147+
}));
148+
149+
console.log('⚙️ Utworzono nową konfigurację PageFind');
150+
}
151+
152+
console.log('✅ Konfiguracja PageFind zakończona');
116153
}
117-
},
118-
},
119-
],
154+
}
155+
}
156+
]
120157
}
121158
});

0 commit comments

Comments
 (0)