-
-
Notifications
You must be signed in to change notification settings - Fork 154
Importing single HTML file: prefer html title over filename #598
Importing single HTML file: prefer html title over filename #598
Conversation
When importing HTML files, extract and use the title from the <title> tag if available, falling back to the filename only when no title tag is found. This improves handling of titles with special characters that can't be represented in filenames.
Gotta say, code looks decent even from an LLM lol. |
"TSError: ⨯ Unable to compile TypeScript: spec/services/import/single.spec.ts:137:25 - error TS2339: Property 'content' does not exist on type 'BNote'."
"$ npx tsx spec/services/import/single.spec.ts /home/mhw/dev/tnext/spec/services/import/single.spec.ts:6 describe('HTML Import', () => { ^ ReferenceError: describe is not defined at <anonymous> (/home/mhw/dev/tnext/spec/services/import/single.spec.ts:6:1) Node.js v18.17.1"
claude sez: "I see the issue. The tests are failing because we need to set up the CLS (Continuation Local Storage) context that Trilium uses for transactions. Let me check how this is handled in other tests: I've updated the test file to: I've updated the test file to: Use an in-memory database for testing Set up necessary database tables in beforeEach Wrap all database operations in cls.init() and sql.transactional() Handle async operations properly
claude: I've updated the test file to: Add the entity_changes table with all required fields Add missing fields to the notes table (isDeleted) Add missing fields when inserting the parent note
I set up an Ubuntu WSL container to run npm and tests within on this branch. The last 5 commits are me basically letting Claude do whatever it wanted with prompts of the last error message. Things really started to go off the rails after importSinglefile (14d7e3e) and I suspect rest of the commits are not worth much! A root cause of confusion is me not knowing how to run tests in node anyway. For what it's worth, these are the test commands attempted: npx jasmine spec/services/import/single.spec.ts
npx tsx spec/services/import/single.spec.ts
npx ts-node --esm spec/services/import/single.spec.ts
npx ts-node --esm --compilerOptions '{"target":"es2022"}' spec/services/import/single.spec.ts
NODE_OPTIONS="--loader tsx" jasmine spec/services/import/single.spec.ts |
@maphew , I've removed the test for now although it seemed very promising just because we don't have a well defined test suite mechanism unfortunately. Either way, when testing the PR using an HTML file generated by Trilium I've noticed it was not working, prefering the file name. The reason is that the I've also fixed two more issues that were unrelated to the PR itself:
|
thank you @eliandoran! |
Prefer HTML title tag over filename during import
When importing HTML files, extract and use the title from the <title> tag if available, falling back to the filename only when no title tag is found.
Primary motivaton is handling of titles with special characters that can't be represented in filenames.
I'm inexperienced with javascript and typescript. I relied on Claude Sonnet 3.5 via Codeium to build this. The included test hasn't been run as I've been unsuccessful so far at putting together a complete development environment on Windows.