Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@ const hasOwnProperty = (obj, key) =>
const hasTrailingSlash = (pathname) =>
pathname === '/' ? false : TRAILING_SLASH.test(pathname);

exports.onPreBootstrap = () => {
exports.onPreBootstrap = async () => {
console.log('🔍 Building search index...');

// Build search index for current BUILD_LANG (Netlify-compatible approach)
try {
const SearchIndexBuilder = require('./scripts/search/build-search-index.js');

// Get current build language from environment (for production builds)
const currentBuildLang = process.env.BUILD_LANG || 'en';
console.log(`🌐 Building search index for language: ${currentBuildLang.toUpperCase()}`);

const builder = new SearchIndexBuilder(currentBuildLang);
await builder.build();
console.log(`✅ Search index built successfully for ${currentBuildLang.toUpperCase()}!`);
} catch (error) {
console.error('❌ Failed to build search indexes:', error);
// Don't fail the build, just log the error
}

// Create navigation (existing functionality)
createSingleNav();
};

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
"add-files-to-translate": "node scripts/actions/add-files-to-translation-queue.js",
"build:production": "ENVIRONMENT=production yarn run build",
"build": "scripts/build.sh",
"build:search-index": "node scripts/search/build-search-index.js",
"build:search-indexes-all": "node scripts/search/build-all-search-indexes.js",
"test:search": "node scripts/search/test-search.js",
"check-for-outdated-translations": "node scripts/actions/check-for-outdated-translations.js",
"clean": "gatsby clean",
"convert-to-webp": "node scripts/convertPNGs.mjs",
Expand Down Expand Up @@ -224,7 +227,7 @@
"serialize": "node ./scripts/serde.mjs serialize",
"serve": "gatsby serve",
"start:full": "NODE_OPTIONS='--max-old-space-size=5120' yarn develop",
"start": "NODE_OPTIONS='--max-old-space-size=5120' BUILD_LANG=en yarn develop",
"start": "NODE_OPTIONS='--max-old-space-size=8192' BUILD_LANG=en yarn develop",
"test": "yarn test:cjs && yarn test:esm",
"test:cjs": "jest -i",
"test:esm": "NODE_OPTIONS=--loader=esmock uvu . __esm-tests__",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ if [[ -z "${BUILD_LANG}" ]]; then
echo "BUILD_LANG env var required 🥸 set BUILD_LANG=en for a default build"
exit 1
else
echo "Building search indexes for ALL languages..."
node scripts/search/build-all-search-indexes.js
echo "All search indexes built successfully!"
exec node scripts/createNetlifyRedirects.mjs & NODE_OPTIONS='--max-old-space-size=5120' gatsby build --prefix-paths
fi
80 changes: 80 additions & 0 deletions scripts/search/build-all-search-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const SearchIndexBuilder = require('./build-search-index.js');

async function buildAllSearchIndexes() {
console.log('🔍 Building search indexes for ALL languages...');

// Define all supported languages
const supportedLanguages = ['en', 'es', 'fr', 'jp', 'kr', 'pt'];

// Check which languages actually have content
const availableLanguages = [];
for (const lang of supportedLanguages) {
let contentPath;
if (lang === 'en') {
contentPath = path.join(__dirname, '../../src/content/docs');
} else {
contentPath = path.join(__dirname, `../../src/i18n/content/${lang}/docs`);
}

if (fs.existsSync(contentPath)) {
availableLanguages.push(lang);
console.log(`📂 Found content for language: ${lang.toUpperCase()}`);
} else {
console.log(`⚠️ No content found for language: ${lang.toUpperCase()} (path: ${contentPath})`);
}
}

console.log(`📚 Building search indexes for ${availableLanguages.length} languages: ${availableLanguages.join(', ')}`);

// Build indexes for all available languages in parallel
const buildPromises = availableLanguages.map(async (lang) => {
try {
console.log(`🔨 Building index for ${lang.toUpperCase()}...`);
const builder = new SearchIndexBuilder(lang);
await builder.build();
console.log(`✅ Search index built for ${lang.toUpperCase()}`);
return { lang, success: true };
} catch (error) {
console.error(`❌ Failed to build search index for ${lang.toUpperCase()}:`, error);
return { lang, success: false, error };
}
});

const results = await Promise.all(buildPromises);

// Report results
const successful = results.filter(r => r.success);
const failed = results.filter(r => !r.success);

console.log(`\n📊 Build Summary:`);
console.log(`✅ Successful: ${successful.length} (${successful.map(r => r.lang.toUpperCase()).join(', ')})`);
if (failed.length > 0) {
console.log(`❌ Failed: ${failed.length} (${failed.map(r => r.lang.toUpperCase()).join(', ')})`);
}

if (failed.length === 0) {
console.log(`🎉 All search indexes built successfully!`);
} else {
console.error(`⚠️ Some search indexes failed to build`);
process.exit(1);
}
}

// Run if called directly
if (require.main === module) {
buildAllSearchIndexes()
.then(() => {
console.log('🎉 Multi-language search index build complete!');
process.exit(0);
})
.catch((error) => {
console.error('❌ Multi-language search index build failed:', error);
process.exit(1);
});
}

module.exports = buildAllSearchIndexes;
Loading
Loading