final touch
This commit is contained in:
parent
7b7b979b20
commit
72266d1cd5
|
@ -36,8 +36,6 @@ export default async function importFromHTMLFile(
|
||||||
|
|
||||||
const jsonData = parse(document.documentElement.outerHTML);
|
const jsonData = parse(document.documentElement.outerHTML);
|
||||||
|
|
||||||
// console.log(jsonData);
|
|
||||||
|
|
||||||
for (const item of jsonData) {
|
for (const item of jsonData) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
await processBookmarks(userId, item as Element);
|
await processBookmarks(userId, item as Element);
|
||||||
|
@ -54,15 +52,13 @@ async function processBookmarks(
|
||||||
if (data.type === "element") {
|
if (data.type === "element") {
|
||||||
for (const item of data.children) {
|
for (const item of data.children) {
|
||||||
if (item.type === "element" && item.tagName === "dt") {
|
if (item.type === "element" && item.tagName === "dt") {
|
||||||
|
// process collection or sub-collection
|
||||||
|
|
||||||
let collectionId;
|
let collectionId;
|
||||||
const collectionName = item.children.find(
|
const collectionName = item.children.find(
|
||||||
(e) => e.type === "element" && e.tagName === "h3"
|
(e) => e.type === "element" && e.tagName === "h3"
|
||||||
) as Element;
|
) as Element;
|
||||||
|
|
||||||
console.log("collection:", item);
|
|
||||||
console.log("collectionName:", collectionName);
|
|
||||||
|
|
||||||
// This is a collection or sub-collection
|
|
||||||
if (collectionName) {
|
if (collectionName) {
|
||||||
collectionId = await createCollection(
|
collectionId = await createCollection(
|
||||||
userId,
|
userId,
|
||||||
|
@ -76,23 +72,16 @@ async function processBookmarks(
|
||||||
collectionId || parentCollectionId
|
collectionId || parentCollectionId
|
||||||
);
|
);
|
||||||
} else if (item.type === "element" && item.tagName === "a") {
|
} else if (item.type === "element" && item.tagName === "a") {
|
||||||
// This is a link
|
// process link
|
||||||
|
|
||||||
// get link href
|
|
||||||
const linkUrl = item?.attributes.find((e) => e.key === "href")?.value;
|
const linkUrl = item?.attributes.find((e) => e.key === "href")?.value;
|
||||||
|
|
||||||
// get link name
|
|
||||||
const linkName = (
|
const linkName = (
|
||||||
item?.children.find((e) => e.type === "text") as TextNode
|
item?.children.find((e) => e.type === "text") as TextNode
|
||||||
)?.content;
|
)?.content;
|
||||||
|
|
||||||
// get link tags
|
|
||||||
const linkTags = item?.attributes
|
const linkTags = item?.attributes
|
||||||
.find((e) => e.key === "tags")
|
.find((e) => e.key === "tags")
|
||||||
?.value.split(",");
|
?.value.split(",");
|
||||||
|
|
||||||
console.log("link:", item);
|
|
||||||
|
|
||||||
if (linkUrl && parentCollectionId) {
|
if (linkUrl && parentCollectionId) {
|
||||||
await createLink(
|
await createLink(
|
||||||
userId,
|
userId,
|
||||||
|
@ -118,11 +107,9 @@ async function processBookmarks(
|
||||||
|
|
||||||
await processBookmarks(userId, item, parentCollectionId);
|
await processBookmarks(userId, item, parentCollectionId);
|
||||||
} else {
|
} else {
|
||||||
// This could be anything else
|
// process anything else
|
||||||
await processBookmarks(userId, item, parentCollectionId);
|
await processBookmarks(userId, item, parentCollectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add more conditions as necessary based on your JSON structure
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ŝarĝante…
Reference in New Issue