farling42 / obsidian-import-json

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

FR: Public API for other plugin use #2

Closed valentine195 closed 2 years ago

valentine195 commented 2 years ago

Hey! I was thinking about adding the ability to specify import templates using handlebars for the TTRPG Statblocks plugin, and realized that you already did the hard work :)

Would it be possible for you to create a generic method I could pass a json file and handlebars template file to, and get back the parsed file?

farling42 commented 2 years ago

The convertJson routine in my plugin takes a jsonfile which contains an array of records and creates many files, one per record in the array.

If that is what is required then I can probably make it an easy exported method.

--

If you only require a single record to be processed then it might be quicker to grab just the few lines required:

85 (JSON.parse)

88-92 (sets up handlebars)

125 (let body = template(jsondata)).

On 16/01/2022 00:09, Jeremy Valentine wrote:

Hey! I was thinking about adding the ability to specify import templates using handlebars for the TTRPG Statblocks plugin, and realized that you already did the hard work :)

Would it be possible for you to create a generic method I could pass a json file and handlebars template file to, and get back the parsed file?

— Reply to this email directly, view it on GitHub https://github.com/farling42/obsidian-import-json/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFM4SCXQT245SRR55WNRDLUWIECBANCNFSM5MBSPXLA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

valentine195 commented 2 years ago

Yup, basically. The idea would be to pass a file of JSON array of objects and a handlebars file and get back the array of monsters.

Edit: but yeah, no worries - I can just pull out the code too. Probably easier in the end 😁

farling42 commented 2 years ago

My version adds the files directly into the vault in a named location; I don't know if you would want them there.

It is only half a dozen lines - the main thing is to initialize the handlebars thing only once per batch. :)

valentine195 commented 2 years ago

Thanks for the heads up!