Closed GollyTicker closed 2 years ago
@nybbles Could we merge this?
@GollyTicker apologies for the long response time. Did you test what happens when there's already a file with the shortened name?
e.g. currently if there's already a somefile
and we try to save another somefile
, it will be saved as somefile 2
instead.
The relevant logic that adds a version number is here: https://github.com/nybbles/obsidian-pocket/blob/d059632c337399b93391219faf8cc3ac9c1882ec/src/ItemNote.ts#L244-L256.
The number of duplicates goes up to 1000, so with the space separator that's five extra characters. I think the simplest solution would be to just do 255 - 5.
Actually hold on, I see that you're doing 255 - 15 already - where does 15 come from?
Oh yes and thank you for putting up a pull request for the issue you raised. It's much appreciated.
I didn't test specifically for this scenario, but because we still leave enough characters (255-15) for line ending and the de-duplication number, I think this should be fine.
I'd did test the logic with smaller and larger titles.
Where does the value for 15 come from? Do you think it would be reasonable to set it to 5?
This truncation should also only be happening on Windows, since that's the only platform that has this requirement on filenames.
Actually this happens on Mac too
looks like 255 characters for filenames is a pretty common limit across various filesystems, so I think it's okay to apply this limit to all supported Obsidian platforms.
I've updated the PR @nybbles
Thanks for your fix. I'll cut a release later today.
FYI this fix is released and installable now. Sorry about the delay.
I had issues with long filenames generated by the obsidian-pocket plugin, when the original Title/URL from Pocket was too long. This can happen for certain Reddit posts with long titles.
I added a small fix which truncates filenames to the length
255 - 15
. I have manually edited the change into my localmain.js
and tested, that it works as expected.I think it is reasonable to expect, that the entire title does not need to be in the filename - especially when it's so long. Alternatively, we could add an option to toggle this sanitization, if necessary.
What do you think? Could we merge this? @nybbles