summaryrefslogtreecommitdiffstats
path: root/ui/new_article_dialog.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-03 10:40:54 +0200
committerDanilo M. <danix@danix.xyz>2026-05-03 10:40:54 +0200
commit5ac2f470c18a9eda17c1f2f8489c07e2eed2cd04 (patch)
tree326217431959ee7de3587b541503102702cfe009 /ui/new_article_dialog.py
parentd4e151f6782dc7a66313eb92bf6e05fa2d343823 (diff)
downloadpublisher-5ac2f470c18a9eda17c1f2f8489c07e2eed2cd04.tar.gz
publisher-5ac2f470c18a9eda17c1f2f8489c07e2eed2cd04.zip
feat: new article stub creation with Typora open
Diffstat (limited to 'ui/new_article_dialog.py')
-rw-r--r--ui/new_article_dialog.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/ui/new_article_dialog.py b/ui/new_article_dialog.py
new file mode 100644
index 0000000..0e0b4f5
--- /dev/null
+++ b/ui/new_article_dialog.py
@@ -0,0 +1,93 @@
+from __future__ import annotations
+from datetime import date
+from pathlib import Path
+from PyQt6.QtWidgets import (
+ QDialog, QVBoxLayout, QFormLayout, QHBoxLayout,
+ QLineEdit, QComboBox, QLabel, QPushButton, QMessageBox,
+)
+from core.models import ARTICLE_TYPES
+
+STUB_TEMPLATE = """\
++++
+title = "{title}"
+date = {date}
+type = "{type}"
+draft = true
+excerpt = ""
+tags = []
+categories = []
++++
+
+TODO: scrivi il contenuto qui.
+"""
+
+class NewArticleDialog(QDialog):
+ def __init__(self, blog_root: Path, parent=None):
+ super().__init__(parent)
+ self.setWindowTitle("Nuovo articolo")
+ self.setMinimumWidth(400)
+ self._blog_root = blog_root
+ self._created_path: Path | None = None
+ self._build_ui()
+
+ @property
+ def created_path(self) -> Path | None:
+ return self._created_path
+
+ def _build_ui(self):
+ layout = QVBoxLayout(self)
+ form = QFormLayout()
+
+ self._slug = QLineEdit()
+ self._slug.setPlaceholderText("mio-articolo-2026")
+ form.addRow("Slug:", self._slug)
+
+ self._title = QLineEdit()
+ self._title.setPlaceholderText("Il mio articolo")
+ form.addRow("Titolo:", self._title)
+
+ self._lang = QComboBox()
+ self._lang.addItems(["it", "en"])
+ form.addRow("Lingua:", self._lang)
+
+ self._type = QComboBox()
+ self._type.addItems(ARTICLE_TYPES)
+ form.addRow("Tipo:", self._type)
+
+ layout.addLayout(form)
+
+ btns = QHBoxLayout()
+ create_btn = QPushButton("Crea")
+ create_btn.clicked.connect(self._create)
+ cancel_btn = QPushButton("Annulla")
+ cancel_btn.clicked.connect(self.reject)
+ btns.addStretch()
+ btns.addWidget(cancel_btn)
+ btns.addWidget(create_btn)
+ layout.addLayout(btns)
+
+ def _create(self):
+ slug = self._slug.text().strip()
+ title = self._title.text().strip()
+ lang = self._lang.currentText()
+ article_type = self._type.currentText()
+
+ if not slug or not title:
+ QMessageBox.warning(self, "Errore", "Slug e titolo sono obbligatori.")
+ return
+
+ target = self._blog_root / "content" / lang / "articles" / slug
+ if target.exists():
+ QMessageBox.warning(self, "Errore", f"Esiste già: {target}")
+ return
+
+ target.mkdir(parents=True)
+ index_md = target / "index.md"
+ index_md.write_text(STUB_TEMPLATE.format(
+ title=title,
+ date=date.today().isoformat(),
+ type=article_type,
+ ), encoding="utf-8")
+
+ self._created_path = index_md
+ self.accept()