Automatically generate blog posts from your GitHub repositories and publish them to your Hugo blog site.
- 🤖 Automatically discovers your new GitHub repositories
- ✍️ Generates blog posts using AI (via OpenRouter) or a fallback method
- 📚 Saves posts to your Obsidian vault
- 🚀 Syncs with your Hugo blog and deploys changes
- 🔄 Keeps track of processed repositories to avoid duplication
- Python 3.6+
- GitHub account with repositories
- Obsidian vault setup
- Hugo blog setup
- (Optional) OpenRouter API key for AI-generated content
-
Clone this repository:
git clone https://github.com/yourusername/autoblog.git cd autoblog -
Install required packages:
pip install -r requirements.txt
-
Create a
.envfile based on the provided.env-example:cp .env-example .env
-
Fill in your configuration values in the
.envfile
Edit the .env file with your specific details:
# GitHub settings
GITHUB_TOKEN=your_github_personal_access_token
GITHUB_USERNAME=your_github_username
# Path settings
OBSIDIAN_VAULT_PATH=C:/path/to/your/obsidian/vault
BLOG_REPO_PATH=C:/path/to/your/blog/repository
# OpenRouter settings
OPENROUTER_API_KEY=your_openrouter_api_key # Optional
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token" → "Generate new token (classic)"
- Give your token a name and select these scopes:
repo(Full control of private repositories)read:user(Read user information)
- Click "Generate token" and copy it immediately
- Add it to your
.envfile asGITHUB_TOKEN
-
OBSIDIAN_VAULT_PATH: Full path to your Obsidian vault's blog posts folder- Use forward slashes
/instead of backslashes\ - If path contains spaces, wrap in quotes:
"C:/Path With Spaces/Blog"
- Use forward slashes
-
BLOG_REPO_PATH: Path to your Hugo blog repository- Must be a git repository
- Should contain Hugo's content structure
- Register at openrouter.ai
- Get your API key from Dashboard → API Keys
- Add to
.envasOPENROUTER_API_KEY
Run with the batch file:
run.batOr directly with Python:
python main.py- Process repos after a specific date:
python main.py --date 2023-01-01
-
Repository Discovery
- Scans your GitHub account for repositories
- Checks for README.md files
- Compares against previously processed repos
-
Content Generation
- Attempts AI generation with OpenRouter
- Falls back to template-based generation if AI fails
- Extracts:
- Repository description
- Code samples (up to 5 files)
- Language statistics
- Tags from README content
-
Content Management
- Saves to Obsidian vault with date prefix
- Syncs to Hugo content directory
- Updates processed_repos.json
-
Publishing
- Builds Hugo site
- Commits changes
- Pushes to blog repository
Modify config.py to customize the blog post template:
blog_post_template = """---
title: "{title}"
date: {date}
draft: false
tags: [{tags}]
---
// ... customize your template
"""Adjust in blog_generator.py:
- Change AI model
- Modify prompt
- Adjust temperature (creativity)
- Set token limits
processed_repos.json: Tracks processed repositories- Generated files:
YYYY-MM-DD-repo-name.md - Hugo integration: Posts appear in
content/posts/
-
Path Issues
- Use forward slashes
/in paths - Wrap paths with spaces in quotes
- Verify paths exist before running
- Use forward slashes
-
GitHub API Issues
- Check token permissions
- Verify token hasn't expired
- Ensure username is correct
-
Hugo Integration
- Verify Hugo is installed and in PATH
- Check Hugo content directory structure
- Ensure git repository is properly initialized
-
OpenRouter Issues
- Verify API key is valid
- Check API rate limits
- Monitor usage quotas
- "No module named 'dotenv'": Run
pip install python-dotenv - "Invalid token": Regenerate GitHub token
- "Path does not exist": Check path configurations
- "Hugo build failed": Verify Hugo installation
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your branch
- Create a Pull Request
MIT License - See LICENSE file for details
- Create an issue for bugs
- Pull requests welcome
- Star the repository if you find it useful
- Built with Python and GitHub API
- Uses OpenRouter for AI content
- Integrates with Hugo and Obsidian