diff --git a/hdyc-svelte/package.json b/hdyc-svelte/package.json index 087cf54..ad87f0a 100644 --- a/hdyc-svelte/package.json +++ b/hdyc-svelte/package.json @@ -10,7 +10,8 @@ "start": "node build", "prepare": "svelte-kit sync || echo ''", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", - "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "lint:3col": "node scripts/lint-3col.mjs" }, "devDependencies": { "@sveltejs/adapter-node": "^5.5.4", diff --git a/hdyc-svelte/scripts/lint-3col.mjs b/hdyc-svelte/scripts/lint-3col.mjs new file mode 100755 index 0000000..f13aa11 --- /dev/null +++ b/hdyc-svelte/scripts/lint-3col.mjs @@ -0,0 +1,36 @@ +#!/usr/bin/env node +import { readFileSync } from 'fs'; +import path from 'path'; + +const file = path.resolve('src/lib/data/calculators.ts'); +const text = readFileSync(file, 'utf8'); +const start = text.indexOf('['); +const end = text.indexOf('];', start); +if (start === -1 || end === -1) { + console.error('Unable to locate calculators array in calculators.ts'); + process.exit(1); +} +let arr = text.slice(start, end + 1).trim(); +arr = arr.replace(/,\s*\]$/, ']'); +let calculators; +try { + calculators = JSON.parse(arr); +} catch (err) { + console.error('Failed to parse calculators.ts as JSON:', err.message); + process.exit(1); +} + +const offenders = calculators.filter(c => + ['3col', '3col-mul'].includes(c.type) && + c.name.toLowerCase().includes(' to ') && + (!c.labels?.in3 || c.labels.in3.toLowerCase() === 'result') +); + +if (offenders.length) { + console.error(`3-col calculators with vague or missing output labels: ${offenders.length}`); + offenders.slice(0, 20).forEach(c => console.error(`- ${c.slug}`)); + if (offenders.length > 20) console.error(`…and ${offenders.length - 20} more`); + process.exit(1); +} + +console.log('3-col label lint passed.'); diff --git a/hdyc-svelte/src/routes/[slug]/+page.svelte b/hdyc-svelte/src/routes/[slug]/+page.svelte index c74055a..1a83dd3 100644 --- a/hdyc-svelte/src/routes/[slug]/+page.svelte +++ b/hdyc-svelte/src/routes/[slug]/+page.svelte @@ -11,7 +11,9 @@ $: calc = data.calculator; $: related = data.related; $: pageTitle = `${calc.name} — ${SITE_NAME}`; - $: pageDescription = `Convert ${calc.labels.in1} to ${calc.labels.in2} instantly with our free online calculator. Accurate bidirectional conversion with the exact formula shown.`; + $: pageDescription = ['3col', '3col-mul'].includes(calc.type) + ? `Compute ${calc.labels.in3 ?? 'the derived value'} using ${calc.labels.in1} and ${calc.labels.in2}. Enter any two fields to solve the third.` + : `Convert ${calc.labels.in1} to ${calc.labels.in2} instantly with our free online calculator. Accurate two-way conversion with the exact formula shown.`; $: seo = buildSeoMeta({ title: pageTitle, description: pageDescription, diff --git a/migrate.py b/migrate.py index b3a0014..3fdf075 100644 --- a/migrate.py +++ b/migrate.py @@ -187,6 +187,11 @@ def process(): except: pass + # Give 3-col calculators honest display names instead of "A to B" + if c_type in ['3col', '3col-mul'] and split_conversion_name(display_name): + op = '*' if c_type == '3col-mul' else '/' + display_name = f"{in1} {op} {in2}" + # Avoid escaping single quotes by using JSON or dict entry = { 'slug': slug, @@ -200,11 +205,16 @@ def process(): # Determine labels labels = {'in1': in1, 'in2': in2} if c_type in ['3col', '3col-mul']: - # generic 3rd label - if 'watts' in slug and 'amps' in slug: labels['in3'] = 'Volts' - elif 'lumens' in slug: labels['in3'] = 'Area (sq m)' - elif 'moles' in slug: labels['in3'] = 'Molar Mass' - else: labels['in3'] = 'Result' + # generic 3rd label; make it descriptive instead of the vague "Result" + if 'watts' in slug and 'amps' in slug: + labels['in3'] = 'Volts' + elif 'lumens' in slug: + labels['in3'] = 'Area (sq m)' + elif 'moles' in slug: + labels['in3'] = 'Molar Mass' + else: + op = '*' if c_type == '3col-mul' else '/' + labels['in3'] = f"{in1} {op} {in2}" if custom_labels: labels = custom_labels