Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created October 23, 2021 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emisjerry/b22db3e1e5465f6b25514aac6b09c897 to your computer and use it in GitHub Desktop.
Save emisjerry/b22db3e1e5465f6b25514aac6b09c897 to your computer and use it in GitHub Desktop.
Open Obsidian starting Home note
/**
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