Add importer

This commit is contained in:
2023-06-10 19:17:11 +04:00
parent a59bd92b89
commit a98bc44732

107
frontend/app/import/page.js Normal file
View File

@@ -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(' &amp')
.join('')
.split('&')
.join('and')
.split('/')
.join('-')
)
}
function sanitize(str = '') {
return (
str
//
.split(' &amp')
.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 (
<main>
<h1>Import {new Date().toISOString()}</h1>
{/* <pre>{JSON.stringify({ categories, topics }, null, 2)}</pre> */}
</main>
)
}