Yes, this is referencing a couple of other files:
My journal class:
class main {
constructor() {
const tp = app.plugins.plugins['templater-obsidian'].templater.current_functions_object
tp.user._boilerplate(this)
// Journal is sorted by date descending, so most recent is index 0
this.journal = this.dv.pages('"Journal/Daily"').sort(x => x.file.path, 'desc').array()
}
async changeIndex(amount) {
let index = this.journal.findIndex(x => x.file.path === this.file.path)
index = Math.max(0, Math.min(index + amount, this.journal.length - 1))
await this.goToFile(this.journal[index].file.path)
}
async randomEntry() {
const random = this.journal[Math.floor(Math.random() * this.journal.length)]
await this.goToFile(random.file.path)
await this.setEditMode(false) // change to Preview mode
return ''
}
async goToLatestEntry() {
await this.goToFile(this.journal[0].file.path)
return ''
}
async previousEntry() {
await this.changeIndex(1)
return ''
}
async nextEntry() {
await this.changeIndex(-1)
return ''
}
}
module.exports = main
And that file is referencing this general functions class:
function main(target) {
const dv = app.plugins.plugins.dataview.api
const tp = app.plugins.plugins['templater-obsidian'].templater.current_functions_object
target.app = app
target.dv = dv
target.tp = tp
target.page = dv.page(tp.file.path(true))
target.file = target.page.file
target.view = app.workspace.activeLeaf.view
target.sleep = async function (ms) {
await new Promise(resolve => setTimeout(resolve, ms))
}
/**
* Create a new file from a template, and return the link or open the file
* @param {string} templatePath
* @param {string} newNoteName
* @param {string} destinationFolder - Path to the destination folder. Defaults to current folder
* @param {boolean} openNewNote - Open the note in a new window, or return a link
* @returns
*/
target.createFromTemplate = async function (templatePath, newNoteName, destinationFolder, openNewNote) {
destinationFolder = destinationFolder || tp.file.folder(true)
await tp.file.create_new(tp.file.find_tfile(templatePath), newNoteName, openNewNote, app.vault.getAbstractFileByPath(destinationFolder))
return openNewNote ? '' : `[[${newNoteName}]] `
}
target.setEditMode = function (canEdit) {
const curr = app.workspace.activeLeaf.getViewState()
curr.state.mode = canEdit ? 'source' : 'preview'
app.workspace.activeLeaf.setViewState(curr)
if (canEdit) {
target.view.editor?.focus()
}
}
/**
* Get the text contents of a file, specified by string path
* @param {string} path
*/
target.getContents = async function (path) {
const file = app.vault.getAbstractFileByPath(path)
return app.vault.read(file)
}
target.goToFile = async function (path) {
const file = app.vault.getAbstractFileByPath(path)
if (path !== target.file.path) {
await app.workspace.getLeaf(false).openFile(file)
}
}
}
module.exports = main