blacksmithgu / obsidian-dataview Public
generated from obsidianmd/obsidian-sample-pluginNew issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to reuse js code in dataviewjs? #271
Comments
|
I'd find the way. I got the path of the vault root form |
|
This seems to work, but not on iOS. Here the example I used: I create a js file exports.formatDate = date=> date.toLocaleString({ weekday:'short', day: 'numeric'})And then you can use it inside a Note // ```dataviewjs
const lib = require(dv.app.vault.adapter.basePath+'/Queries/library.js')
dv.paragraph(1,lib.formatDate(dv.current().file.ctime))
// ```If you want to reload the referenced library every time, without restarting obsidian, use this code: const src = dv.app.vault.adapter.basePath+'/Queries/library.js'
delete global.require.cache[global.require.resolve(src)]
const lib = require(src) |
|
@andi0b were you able to find a workaround to get this working on iOS? |
No, I copy&pasted the code now into every file. Seems to be the better compromise. |
|
I can add a |
|
Hey, I actually created a new plugin — now in the community store — that specifically addresses code reuse. It can be used in |
This would be actually perfect. Nothing against @SamLewis0602 solution here which works good for me currently, but i'd love to have this centralized in here(as the project allows for coding anyways it makes at least sense to me to have said feature available) |
|
For now, to get this feature "out", I'll probably implement a janky solution which simply loads + evals files for you (with a cache to support recursive includes); the best long-term approach would be to override |
|
I'd be curious to see your solution if you're able to get |
I have some
dataviewjscode blocks defined in some.mdfiles, and they are very similar. Such as some utils functions. I wonder is there a way to place this code together, and import it to adataviewjsblock, just likeimportstatement in ES6?The text was updated successfully, but these errors were encountered: