-
Notifications
You must be signed in to change notification settings - Fork 185
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
base: master
Are you sure you want to change the base?
Conversation
6dd4a06
to
65b4771
Compare
There was a problem hiding this 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.
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( |
There was a problem hiding this comment.
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.
/**
* 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;
GMT-0400
)NOTE: The whitespace changes are from prettier