mirror of
https://github.com/docmarionum1/obsidian-pinned-daily-notes.git
synced 2026-07-22 05:41:59 +00:00
cleanup
This commit is contained in:
parent
e598ca2193
commit
04addb6786
5 changed files with 5 additions and 127 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,6 +4,7 @@ node_modules/
|
|||
# Build output
|
||||
*.js.map
|
||||
data.json
|
||||
main.js
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
|
|
|
|||
123
main.js
123
main.js
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
*/
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// main.ts
|
||||
var main_exports = {};
|
||||
__export(main_exports, {
|
||||
default: () => PinDailyNotePlugin
|
||||
});
|
||||
module.exports = __toCommonJS(main_exports);
|
||||
var import_obsidian = require("obsidian");
|
||||
var PinDailyNotePlugin = class extends import_obsidian.Plugin {
|
||||
constructor(app, manifest) {
|
||||
super(app, manifest);
|
||||
this.obsidianApp = app;
|
||||
}
|
||||
async onload() {
|
||||
const handleDailyNote = async () => {
|
||||
const todayPath = this.getTodayNotePath();
|
||||
if (!todayPath)
|
||||
return;
|
||||
const leaves = this.obsidianApp.workspace.getLeavesOfType("markdown");
|
||||
let leaf = leaves.find((leaf2) => {
|
||||
var _a;
|
||||
const obsLeaf = leaf2;
|
||||
const view = obsLeaf.view;
|
||||
return obsLeaf.pinned && this.isDailyNotePath((_a = view == null ? void 0 : view.file) == null ? void 0 : _a.path);
|
||||
});
|
||||
if (!leaf) {
|
||||
leaf = this.obsidianApp.workspace.getLeaf("tab");
|
||||
leaf.setPinned(true);
|
||||
}
|
||||
this.obsidianApp.workspace.setActiveLeaf(leaf, { focus: true });
|
||||
let todayFile = this.obsidianApp.vault.getAbstractFileByPath(todayPath);
|
||||
if (!(todayFile instanceof import_obsidian.TFile)) {
|
||||
const dailyNotesCommand = this.obsidianApp.commands.commands["daily-notes"];
|
||||
if (dailyNotesCommand) {
|
||||
await dailyNotesCommand.callback();
|
||||
const newLeaf = this.obsidianApp.workspace.getMostRecentLeaf();
|
||||
if (newLeaf && newLeaf !== leaf) {
|
||||
newLeaf.detach();
|
||||
}
|
||||
todayFile = this.obsidianApp.vault.getAbstractFileByPath(todayPath);
|
||||
}
|
||||
}
|
||||
if (todayFile instanceof import_obsidian.TFile) {
|
||||
await leaf.openFile(todayFile);
|
||||
this.obsidianApp.workspace.setActiveLeaf(leaf, { focus: true });
|
||||
}
|
||||
};
|
||||
this.addRibbonIcon("calendar-plus", "Open today's daily note (Pinned)", () => {
|
||||
handleDailyNote();
|
||||
});
|
||||
this.addCommand({
|
||||
id: "open-todays-daily-note-pinned",
|
||||
name: "Open today's daily note",
|
||||
callback: () => handleDailyNote()
|
||||
});
|
||||
}
|
||||
getTodayNotePath() {
|
||||
var _a, _b, _c;
|
||||
const dailyNotesPlugin = this.obsidianApp.internalPlugins.plugins["daily-notes"];
|
||||
if (!(dailyNotesPlugin == null ? void 0 : dailyNotesPlugin.enabled))
|
||||
return null;
|
||||
try {
|
||||
const settings = (_a = dailyNotesPlugin.instance) == null ? void 0 : _a.options;
|
||||
if (!settings)
|
||||
return null;
|
||||
const folder = ((_b = settings.folder) == null ? void 0 : _b.trim().replace(/\/$/, "")) || "";
|
||||
const format = ((_c = settings.format) == null ? void 0 : _c.trim()) || "YYYY-MM-DD";
|
||||
const date = window.moment();
|
||||
let filename = date.format(format);
|
||||
if (format.includes("/")) {
|
||||
const formattedPath = folder ? `${folder}/${filename}` : filename;
|
||||
return formattedPath + ".md";
|
||||
} else {
|
||||
const path = folder ? `${folder}/${filename}` : filename;
|
||||
return path + ".md";
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error generating daily note path:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
isDailyNotePath(path) {
|
||||
var _a, _b, _c;
|
||||
if (!path)
|
||||
return false;
|
||||
const dailyNotesPlugin = this.obsidianApp.internalPlugins.plugins["daily-notes"];
|
||||
if (!(dailyNotesPlugin == null ? void 0 : dailyNotesPlugin.enabled))
|
||||
return false;
|
||||
try {
|
||||
const settings = (_a = dailyNotesPlugin.instance) == null ? void 0 : _a.options;
|
||||
if (!settings)
|
||||
return false;
|
||||
const folder = ((_b = settings.folder) == null ? void 0 : _b.trim().replace(/\/$/, "")) || "";
|
||||
if (folder && !path.startsWith(folder))
|
||||
return false;
|
||||
const filename = path.slice(folder ? folder.length + 1 : 0, -3);
|
||||
return window.moment(filename, ((_c = settings.format) == null ? void 0 : _c.trim()) || "YYYY-MM-DD", true).isValid();
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
2
main.ts
2
main.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { App, Plugin, TFile, TAbstractFile, WorkspaceLeaf, View } from 'obsidian';
|
||||
import { App, Plugin, TFile, WorkspaceLeaf, View } from 'obsidian';
|
||||
import type moment from 'moment';
|
||||
|
||||
declare global {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-pinned-daily-notes",
|
||||
"id": "pinned-daily-notes",
|
||||
"name": "Pinned Daily Notes",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"minAppVersion": "1.8.9",
|
||||
"description": "Dynamically update a pinned tab with today's daily note",
|
||||
"author": "Jeremy Neiman",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-pinned-daily-notes",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Automatically pins today's daily note to a tab and updates it when opening new daily notes",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue