farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
85 stars 5 forks source link

Importer says "finished" but nothing happens. #63

Closed KINOTheProducer closed 7 months ago

KINOTheProducer commented 8 months ago

Hey there, sorry for the bother, I'm trying to get this working to import a JSON file with about 75 notes from Mem.ai to Obsidian, but I've never used Handlebar files for something like this, so I feel like I might be doing something wrong here.

This is an example of how the Mem notes are saved in the JSON:

[
{
    "id":"8CAfvLVns1CkWeHohW6N",
    "title":"Holy Grail Of Web Dev",
    "markdown":"# Holy Grail Of Web Dev\n \n\nWeb3:\n- web3.js\n- ether.js\n- sequence.xyz\n\n3D:\n- three.js\n\nAnimation:\n- Framer Motion\n\nAuth:\n- Kinde (Next.js)\n- Auth0\n\nDatabase:\n- Firebase\n- Supabase\n- Planetscale\n",
    "tags":["react","webdev"],
    "created":"2023-07-05T15:06:59.808Z","updated":"2023-07-05T15:13:00.905Z"
},
{
    "id":"huGwEHvWPDqTvFSm4OjX",
    "title":"13 Sites to Find Free Fonts to Elevate Your Design",
    "markdown":"## 13 Sites to Find Free Fonts to Elevate Your Design\n\n[https://twitter.com/hyperfreelancer/status/1671178174645010433](https://twitter.com/hyperfreelancer/status/1671178174645010433)\n\n**🪄Smart summary:**\nThis thread provides a list of 13 websites that offer free fonts to help elevate design from \"meh\" to extraordinary. The websites range from Fontshare, Open Foundry, Freefaces, Uncut, Use Modify, Velvetyne, Collletttivo, Badass fonts by womxm, Tunera Foundry, Death of typography, Pixel Surplus, and The League of Moveable Type.\n-------\n\n80% of good design is typography. It's fact.\n\nYet, most people settle for generic Google fonts. 🫤\n\n13 sites I use to find true masterpiece free fonts that will help elevate your design from \"meh\" to extraordinary: [https://t.co/8NO1OK9M9U](https://t.co/8NO1OK9M9U)\n\n1️⃣ Fontshare\n\nFontshare is a free fonts service from the Indian Type Foundry (ITF), making quality fonts accessible to all.\n\n[https://t.co/dzU1pCAuga](https://t.co/dzU1pCAuga)\n\n![](https://pbs.twimg.com/media/FzE3sqHaQAAYb6l.jpg)\n\n2️⃣ Open Foundry\n\nA new platform for open-source fonts in a noise-free environment, to highlight their beauty, extend functionality and encourage further exploration.\n\n[https://t.co/16lO8K555V](https://t.co/16lO8K555V)\n\n![](https://pbs.twimg.com/media/FzE3tHxaIAUICxv.jpg)\n\n3️⃣ Freefaces\n\nThis website is a curated collection of typefaces that are available under a variety of free licences somewhere on the interwebs.\n\n[https://t.co/djwc4fBYdS](https://t.co/djwc4fBYdS)\n\n![](https://pbs.twimg.com/media/FzE3tvPacAAt5Ua.jpg)\n\n4️⃣ Uncut\n\nUNCUT is a (mostly*) libre typeface catalogue, focusing on somewhat contemporary type. ",
    "tags":[],
    "created":"2023-06-21T08:00:05.568Z",
    "updated":"2023-06-21T08:00:05.568Z"
}
]

And this is my Handlebars.md file:

{{#each id}}

{{markdown}}

**Tags:** {{tags.join(', ')}}

_Created:_ {{created}}

_Updated:_ {{updated}}

{{/each}}

I've tried this setup in the importer to no avail. I'm sure my Handlebars is incorrect and would love some insight if that's the case or not:

Thank you so much for making this importer in the first place!

farling42 commented 8 months ago

You don't need the outer #each.

The importer will iterate over each element in the outer array in the JSON data and pass each individual array element to the handlebars parser.

farling42 commented 8 months ago

Joining the tags together in handlebars is {{join tags ", "}}

KINOTheProducer commented 8 months ago

Thank you @farling42 - that made the import go through!

It seems the beginning of the markdown has the title listed again, and I'm trying to remove that duplicated data - just leaving the filename as the header. It appears like so:

This is my current Handlebars template, but again, feel as though this may be incorrect. Would I need a Handlebar Helper for this?

**Tags:** {{#each tags}}#{{this}} {{/each}}

{{{{#with title as |t|}}
{{#with (replace markdown (concat "# " t "\n") "") as |content|}}
{{content}} {{/with}} {{/with}}}}

_Created:_ {{created}}

_Updated:_ {{updated}}
farling42 commented 8 months ago

The first occurrence at the top of your image is the name of the note file itself. (There might be an Obsidian option to not display the note name at the top of each page.)

So you might not need to include the title at the start of your template.