aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2026-06-07 19:19:16 +0200
committeruser@node5.net <user@node5.net>2026-06-07 19:19:16 +0200
commitee15f9fba18f6ab1180217f9bf19288f145b83c3 (patch)
tree5e733f7981a1cd04e50f0ddbb89d64bb339d6086 /src
parentd4c5687ccdcc899db177bf240b6da944b068c566 (diff)
clone articles if they don't exist
Diffstat (limited to 'src')
-rw-r--r--src/blog_node5_net.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py
index da5b470..5db8d7a 100644
--- a/src/blog_node5_net.py
+++ b/src/blog_node5_net.py
@@ -6,6 +6,7 @@ import sys
import typing
import urllib
import pathlib
+import subprocess
import flask
import markdown
@@ -53,9 +54,22 @@ logger.info(f"Debug: {'en' if debug else 'dis'}abled")
articles_path = os.environ["ARTICLES_PATH"] if "ARTICLES_PATH" in os.environ else './blog.node5.net/articles/'
site_files_path = os.environ["SITE_FILES_PATH"] if "SITE_FILES_PATH" in os.environ else './blog.node5.net/'
+articles_repo_url = os.environ["ARTICLES_REPO_URL"] if "ARTICLES_REPO_URL" in os.environ else 'https://git.node5.net/blog/articles/'
logger.debug(f'articles_path: {articles_path}')
logger.debug(f'site_files_path: {site_files_path}')
+pathlib.Path(articles_path).mkdir(parents=True, exist_ok=True)
+if pathlib.Path(articles_path).exists() and not any(pathlib.Path(articles_path).iterdir()):
+ logger.info(f"Articles path {articles_path} is empty, cloning {articles_repo_url} into {articles_path}")
+ try:
+ subprocess.run(["git", "clone", articles_repo_url, articles_path], check=True, stderr=subprocess.PIPE, text=True)
+ except subprocess.CalledProcessError as e:
+ # Cleanup partially created files on failure
+ if path.exists() and not any(path.iterdir()):
+ shutil.rmtree(path, ignore_errors=True)
+ raise RuntimeError(f"git clone failed: {e.stderr.strip()}") from e
+
+
article_generator = article.ArticleGenerator(articles_path)
@@ -195,7 +209,7 @@ def load_articles():
logger.info('Loading articles')
articles = get_articles()
if not articles.articles:
- logger.warning(f"No articles loaded, path: {articles_path}")
+ logger.warning(f"No articles found, path: {articles_path}")
register_urls(articles)