refactor: Remove redundant introductory sentences from calculator descriptions.

This commit is contained in:
Ben
2026-03-06 21:32:20 -08:00
parent 47042ee5a7
commit 9b05ff70c2
3 changed files with 169 additions and 120 deletions

View File

@@ -33,9 +33,10 @@ def fetch_all_wp_calculators():
for p in pars:
p_clean = re.sub(r'<[^>]+>', '', p).replace('\n', ' ').strip()
p_clean = re.sub(r'\s+', ' ', p_clean)
# Remove first paragraph flavor text boilerplate pattern
p_clean = re.sub(r'^.*?: Technical specifications, .*? conversion factors, and historical unit context\.$', '', p_clean)
if p_clean and "The transformation of this data is governed by universal standard definitions" not in p_clean:
# Actually, maybe the user wants the exact SEO text including that text?
# Let's keep it if they wrote it.
pass
if p_clean:
clean_pars.append(f"<p>{p_clean}</p>")
@@ -208,6 +209,50 @@ def process():
if slug.startswith('decimal'): entry['fromBase'] = 10
else: entry['toBase'] = 10
if category == 'data' and c_type == 'standard':
# Fix data scale names and factors
# Megabytes, Gigabytes, Terabytes etc should use decimal base-10 sizes (1000).
# Mebibytes, Gibibytes, Tebibytes should use binary base-2 sizes (1024).
# Create a simple mapping for names to exponents to calculate strict factors
units_10 = {'byte': 0, 'kilobyte': 3, 'megabyte': 6, 'gigabyte': 9, 'terabyte': 12, 'petabyte': 15, 'exabyte': 18}
units_2 = {'kibibyte': 10, 'mebibyte': 20, 'gibibyte': 30, 'tebibyte': 40, 'pebibyte': 50, 'exbibyte': 60}
in1_key = in1.lower()
if in1_key.endswith('s'): in1_key = in1_key[:-1]
in2_key = in2.lower()
if in2_key.endswith('s'): in2_key = in2_key[:-1]
# Helper to get base and exp
def get_val(k):
if k in units_10: return 10, units_10[k]
if k in units_2: return 2, units_2[k]
if k == 'bit': return 10, -1 # placeholder relative to bytes, though bits are 1/8 byte. Handling simple bytes here only
return None, None
b1, e1 = get_val(in1_key)
b2, e2 = get_val(in2_key)
if b1 and b2 and b1 == b2 and b1 == 10:
# Decimal to decimal
factor = 10 ** (e1 - e2)
factor_val = str(factor)
try: entry['factor'] = float(factor_val)
except: pass
elif b1 and b2 and b1 == b2 and b1 == 2:
# Binary to binary
factor = 2 ** (e1 - e2)
factor_val = str(factor)
try: entry['factor'] = float(factor_val)
except: pass
elif b1 and b2:
# Cross conversion
val1 = (10 ** e1) if b1 == 10 else (2 ** e1)
val2 = (10 ** e2) if b2 == 10 else (2 ** e2)
factor = val1 / val2
try: entry['factor'] = float(factor)
except: pass
# Remove empty descriptions
if desc_html:
entry['descriptionHTML'] = desc_html.replace('"', '\\"').replace('\n', '')
@@ -294,7 +339,7 @@ export function getCalculatorBySlug(slug: string): CalculatorDef | undefined {
}
export function getCalculatorsByCategory(category: string): CalculatorDef[] {
return calculators.filter(c => c.category === category);
return calculators.filter(c => c.category === category && !c.hidden);
}
export function getCategoriesWithCounts(): { key: string; label: string; icon: string; count: number }[] {