diff --git a/frontend/app/import/page.js b/frontend/app/import/page.js new file mode 100644 index 0000000..bcac672 --- /dev/null +++ b/frontend/app/import/page.js @@ -0,0 +1,107 @@ +import directus from '~/lib/directus' +import all from '~/public/data.json' + +function sluggify(str = '') { + return ( + str + .toLocaleLowerCase() + .trim() + // + .split(' ') + .join('-') + .split('-/-') + .join('-') + .split('(') + .join('') + .split(')') + .join('') + .split(' &') + .join('') + .split('&') + .join('and') + .split('/') + .join('-') + ) +} + +function sanitize(str = '') { + return ( + str + // + .split(' &') + .join('') + .split(' / ') + .join('/') + .split('/') + .join(' / ') + .trim() + ) +} + +export default async function Home() { + // // Categories : marketplaceexhibitorcategory + // all.results.map((one) => { + // one.raw.marketplaceexhibitorcategory?.map(async (cat) => { + // const slug = sluggify(cat) + // try { + // await directus.items('categories').createOne({ + // slug, + // name: sanitize(cat), + // }) + // } catch (error) {} + // }) + // }) + + // // Subcategories : marketplaceexhibitorsubcategory + // all.results.map((one) => { + // one.raw.marketplaceexhibitorsubcategory?.map(async (cat) => { + // const slug = sluggify(cat) + // try { + // await directus.items('categories').createOne({ + // slug, + // name: sanitize(cat), + // }) + // } catch (error) {} + // }) + // }) + + // // Category structure : marketplaceexhibitorcategorysubcategory + // const { data: categories } = await directus.items('categories').readByQuery({ limit: -1 }) + // all.results.map((one) => { + // one.raw.marketplaceexhibitorcategorysubcategory?.map(async (cat) => { + // const [parentTitle, catTitle] = cat.split('|') + // const catSlug = sluggify(catTitle) + // const parentSlug = sluggify(parentTitle) + // if (parentSlug) { + // try { + // const category = categories.find((c) => catSlug === c.slug) + // const parent = categories.find((c) => parentSlug === c.slug) + // await directus.items('categories').updateOne(category.id, { + // parent_id: parent.id, + // }) + // } catch (error) {} + // } + // }) + // }) + + // // Topics : industrytopicsubtopics + // all.results.map((one) => { + // one.raw.industrytopicsubtopics?.map(async (cat) => { + // const slug = sluggify(cat) + // try { + // await directus.items('topics').createOne({ + // slug, + // name: sanitize(cat), + // }) + // } catch (error) {} + // }) + // }) + // const { data: topics } = await directus.items('topics').readByQuery({ limit: -1 }) + + return ( +
+

Import {new Date().toISOString()}

+ {/*
{JSON.stringify({ categories, topics }, null, 2)}
*/} +
+ ) +}