创建每月笔记库
创建每月笔记库 :在CYG日常和IT工单下创建文件夹
module.exports = async (tp) => {
const fs = app.vault.adapter;
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const formattedDate = `${year}-${month}`;
// 相对于 Obsidian 的工作目录
const dailyDirectory = `CYG-Works/CYG日常/${formattedDate}`; //日常笔记目录
const workDirectory = `CYG-Works/IT工单/${formattedDate}`; //工单笔记目录
try {
// 检查文件夹是否存在
const exists = await fs.exists(dailyDirectory);
if (!exists) {
// 如果不存在,则创建文件夹
await fs.mkdir(dailyDirectory);
fs.mkdir(`${dailyDirectory}/IMAGES`)
fs.mkdir(`${dailyDirectory}/DATAFILES`)
new Notice(`Folder created: ${dailyDirectory}`);
} else {
new Notice(`Folder already exists: ${dailyDirectory}`);
}
// 检查文件夹是否存在
const exists_work = await fs.exists(workDirectory);
if (!exists_work) {
// 如果不存在,则创建文件夹
await fs.mkdir(workDirectory);
fs.mkdir(`${workDirectory}/IMAGES`)
fs.mkdir(`${workDirectory}/DATAFILES`)
new Notice(`Folder created: ${workDirectory}`);
} else {
new Notice(`Folder already exists: ${workDirectory}`);
}
} catch (error) {
new Notice(`Error: ${error}`);
}
};全局置顶
全局置顶 在新窗口打开当前笔记并全局置顶
module.exports = async (params) => {
// 获取笔记的基本路径
const filePath = app.workspace.getActiveFile().path;
// 获取激活窗口的位置和大小
var activeWindowLeft = activeWindow.screenX;
var activeWindowTop = activeWindow.screenY;
var activeWindowWidth = activeWindow.outerWidth;
var activeWindowHeight = activeWindow.outerHeight;
// 相邻窗口打开
var newWindowLeft = activeWindowLeft + activeWindowWidth + 5;
var newWindowTop = activeWindowTop + 100;
// 设置默认的窗口大小
const newWindowWidth = 500;
const newWindowHeight = 550;
await app.workspace.openPopoutLeaf({ width: newWindowWidth, height: newWindowHeight }).openFile(app.vault.getAbstractFileByPath(filePath));
// 窗口置顶
activeWindow.electronWindow.setAlwaysOnTop(true);
// 控制界面缩放
activeWindow.electronWindow.webContents.zoomFactor = 0.8;
};