mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
PR: Refactor: Extract page conversion logic to dedicated service
Description
This Pull Request refactors the Page model by extracting the complex HTML <-> Markdown conversion logic into a dedicated service (PageConverter).
Changes
- Created server/services/page-converter.js: This new service handles all DOM manipulation (Cheerio) and Markdown generation (Turndown).
- Modified server/models/pages.js: Removed dependencies on cheerio, turndown, and turndown-plugin-gfm. The convertPage method now delegates the conversion task to the new service.
Benefits:
- Code Cleanup: The
pages.jsfile sheds approximately 80 lines of conversion logic that are unrelated to data persistence (Model responsibility). - Import Performance: Since
pages.jsis a frequently loaded model, removing heavy dependencies likecheerioandturndownmakes its initial load time lighter and more efficient. - Maintainability: Future changes to how Markdown/HTML is generated/converted will only require modifying
page-converter.js, isolating the logic from the core database model.
File Changes
- [NEW] server/services/page-converter.js
- [MODIFY] server/models/pages.js