Skip to content

feat(editor): sync changes to local Markdown files - #25

Open
RerankerGuo wants to merge 1 commit into
acmenlei:masterfrom
RerankerGuo:feat/issue-24-local-markdown-sync
Open

feat(editor): sync changes to local Markdown files#25
RerankerGuo wants to merge 1 commit into
acmenlei:masterfrom
RerankerGuo:feat/issue-24-local-markdown-sync

Conversation

@RerankerGuo

Copy link
Copy Markdown

Summary

Closes #24.

CodeCV currently keeps editor changes in localStorage, so browser content
can diverge from a local Markdown source file. This PR adds an opt-in local
file binding that writes later editor changes back to a user-approved .md
file.

Changes

  • add a Sync local MD action to the editor header;
  • request a Markdown file through the File System Access API;
  • require an explicit choice when the file and editor content differ;
  • debounce and serialize later writes to the active file handle;
  • abort failed write streams and prevent pending writes from crossing file
    bindings;
  • keep the existing import/export workflow for unsupported browsers.

The browser still cannot discover or write arbitrary local paths. Users must
select a file, and the binding lasts for the current page session.

Verification

  • npx prettier --check src/views/editor/hook.ts src/views/editor/editor.vue src/views/editor/components/header/header.vue
  • npx eslint src/views/editor/hook.ts src/views/editor/editor.vue src/views/editor/components/header/header.vue
  • npm run build
  • browser regression with a controlled File System Access handle:
    • editor content overwrote the selected file only after confirmation;
    • selecting the local-file version replaced the editor and preview;
    • a later editor change produced one debounced write and one close;
    • editor, preview, and written content contained the same marker;
    • the preview rendered one page.

The current master branch has the unrelated duplicate-route-name startup
failure covered by #22. Browser verification applied those three route
renames temporarily; they are not included in this PR.

Compatibility

  • Chromium-based browsers in a secure context (including localhost) can use
    local synchronization.
  • Other browsers receive a warning and can continue using Import MD / Export
    MD.

Closes acmenlei#24. Add opt-in file linking, conflict resolution, debounced write-through, and compatibility fallback.
@RerankerGuo

Copy link
Copy Markdown
Author

@acmenlei 您好,抱歉打扰。

我们在本地使用 CodeCV 时发现,浏览器编辑后的 Markdown 只保存在 localStorage,无法与本地 .md 文件同步,容易造成两份内容分叉,因此提交了 #24 和这个最小范围的 PR。

本 PR 仅修改编辑器相关的 3 个文件,新增用户主动授权后的本地文件同步,并保留原有导入/导出作为兼容回退;已通过 Prettier、ESLint、npm run build 以及浏览器双向同步回归。您方便时烦请看一下这个方向是否符合项目预期;如需调整,我会及时跟进。感谢您维护 CodeCV。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: sync editor changes to a local Markdown file

1 participant