refactor: restructure mytoolkit with new subcommands and md-to-pdf improvements

- Add new subcommands: convert, preflight, server, templates, webpage
- Migrate config from bin/config.json to ~/.config/mytoolkit
- Fix expand_bookmarks to modify writer objects instead of reader
- Improve md_to_pdf with CJK bookmark support
- Update README and project metadata
This commit is contained in:
Zhengshou Lai
2026-05-04 17:19:32 +08:00
parent 38328c28d0
commit 3e4cf618a8
20 changed files with 1846 additions and 214 deletions
+14 -3
View File
@@ -3,23 +3,34 @@
import json
from pathlib import Path
CONFIG_PATH = Path.home() / ".config" / "mytoolkit" / "env.json"
_LEGACY_PATH = Path(__file__).parent / "config.json"
class Config:
"""Simple config manager for environment variables."""
def __init__(self):
self._config_path = Path(__file__).parent / "config.json"
self._config_path = CONFIG_PATH
self._migrate_legacy()
self._data = self._load()
def _migrate_legacy(self) -> None:
"""One-shot move of legacy bin/config.json into the user config dir."""
if _LEGACY_PATH.exists() and not self._config_path.exists():
self._config_path.parent.mkdir(parents=True, exist_ok=True)
_LEGACY_PATH.rename(self._config_path)
def _load(self) -> dict:
if self._config_path.exists():
with open(self._config_path) as f:
with open(self._config_path, encoding="utf-8") as f:
return json.load(f)
return {"vars": {}}
def save(self):
"""Save config to file."""
with open(self._config_path, "w") as f:
self._config_path.parent.mkdir(parents=True, exist_ok=True)
with open(self._config_path, "w", encoding="utf-8") as f:
json.dump(self._data, f, indent=2, ensure_ascii=False)
f.write("\n")