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

Rough stab at making the default template settings-driven #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidfells
Copy link

@davidfells davidfells commented Apr 29, 2021

This is a quick stab at converting the templating to be dynamic. I was not able to get the project to build locally, so this is completely untested, but the changes appear to be quite simple. Along with other users in the issue thread at #56 , being able to customize my default Day Planner would be a fantastic QOL improvement.

Copy link

@Thracky Thracky left a comment

I hugely appreciate this addition as I felt it was the only major thing missing from the plugin and wanted to give it a whirl so I fixed up the build (failing due to API changes) and was able to test and fix a couple things so I'll outline them all here.

Not directly related to this PR but to get it to build I did the following:
in tsconfig.json :
remove `"inlineSourceMap": true,"

in main.ts:

On line 46 change:

    this.registerEvent(this.app.on("codemirror", this.codeMirror));

to

    this.registerCodeMirror(this.codeMirror);

The API was changed in v0.10.0 in obsidianmd/obsidian-api@2e4ac7c#diff-0eaea5db2513fdc5fe65d534d3591db5b577fe376925187c8a624124632b7466

Also, I feel like it would be nice to specify a template file instead of having to jam markdown into the tiny little config text box. The core Daily notes plugin does this but not sure how specifically. However, I'm pretty happy with the setting for now :)

@@ -61,7 +61,7 @@ export default class DayPlannerFile {
try {
const normalizedFileName = normalizePath(fileName);
if (!await this.vault.adapter.exists(normalizedFileName, false)) {
await this.vault.create(normalizedFileName, DAY_PLANNER_DEFAULT_CONTENT);
await this.vault.create(normalizedFileName, DayPlannerSettings.defaultContent);
Copy link

@Thracky Thracky May 14, 2021

Choose a reason for hiding this comment

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

Needs to be this.settings.defaultContent

@@ -32,7 +32,7 @@ export default class PlannerMarkdown {
const fileContents = await (await this.file.getFileContents(filePath)).split('\n');
const view = this.workspace.activeLeaf.view as MarkdownView;
const currentLine = view.sourceMode.cmEditor.getCursor().line;
const insertResult = [...fileContents.slice(0, currentLine), ...DAY_PLANNER_DEFAULT_CONTENT.split('\n'), ...fileContents.slice(currentLine)];
const insertResult = [...fileContents.slice(0, currentLine), ...DayPlannerSettings.defaultContent.split('\n'), ...fileContents.slice(currentLine)];
Copy link

@Thracky Thracky May 14, 2021

Choose a reason for hiding this comment

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

Also needs to be this.settings.defaultContent

@balint-bg
Copy link

@balint-bg balint-bg commented Jun 17, 2021

Just wanted to say that I'm eagerly waiting for this feature to be merged. I can't comment on the code (I know nothing about JS) but in case a huge +1 was going to help getting this in sooner, then here it is :)
Thanks for the work!!!

@lynchjames
Copy link
Owner

@lynchjames lynchjames commented Jun 19, 2021

I hugely appreciate this addition as I felt it was the only major thing missing from the plugin and wanted to give it a whirl so I fixed up the build (failing due to API changes) and was able to test and fix a couple things so I'll outline them all here.

Not directly related to this PR but to get it to build I did the following:
in tsconfig.json :
remove `"inlineSourceMap": true,"

in main.ts:

On line 46 change:

    this.registerEvent(this.app.on("codemirror", this.codeMirror));

to

    this.registerCodeMirror(this.codeMirror);

The API was changed in v0.10.0 in obsidianmd/obsidian-api@2e4ac7c#diff-0eaea5db2513fdc5fe65d534d3591db5b577fe376925187c8a624124632b7466

Also, I feel like it would be nice to specify a template file instead of having to jam markdown into the tiny little config text box. The core Daily notes plugin does this but not sure how specifically. However, I'm pretty happy with the setting for now :)

@Thracky the inlineSourceMap setting has now been removed from tsconfig.json.

I decided to replace the CodeMirror event with a file modified event as the Day Planner does not need to be updated on every single change in the CodeMirror editor, modifications to the file are enough to keep the gantt chart, status bar and timeline updated.

@lynchjames
Copy link
Owner

@lynchjames lynchjames commented Jun 19, 2021

@davidfells could you rebase from lynchjames:main to get the latest updates and make the changes @Thracky has suggested?

@ebdavison
Copy link

@ebdavison ebdavison commented Feb 7, 2022

Would love to see this merged as well as this would be a big benefit over hacking the JS code to change the daily template.

@gkiar
Copy link

@gkiar gkiar commented Feb 8, 2022

👍 would also love this feature

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

Successfully merging this pull request may close these issues.

None yet

6 participants