140 lines
2.9 KiB
Markdown
140 lines
2.9 KiB
Markdown
---
|
|
date: <% tp.date.now("YYYY-MM-DD") %>
|
|
status: proposed
|
|
owner: Amadou
|
|
---
|
|
|
|
<%*
|
|
const date = tp.date.now("YYYY-MM-DD");
|
|
const year = tp.date.now("YYYY");
|
|
const month = tp.date.now("MM");
|
|
|
|
// --------------------------------------------------
|
|
// 1. Ask for decision title
|
|
// --------------------------------------------------
|
|
|
|
const title = await tp.system.prompt("Decision title");
|
|
|
|
if (!title) {
|
|
new Notice("Decision cancelled: no title entered.");
|
|
return;
|
|
}
|
|
|
|
const safeTitle = title
|
|
.replace(/[\\/:*?"<>|]/g, "-")
|
|
.trim();
|
|
|
|
// --------------------------------------------------
|
|
// 2. Find available projects for the current year
|
|
// --------------------------------------------------
|
|
|
|
const projectsFolder = `20 Work/Projects/${year}`;
|
|
|
|
const projectFiles = app.vault
|
|
.getMarkdownFiles()
|
|
.filter(file => file.parent?.path === projectsFolder)
|
|
.sort((a, b) => a.basename.localeCompare(b.basename));
|
|
|
|
// First option allows a decision with no project
|
|
const projectLabels = [
|
|
"— No project —",
|
|
...projectFiles.map(file => file.basename)
|
|
];
|
|
|
|
const projectValues = [
|
|
null,
|
|
...projectFiles
|
|
];
|
|
|
|
// --------------------------------------------------
|
|
// 3. Ask which project this decision belongs to
|
|
// --------------------------------------------------
|
|
|
|
const selectedProject = await tp.system.suggester(
|
|
projectLabels,
|
|
projectValues,
|
|
false,
|
|
"Related project"
|
|
);
|
|
|
|
// Cancelling the modal cancels note creation
|
|
if (selectedProject === undefined) {
|
|
new Notice("Decision cancelled.");
|
|
return;
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// 4. Create Decisions/YYYY/MM folder
|
|
// --------------------------------------------------
|
|
|
|
const baseFolder = "20 Work/Decisions";
|
|
const yearFolder = `${baseFolder}/${year}`;
|
|
const monthFolder = `${yearFolder}/${month}`;
|
|
|
|
if (!app.vault.getAbstractFileByPath(yearFolder)) {
|
|
await app.vault.createFolder(yearFolder);
|
|
}
|
|
|
|
if (!app.vault.getAbstractFileByPath(monthFolder)) {
|
|
await app.vault.createFolder(monthFolder);
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// 5. Build filename
|
|
// --------------------------------------------------
|
|
|
|
let filename;
|
|
|
|
if (selectedProject) {
|
|
const safeProject = selectedProject.basename
|
|
.replace(/[\\/:*?"<>|]/g, "-")
|
|
.trim();
|
|
|
|
filename = `${date} - ${safeProject} - ${safeTitle}`;
|
|
} else {
|
|
filename = `${date} - ${safeTitle}`;
|
|
}
|
|
|
|
// --------------------------------------------------
|
|
// 6. Move + rename note
|
|
// --------------------------------------------------
|
|
|
|
await tp.file.move(
|
|
`${monthFolder}/${filename}`
|
|
);
|
|
|
|
// Make project available later in the template
|
|
const projectLink = selectedProject
|
|
? `[[${selectedProject.basename}]]`
|
|
: "";
|
|
-%>
|
|
|
|
> 🟡 **Proposed** · 🟢 **Decided** · 🔴 **Rejected** · ⚫ **Superseded**
|
|
|
|
## Context
|
|
|
|
<% tp.file.cursor() %>
|
|
|
|
## Options Considered *(optional)*
|
|
|
|
- **Option 1**
|
|
- Pros:
|
|
- Cons:
|
|
|
|
- **Option 2**
|
|
- Pros:
|
|
- Cons:
|
|
|
|
## Decision
|
|
|
|
## Why
|
|
|
|
-
|
|
|
|
## Consequences
|
|
|
|
-
|
|
|
|
## Related
|
|
|
|
- [[]] |