Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename PeriodicLog -> PeriodicNotes #36

Merged
merged 1 commit into from
Mar 5, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import { Duration, Interval } from "luxon";
import { describe, expect, it } from "vitest";

import { PeriodicLog } from "../periodic-log";
import { PeriodicNotes } from "../periodic-notes";

describe(PeriodicLog.name, () => {
describe(PeriodicNotes.name, () => {
describe("pre-conditions", () => {
it("should throw when folder is empty", () => {
expect(() => new PeriodicLog("", "yyyy-MM-dd", { days: 1 })).toThrow();
expect(() => new PeriodicNotes("", "yyyy-MM-dd", { days: 1 })).toThrow();
});

it("should throw when date format is empty", () => {
expect(() => new PeriodicLog("/vault", "", { days: 1 })).toThrow();
expect(() => new PeriodicNotes("/vault", "", { days: 1 })).toThrow();
});

it("should throw when interval duration is invalid", () => {
expect(() => new PeriodicLog("/vault", "yyyy-MM-dd", Duration.invalid("!"))).toThrow();
expect(() => new PeriodicNotes("/vault", "yyyy-MM-dd", Duration.invalid("!"))).toThrow();
});

it("should throw when interval offset is invalid", () => {
expect(() => new PeriodicLog("/vault", "yyyy-MM-dd", { days: 1 }, Duration.invalid("!"))).toThrow();
expect(() => new PeriodicNotes("/vault", "yyyy-MM-dd", { days: 1 }, Duration.invalid("!"))).toThrow();
});

it.each([+1, 0, -1])("should not throw when interval offset is %j", (days) => {
expect(() => new PeriodicLog("/vault", "yyyy-MM-dd", { days: 1 }, { days })).not.toThrow();
expect(() => new PeriodicNotes("/vault", "yyyy-MM-dd", { days: 1 }, { days })).not.toThrow();
});

it("should throw when interval duration is 0", () => {
expect(() => new PeriodicLog("/vault", "yyyy-MM-dd", { days: 0 })).toThrow();
expect(() => new PeriodicNotes("/vault", "yyyy-MM-dd", { days: 0 })).toThrow();
});

it.each([+1, -1])("should not throw when interval duration is %j", (days) => {
expect(() => new PeriodicLog("/vault", "yyyy-MM-dd", { days })).not.toThrow();
expect(() => new PeriodicNotes("/vault", "yyyy-MM-dd", { days })).not.toThrow();
});
});

describe('given daily log in folder: "/vault"', () => {
const log = new PeriodicLog("/vault", "yyyy-MM-dd", { days: 1 });
const log = new PeriodicNotes("/vault", "yyyy-MM-dd", { days: 1 });

it.each(["/vault/2023-01-01.md"])("should include %j", (filePath) => {
expect(log.includes(filePath)).toBe(true);
Expand All @@ -59,7 +59,7 @@ describe(PeriodicLog.name, () => {
});

describe('given sprint logs starting every other thursday in folder: "/sprints"', () => {
const log = new PeriodicLog("/sprints", "kkkk-'W'WW", { weeks: 2 }, { days: 3 });
const log = new PeriodicNotes("/sprints", "kkkk-'W'WW", { weeks: 2 }, { days: 3 });

it.each(["/sprints/2023-W37.md"])("should include %j", (filePath) => {
expect(log.includes(filePath)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { parse } from "path";
import { Collection } from "./schema";

/**
* Represents a collection of files, each corresponding to unique {@link Interval} of time, kept inside the same folder.
* Intended to handle Obsidian's built-in "Daily Log" plugin and the more-comprehensive "Periodic log" community plugin.
* @see {@link https://github.com/liamcain/obsidian-periodic-notes}
*
* A {@link Collection} where each file corresponds to a unique {@link Interval} of time. Intended to handle Obsidian's
* built-in "Daily Notes" plugin and the more-comprehensive "Periodic Notes" community plugin. As a consequence, all
* files in the collection must be placed in the same folder.
*
* TODO: Is it worth supporting files organized into different folders?
*/
export class PeriodicLog extends Collection {
/**
* The folder containing all of the notes.
* TODO: Is it worth supporting files organized into different folders?
*/
export class PeriodicNotes extends Collection {
/** The folder containing all of the notes. */
public readonly folder: string;

/**
Expand Down