← back to Dw Sarah Rowland Searchfix
inspect-titles.mjs
22 lines
import { gql } from './lib.mjs';
import fs from 'node:fs';
const products=JSON.parse(fs.readFileSync(new URL('./products.json',import.meta.url)));
const generic=products.filter(p=>/^Wallcovering \| Architectural Wallcoverings\s*$/.test(p.title.trim()) || p.title.trim()==='Wallcovering | Architectural Wallcoverings');
console.log(`Bare-title products: ${generic.length} of ${products.length}\n`);
// what naming data exists? sample the first 6
const Q=`query($id:ID!){ product(id:$id){ handle title
pat:metafield(namespace:"custom",key:"pattern_name"){value}
patD:metafield(namespace:"dwc",key:"pattern_name"){value}
col:metafield(namespace:"custom",key:"color"){value}
colway:metafield(namespace:"custom",key:"color_way"){value}
mfrpat:metafield(namespace:"custom",key:"mfr_pattern_number"){value}
sku:variants(first:1){nodes{sku}} } }`;
for(const p of generic.slice(0,6)){
const d=(await gql(Q,{id:p.id})).product;
console.log(`handle: ${d.handle}`);
console.log(` pattern_name(custom)=${d.pat?.value??'∅'} pattern_name(dwc)=${d.patD?.value??'∅'} color=${d.col?.value??'∅'} color_way=${d.colway?.value??'∅'} sku=${d.sku.nodes[0]?.sku??'∅'}`);
}
// also show 3 well-formed siblings for the naming CONVENTION
console.log('\n— well-formed sibling titles for reference —');
products.filter(p=>/ - .*Wallcovering/i.test(p.title)).slice(0,4).forEach(p=>console.log(' ',p.title));