This guide covers setting up the Dev.to Mirror project for local development. The project generates a static mirror of your Dev.to blog posts with AI-enhanced metadata and cross-references.
- Python 3.12+ (the project uses modern Python features)
- Git
- A Dev.to account with published posts
-
Clone and setup:
git clone https://github.com/anchildress1/devto-mirror.git cd devto-mirror make install # Installs dev dependencies and lefthook hooks
-
Configure environment variables:
cp .env.example .env # Edit .env with your actual values - see Environment Variables section below -
Install lefthook hooks (recommended):
make install # Installs dev deps and lefthook hooks -
Run validation to ensure everything works:
make ai-checks # Comprehensive check: format, lint, test, security, site generation -
Generate your site locally:
uv run python scripts/generate_site.py # Creates HTML files in posts/ directory
The project uses a .env file for local development configuration. This keeps sensitive data out of version control and makes local testing easier.
Required variables:
DEVTO_USERNAME: Your Dev.to username (e.g., "anchildress1")
Site URL configuration (one required):
SITE_DOMAIN: Custom domain (e.g., "crawly.checkmarkdevtools.dev")GH_USERNAME: GitHub username (e.g., "anchildress1") - used ifSITE_DOMAINnot set
Optional variables:
FORCE_FULL_REGEN: Set to "true" to regenerate all posts instead of incremental updatesVALIDATION_MODE: Set to "true" to use mock data instead of API calls (for testing)
Example .env file (with custom domain):
DEVTO_USERNAME=your-username
SITE_DOMAIN=crawly.checkmarkdevtools.dev
FORCE_FULL_REGEN=false
VALIDATION_MODE=falseExample .env file (with GitHub Pages):
DEVTO_USERNAME=your-username
GH_USERNAME=your-github-username
FORCE_FULL_REGEN=false
VALIDATION_MODE=falseThe project includes a comprehensive development workflow with automated quality checks:
Daily development commands:
make format # Auto-format code with Black (120 char line length)
make lint # Run all lefthook checks (linting, security, secrets)
make test # Run unit tests for AI optimization modules
make ai-checks # Run everything: format + lint + test + security + site validationUnderstanding the validation pipeline:
- Format: Uses Black to ensure consistent code style
- Lint: Runs lefthook checks (formatting, linting, security)
- Test: Unit tests for content analysis and cross-reference features
- Site validation: Dry-run of site generation to catch build errors early
- Security: Scans for vulnerabilities and security issues
Lefthook hooks run automatically when you commit, catching issues before they reach CI:
lefthook install # One-time setup
lefthook run pre-commit # Manual run on all files
git commit -m "your message" # Hooks run automaticallyWhat the hooks check:
- Code formatting (Black)
- Linting and style checks
- Security issues (bandit)
- Secret detection
- Site generation validation
If any hook fails, the commit is blocked until you fix the issues.
devto-mirror/
├── scripts/ # Main site generation and utility scripts
│ ├── generate_site.py # Core site generation logic
│ ├── validate_site_generation.py # Lefthook validation
│ └── utils.py # Shared script utilities
├── src/ # Python package (AI optimization modules)
│ └── ai_optimization/ # Content analysis and cross-references
├── tests/ # Unit tests
├── docs/ # Documentation
└── .env.example # Environment variable template
The project includes multiple levels of testing:
Unit tests (for AI optimization features):
make test # Run all unit tests with coverageSite generation validation (catches build errors):
uv run python scripts/validate_site_generation.py # Test site generation with mock dataIntegration testing (full pipeline):
make ai-checks # Complete validation pipeline| Error | Solution |
|---|---|
| ModuleNotFoundError: No module named 'src' | Ensure you're in the correct virtual environment and the package is installed (make install will run the recommended install steps). |
| Missing DEVTO_USERNAME | Check your .env file exists and has the correct variable names |
| Lefthook hooks failing | Run make format then make lint to see specific issues |
| Site generation fails locally | Check that your Dev.to username is correct and you have published posts |
| Import errors | Make sure you ran make install (or the equivalent uv commands) and activated your virtual environment |
After forking the repository, configure it for automatic deployment:
-
Set repository variables:
- Navigate to Settings → Actions → Variables → Repository variables
- Add
DEVTO_USERNAMEwith your Dev.to username - This tells the workflows which Dev.to profile to mirror
-
Enable GitHub Pages:
- Go to Settings → Pages
- Under "Source", select "Deploy from a branch"
- Choose
gh-pagesbranch (created automatically by first workflow run) - Your site will be available at
https://yourusername.github.io/devto-mirror
-
Run initial workflow:
- Go to Actions → "Generate and Publish Dev.to Mirror Site" → Run workflow
- This creates the
gh-pagesbranch and deploys your first site
Trigger workflows manually for testing or immediate updates:
- Go to repository's Actions tab
- Select the workflow you want to run
- Click "Run workflow" button
- Choose branch (usually
main) and any options - Click "Run workflow" to start
When to use manual triggers:
- Testing changes before they go live
- Immediate updates after publishing new posts
- Troubleshooting workflow issues
- Full site regeneration (via
publish.yamlwithforce_full_regen=true)
For detailed explanations of the CI/CD workflows and their technical implementation, see CI_GUIDE.md.