From eaba20c208fd90a964f7a56a954c86519a694c23 Mon Sep 17 00:00:00 2001 From: Ryderjj89 Date: Sun, 28 Sep 2025 13:29:02 -0400 Subject: [PATCH] Clean up encoding fixes - removed complex encoding conversion since NKJV files have been manually fixed to match mdbible formatting - Removed fix-nkjv-encoding.js utility script (no longer needed) - Simplified readMarkdownFile back to basic BOM removal - NKJV files now use same format as ESV: numbered paragraphs (1. verses...) - Maintains React parsing for both ESV and NKJV formats --- fix-nkjv-encoding.js | 101 ------------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 fix-nkjv-encoding.js diff --git a/fix-nkjv-encoding.js b/fix-nkjv-encoding.js deleted file mode 100644 index fd6f3c32..00000000 --- a/fix-nkjv-encoding.js +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env node - -/** - * NKJV Encoding Fix Utility - * Converts NKJV markdown files from problematic encoding to clean UTF-8 - */ - -const fs = require('fs'); -const path = require('path'); - -const NKJV_DIR = './NKJV'; - -function walkDirectory(dir, callback) { - const entries = fs.readdirSync(dir, { withFileTypes: true }); - - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - - if (entry.isDirectory()) { - walkDirectory(fullPath, callback); - } else if (entry.isFile() && entry.name.endsWith('.md')) { - callback(fullPath); - } - } -} - -function fixFileEncoding(filePath) { - console.log(`Processing: ${filePath}`); - - try { - // Try to read with UTF-8 first - let content = fs.readFileSync(filePath, 'utf-8'); - - // Check for encoding issues - const hasReplacementChars = content.includes('\ufffd'); // character - const hasCorruptedText = /\w\w/.test(content); // Interspersed replacement chars - - if (hasReplacementChars || hasCorruptedText) { - console.log(` ✓ Found encoding issues, fixing...`); - - // Try alternative encodings - try { - // Attempt Latin-1 reading - content = fs.readFileSync(filePath, 'latin1').normalize('NFC'); - console.log(` ✓ Successfully converted to Latin-1 encoding`); - } catch (latinError) { - console.log(` ✗ Latin-1 conversion failed`); - } - - // Clean up any remaining encoding artifacts - content = content - .replace(/\ufffd/g, '') // Remove replacement characters - .replace(/^\uFEFF/, '') // Remove UTF-8 BOM if present - .replace(/\r\n/g, '\n') // Normalize Windows line endings - .replace(/\r/g, '\n') // Handle stray carriage returns - .trim(); - - // Write back cleaned content - fs.writeFileSync(filePath, content, 'utf-8'); - console.log(` ✓ Fixed and saved: ${filePath}`); - } else { - console.log(` ✓ File appears clean`); - } - - } catch (error) { - console.error(` ✗ Failed to process ${filePath}:`, error.message); - } -} - -console.log('🚀 Starting NKJV encoding fix...'); -console.log(`Scanning directory: ${NKJV_DIR}`); -console.log(''); - -let processedCount = 0; -let fixedCount = 0; - -walkDirectory(NKJV_DIR, (filePath) => { - processedCount++; - const originalContent = fs.readFileSync(filePath, 'utf-8'); - const originalLength = originalContent.length; - - fixFileEncoding(filePath); - - // Check if file was modified - try { - const newContent = fs.readFileSync(filePath, 'utf-8'); - if (!originalContent.includes('\ufffd') && newContent.includes('\ufffd')) { - console.log(` ⚠️ No encoding issues found`); - } - } catch (checkError) { - // File exists, just continue - } -}); - -console.log(''); -console.log('✅ Encoding fix complete!'); -console.log(`Processed ${processedCount} files`); -console.log(''); -console.log('🔄 Now rebuild your containers:'); -console.log('docker-compose build --no-cache'); -console.log('docker-compose up -d');