const fs = require('fs');
const path = require('path');
const cheerio = require('cheerio');

const htmlPath = path.resolve(__dirname, './shop-home.html');
const html = fs.readFileSync(htmlPath, 'utf-8');

const $ = cheerio.load(html);

const categories = [];

$('a.category-item-Y9CQFP').each((_, el) => {
  const $a = $(el);

  const name = $a.text().trim();

  const url = $a.attr('href') || '';

  const categoryId = $a.attr('data-id');

  const image = $a.find('img').attr('data-src') || '';

  categories.push({
    name, categoryId, url, image,
  });
});

fs.writeFileSync(path.resolve(__dirname, './category.json'), JSON.stringify(categories, null, 2), 'utf-8');
