Add importer
This commit is contained in:
107
frontend/app/import/page.js
Normal file
107
frontend/app/import/page.js
Normal 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(' &')
|
||||
.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 (
|
||||
<main>
|
||||
<h1>Import {new Date().toISOString()}</h1>
|
||||
{/* <pre>{JSON.stringify({ categories, topics }, null, 2)}</pre> */}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user