Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/weekly-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ would create a page name of:

For format, check out [this page](https://date-fns.org/v2.21.1/docs/format) for the syntax on what each symbol means.

## ISO Week Format

Weekly Notes supports ISO week-numbering formats. Use the following tokens for ISO week-based naming:

| Token | Description | Example |
|-------|-------------|---------|
| `I` | ISO week number (1-53) | `1`, `52` |
| `II` | ISO week number, 2 digits | `01`, `52` |
| `R` | ISO week-numbering year | `2024` |
| `RRRR` | ISO week-numbering year, 4 digits | `2024` |

**Examples:**

```plain text
{monday:RRRR}-W{monday:II}
```
would create: `[[2024-W52]]`

```plain text
Week {monday:I} {monday:RRRR}
```
would create: `[[Week 52 2024]]`

**Note:** ISO weeks always start on Monday. ISO week 1 is the week containing the first Thursday of the year, so dates in late December may belong to week 1 of the following year. Use `R`/`RRRR` (ISO week-numbering year) instead of `yyyy` (calendar year) when using ISO week numbers to ensure consistency.

# Auto Tagging

When a new weekly page is created, the weekly page will be tagged in all of the daily pages that are part of the week. The tag will be added as the top block on the page. This could be toggled on and off in the `roam/js/weekly-notes` page.
Expand Down
92 changes: 47 additions & 45 deletions src/features/weekly-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,56 +240,15 @@ export const toggleFeature = (
};

const hashListener = (newUrl: string) => {
// Clean up navigation buttons when navigating away
document.getElementById("roamjs-weekly-mode-nav")?.remove?.();

// Clear format cache when visiting config page
const urlUid = newUrl.match(/\/page\/(.*)$/)?.[1];
if (urlUid) {
const title = getPageTitleByPageUid(urlUid);
if (title === CONFIG) {
formatCache.current = "";
return;
}
const { dateArray, valid, formats } = getFormatDateData(title);
if (valid) {
const formattedDateArray = dateArray
.map((d, i) => ({
cur: dateFnsFormat(d, formats[i]),
prev: dateFnsFormat(subWeeks(d, 1), formats[i]),
next: dateFnsFormat(addWeeks(d, 1), formats[i]),
}))
.filter(
(info): info is { cur: string; prev: string; next: string } =>
!!info.cur && !!info.prev && !!info.next
);
const prevTitle = formattedDateArray.reduce(
(acc, info) => acc.replace(info.cur, info.prev),
title
);
const nextTitle = formattedDateArray.reduce(
(acc, info) => acc.replace(info.cur, info.next),
title
);
setTimeout(() => {
const header = document.querySelector(
".roam-article h1.rm-title-display"
) as HTMLHeadingElement;
const headerContainer = header.parentElement;
const buttonContainer = document.createElement("div");
buttonContainer.style.display = "flex";
buttonContainer.style.justifyContent = "space-between";
buttonContainer.style.marginBottom = "32px";
buttonContainer.id = "roamjs-weekly-mode-nav";
headerContainer?.appendChild(buttonContainer);

const makeButton = (pagename: string, label: string) => {
const button = document.createElement("button");
button.className = "bp3-button";
button.onclick = () => navigateToPage(pagename);
button.innerText = label;
buttonContainer.appendChild(button);
};
makeButton(prevTitle, "Last Week");
makeButton(nextTitle, "Next Week");
});
}
}
};
Expand All @@ -312,8 +271,9 @@ export const toggleFeature = (
className: "rm-title-display",
callback: (header: HTMLElement) => {
const title = getPageTitleValueByHtmlElement(header);
const { valid } = getFormatDateData(title);
const { dateArray, valid, formats } = getFormatDateData(title);
if (valid) {
// Prevent title editing
header.onmousedown = (e) => {
if (!e.shiftKey) {
renderToast({
Expand All @@ -323,6 +283,48 @@ export const toggleFeature = (
e.stopPropagation();
}
};

// Remove any existing navigation buttons
document.getElementById("roamjs-weekly-mode-nav")?.remove?.();

// Calculate previous and next week titles
const formattedDateArray = dateArray
.map((d, i) => ({
cur: dateFnsFormat(d, formats[i]),
prev: dateFnsFormat(subWeeks(d, 1), formats[i]),
next: dateFnsFormat(addWeeks(d, 1), formats[i]),
}))
.filter(
(info): info is { cur: string; prev: string; next: string } =>
!!info.cur && !!info.prev && !!info.next
);
const prevTitle = formattedDateArray.reduce(
(acc, info) => acc.replace(info.cur, info.prev),
title
);
const nextTitle = formattedDateArray.reduce(
(acc, info) => acc.replace(info.cur, info.next),
title
);

// Create navigation buttons below the header
const headerContainer = header.parentElement;
const buttonContainer = document.createElement("div");
buttonContainer.style.display = "flex";
buttonContainer.style.justifyContent = "space-between";
buttonContainer.style.marginBottom = "32px";
buttonContainer.id = "roamjs-weekly-mode-nav";
headerContainer?.appendChild(buttonContainer);

const makeButton = (pagename: string, label: string) => {
const button = document.createElement("button");
button.className = "bp3-button";
button.onclick = () => navigateToPage(pagename);
button.innerText = label;
buttonContainer.appendChild(button);
};
makeButton(prevTitle, "Last Week");
makeButton(nextTitle, "Next Week");
}
},
});
Expand Down