Created
October 23, 2021 11:54
-
-
Save emisjerry/b22db3e1e5465f6b25514aac6b09c897 to your computer and use it in GitHub Desktop.
Open Obsidian starting Home note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
home.js | |
功能: 開啟首頁 | |
*/ | |
const homePage = "!!! StartHere !!!"; | |
const openMode_ = "preview"; // preview, source or default | |
const isNewPanel_ = true; // 是否用新面板開啟 | |
module.exports = async function home(params) { | |
const app = params.app; | |
const files = await app.vault.getMarkdownFiles(); | |
const selectedFile = files.filter(file => file.name === homePage + ".md")[0]; | |
if (selectedFile) { | |
if (isNewPanel_) { | |
const leaf = app.workspace.splitActiveLeaf(); | |
leaf.openFile(selectedFile, { state: {mode: openMode_} }); | |
app.workspace.setActiveLeaf(leaf); | |
} else { | |
app.workspace.activeLeaf.openFile(selectedFile) | |
} | |
} else { | |
new Notice("找不到檔案: " + homePage + ".md", 5000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment