--- /dev/null
+import feedparser
+import os
+import re
+import frontmatter
+from markdownify import markdownify as md
+import html
+from datetime import datetime
+
+RSS_URL = "https://medium.com/feed/@xangelo"
+OUTPUT_DIR = "content/posts"
+EXISTING_SLUGS = {f[:-3] for f in os.listdir(OUTPUT_DIR) if f.endswith(".md")}
+
+def slugify(title):
+ return re.sub(r"[^\w-]", "", re.sub(r"\s+", "-", title.lower())).strip("-")
+
+feed = feedparser.parse(RSS_URL)
+
+for entry in feed.entries:
+ slug = slugify(entry.title)
+ if slug in EXISTING_SLUGS:
+ continue
+
+ content_html = entry.get("content", [{}])[0].get("value", "") or entry.get("summary", "")
+ markdown_content = md(html.unescape(content_html))
+
+ post = frontmatter.Post(markdown_content)
+ post["title"] = entry.title
+ post["date"] = entry.published
+ post["slug"] = slug
+ post["draft"] = False
+ post["medium_link"] = entry.link
+
+ output_path = os.path.join(OUTPUT_DIR, f"{slug}.md")
+ with open(output_path, "w", encoding="utf-8") as f:
+ f.write(frontmatter.dumps(post))
+
+ print(f"Saved: {output_path}")
\ No newline at end of file
--- /dev/null
+name: Sync Medium to Hugo
+
+on:
+ workflow_dispatch: {}
+ schedule:
+ - cron: "*/30 * * * *" # Runs every 30m
+
+jobs:
+ sync:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repo
+ uses: actions/checkout@v4
+
+ - name: Set up Python
+ uses: actions/setup-python@v5
+ with:
+ python-version: "3.x"
+
+ - name: Install dependencies
+ run: pip install feedparser markdownify python-frontmatter requests
+
+ - name: Run sync script
+ run: python .github/scripts/medium_to_hugo.py
+
+ - name: Commit and push changes
+ run: |
+ git config user.name "Medium Sync Bot"
+ git config user.email "actions@github.com"
+ git add content/posts/
+ git diff --quiet && git diff --staged --quiet || git commit -m "Sync new Medium posts"
+ git push