madeindjs / vscode-notable

VSCode plugin to take Markdown notes following Notable format.
MIT License
4 stars 1 forks source link

Add functionality to add FrontMatter to existing file, when there is none #7

Closed frudolph77 closed 2 years ago

frudolph77 commented 2 years ago

Due to this Bug #5 and for the reason, that I have md-files without FrontMatter I've added a function to add FrontMatter to the file.

The FrontMatter will only be added it there is no FrontMatter in the file.

As created timestamp the current time is used, I know that's not correct, but I didn't find a way to obtain the file creation date in VS Code.

As an additional option it could be possible to merge the existing FrontMatter with the Notable FrontMatter, but that isn't implemented yet.

The fix #6 should be merged first.

madeindjs commented 2 years ago

Could you correct conflicts ? I'll merge just after

frudolph77 commented 2 years ago

Should be done

Could you please wait with the merge. I'll add at least a message that there is already a FrontMatter in the file, when there is one.

The merge feature will take a while, and I'm currently not sure if it is useful.

madeindjs commented 2 years ago

OK fine, let me know once this PR is ready

frudolph77 commented 2 years ago

It is possible to set the creation date in the FrontMatter to the creation date of the file.

const uri = editor.document.uri
const stats = await workspace.fs.stat(uri)
const ctime = stats.ctime

But as some/most file system do not store the creation date of file, this date will be the last modified date.

The ext4 file system does store the creation date of a file since kernel 4.11, but at least till Ubuntu 20.10 there are no system tools available that are able to read the creation time. I cannot check how MacOS or Windows behave.

Therefore I also could not verify, if VS Code is able to read the creation time, if the file system stores it.

What is your opinion? Are you fine with that limitation, or should we stay on current date, as now.

madeindjs commented 2 years ago

I was not aware of this EXT4 limitation but I'm fine with it. As it's a new feature this will not change the current behavior. So feel free to implement what you prefer

frudolph77 commented 2 years ago

I was not aware of this EXT4 limitation but I'm fine with it.

Me neither. I just wondered yesterday when playing around with FileSystem.stat why, the ctime date is far away from the date I've created the file. After googling a while I found a question on StackExchange where this has been mentioned.

As for now, I'm finished with the feature.

madeindjs commented 2 years ago

Published on https://github.com/madeindjs/vscode-notable/releases/tag/v0.3.0, thank for your contribution :heart: