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

fix: Sort scheduling info and replace values individually #1107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thisispvb
Copy link

@thisispvb thisispvb commented Oct 5, 2024

  • fix: Sort scheduling info and replace values individually (backwards compatible and resolves [BUG] YAML duplication due re-ordering #613)
  • fix: Ensure consistent timezone when running tests (otherwise failed locally for me in GMT-0400)

NOTE: The whitespace changes are from prettier

@thisispvb thisispvb changed the title fix: Sort scheduling info and replace values individually (resolves #613) fix: Sort scheduling info and replace values individually (fixes #613) Oct 5, 2024
@thisispvb thisispvb changed the title fix: Sort scheduling info and replace values individually (fixes #613) fix: Sort scheduling info and replace values individually Oct 5, 2024
Copy link
Owner

@st3v3nmw st3v3nmw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. Please check the comment.

Comment on lines +59 to 76
const hasSchedulingDueString = SCHEDULING_INFO_DUE_REGEX.test(fileText);
const hasSchedulingEase = SCHEDULING_INFO_EASE_REGEX.test(fileText);
const hasSchedulingInterval = SCHEDULING_INFO_INTERVAL_REGEX.test(fileText);
if (hasSchedulingDueString && hasSchedulingEase && hasSchedulingInterval) {
const schedulingDueString = SCHEDULING_INFO_DUE_REGEX.exec(fileText);
fileText = fileText.replace(
SCHEDULING_INFO_DUE_REGEX,
`${schedulingDueString[1]}${dueString}${schedulingDueString[3]}`,
);

const schedulingEase = SCHEDULING_INFO_EASE_REGEX.exec(fileText);
fileText = fileText.replace(
SCHEDULING_INFO_EASE_REGEX,
`${schedulingEase[1]}${ease}${schedulingEase[3]}`,
);

const schedulingInterval = SCHEDULING_INFO_INTERVAL_REGEX.exec(fileText);
fileText = fileText.replace(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just checked the Obsidian API and it's now possible to modify the FrontMatter using the native processFrontMatter function. That might be the better approach.

https://github.com/obsidianmd/obsidian-api/blob/23947b58d372ea02225324308e31d36b4aa95869/obsidian.d.ts#L1551

/**
* Atomically read, modify, and save the frontmatter of a note.
* The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result.
*
* Remember to handle errors thrown by this method.
*
* @param file - the file to be modified. Must be a Markdown file.
* @param fn - a callback function which mutates the frontmatter object synchronously.
* @param options - write options.
* @throws YAMLParseError if the YAML parsing fails
* @throws any errors that your callback function throws
* @example
* ts * app.fileManager.processFrontMatter(file, (frontmatter) => { * frontmatter['key1'] = value; * delete frontmatter['key2']; * }); *
* @public
*/
processFrontMatter(file: TFile, fn: (frontmatter: any) => void, options?: DataWriteOptions): Promise;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] YAML duplication due re-ordering
2 participants