How to "create new project" by code
zhangkaihua88 opened this issue · 2 comments
zhangkaihua88 commented
What would you like to be added?
I would like to ask how to quickly create a project through code instead of a UI interface
like this app.plugins.plugins["obsidian-projects"].createProject()
Why is this needed?
Due to my many projects, I want to automate the creation
zhangkaihua88 commented
I implemented it by adding the following code in main.js
addNewProject(data){
data.id = v4_default()
data.views.forEach(view => {
view.id = v4_default(); // Setting the 'type' property to 2
});
settings.addProject(data);
// this.activateView(data.id);
return data.id
}
Calling through JavaScript
a = {
"fieldConfig": {},
"defaultName": "",
"templates": [],
"excludedNotes": [],
"isDefault": false,
"dataSource": {
"kind": "folder",
"config": {
"path": "14_Quant/因子学习",
"recursive": true
}
},
"newNotesFolder": "",
"views": [
{
"config": {},
"filter": {
"conjunction": "and",
"conditions": []
},
"colors": {
"conditions": []
},
"sort": {
"criteria": []
},
"name": "表格",
"type": "table"
}
],
"name": "Quant_test"
};
app.plugins.getPlugin('obsidian-projects').addNewProject(a)