feat: Update total calculator count to include all calculators by modifying the migration script.

This commit is contained in:
Ben
2026-03-08 19:34:07 -07:00
parent 3ae77e02a0
commit 379bb60722
6 changed files with 37196 additions and 13 deletions

View File

@@ -1,11 +1,13 @@
import json
import re
import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent
CALCLIST = BASE_DIR / 'calculators_list.md'
OUTPUT_FILE = BASE_DIR / 'hdyc-svelte/src/lib/data/calculators.ts'
STATS_FILE = BASE_DIR / 'hdyc-svelte/src/lib/data/stats.ts'
CALCULATORS_JSON = BASE_DIR / 'hdyc-svelte/static/data/calculators.json'
CATEGORY_KEYS = [
'length',
@@ -496,15 +498,21 @@ export function searchCalculators(query: string): CalculatorDef[] {
print(f"Generated {len(calculators_ts_entries)} calculators into calculators.ts")
# Generate stats.ts
active_count = len([e for e in calculators_ts_entries if not e.get('hidden')])
total_count = len(calculators_ts_entries)
stats_content = f"""// THIS FILE IS AUTO-GENERATED BY migrate.py
export const categories: Record<string, {{ label: string; icon: string }}> = {json.dumps(CATEGORIES, indent=2, ensure_ascii=False)};
export const totalCalculators = {active_count};
export const totalCalculators = {total_count};
"""
with open(STATS_FILE, 'w', encoding='utf-8') as f:
f.write(stats_content)
print(f"Generated stats.ts with {active_count} active calculators")
print(f"Generated stats.ts with {total_count} total calculators")
# Generate calculators.json for true lazy loading
os.makedirs(os.path.dirname(CALCULATORS_JSON), exist_ok=True)
with open(CALCULATORS_JSON, 'w', encoding='utf-8') as f:
json.dump(calculators_ts_entries, f, ensure_ascii=False, indent=2)
print(f"Generated calculators.json (Size: {os.path.getsize(CALCULATORS_JSON) // 1024}KB)")
if __name__ == '__main__':
process()