obsidian-importer
obsidian-importer copied to clipboard
[OneNote] Import fails on empty titles
Any pages without titles give ENOENT error.
Failed: "<contents of note>" because Error: ENOENT: no such file or directory, open 'C:\Users\<user>\Obsidian Vault\OneNote\Journ...'
This is a show stopper for me. I'm going to try and see about modifying the plugin
I believe a fix to https://github.com/obsidianmd/obsidian-importer/blob/e2ad99f78a282bcefe01d3c5b287682a20c624aa/src/formats/onenote.ts#L255 is needed.
The conditional
if (!page.title) page.title = Untitled-${moment().format('YYYYMMDDHHmmss')};
May need to be replaced with something more like
if (!page.title || page.title.trim() === "" || page.title.trim() === "Untitled Page") {...
It seems "Untitled Page" is returning as the page title when there is no page title.
I patched the plugin with the above code and it appears to fix the issue. A larger test is stuck due to another issue which is the importer doesn't respect HTTP 429 (too many requests) and instead keeps hammering the API and results in
Failed: ... because TypeError: Cannot read properties of undefined (reading 'split') documented in #225
I also noticed a third bug while testing (it appears trailing spaces aren't removed from the title).
This is the code I'm using (not production ready since the filename sanitation was supposed to happen elsewhere)
for (let p = 0; p < c.length; p++) {
// Existing minified code
let m = c[p];
let title = m.title;
// Define invalid file characters
const invalidChars = /[<>:"/\\|?*\x00-\x1F]/g;
// Trim invalid characters and whitespace from the title
title = title.replace(invalidChars, '').trim();
// Limit page title length
if (title.length > this.maxFileNameLength) {
title = title.slice(0, this.maxFileNameLength);
}
// Ensure the title doesn't end with a space or a period
title = title.replace(/[. ]+$/, '');
if (!title || title.trim() === "" || title.trim() === "Untitled Page")
title = `Untitled-${(0,Ee.moment)().format("YYYYMMDDHHmmss")}`;
m.title = title;