Fix 3-col calculator labelling and add lint
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
"start": "node build",
|
"start": "node build",
|
||||||
"prepare": "svelte-kit sync || echo ''",
|
"prepare": "svelte-kit sync || echo ''",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"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": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-node": "^5.5.4",
|
"@sveltejs/adapter-node": "^5.5.4",
|
||||||
|
|||||||
36
hdyc-svelte/scripts/lint-3col.mjs
Executable file
36
hdyc-svelte/scripts/lint-3col.mjs
Executable file
@@ -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.');
|
||||||
@@ -11,7 +11,9 @@
|
|||||||
$: calc = data.calculator;
|
$: calc = data.calculator;
|
||||||
$: related = data.related;
|
$: related = data.related;
|
||||||
$: pageTitle = `${calc.name} — ${SITE_NAME}`;
|
$: 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({
|
$: seo = buildSeoMeta({
|
||||||
title: pageTitle,
|
title: pageTitle,
|
||||||
description: pageDescription,
|
description: pageDescription,
|
||||||
|
|||||||
20
migrate.py
20
migrate.py
@@ -187,6 +187,11 @@ def process():
|
|||||||
except:
|
except:
|
||||||
pass
|
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
|
# Avoid escaping single quotes by using JSON or dict
|
||||||
entry = {
|
entry = {
|
||||||
'slug': slug,
|
'slug': slug,
|
||||||
@@ -200,11 +205,16 @@ def process():
|
|||||||
# Determine labels
|
# Determine labels
|
||||||
labels = {'in1': in1, 'in2': in2}
|
labels = {'in1': in1, 'in2': in2}
|
||||||
if c_type in ['3col', '3col-mul']:
|
if c_type in ['3col', '3col-mul']:
|
||||||
# generic 3rd label
|
# generic 3rd label; make it descriptive instead of the vague "Result"
|
||||||
if 'watts' in slug and 'amps' in slug: labels['in3'] = 'Volts'
|
if 'watts' in slug and 'amps' in slug:
|
||||||
elif 'lumens' in slug: labels['in3'] = 'Area (sq m)'
|
labels['in3'] = 'Volts'
|
||||||
elif 'moles' in slug: labels['in3'] = 'Molar Mass'
|
elif 'lumens' in slug:
|
||||||
else: labels['in3'] = 'Result'
|
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:
|
if custom_labels:
|
||||||
labels = custom_labels
|
labels = custom_labels
|
||||||
|
|||||||
Reference in New Issue
Block a user