πŸ”— Redirect Generator Documentation

Automated tool for creating branded affiliate shortlink pages for Th1nkN3st.

🎯 Purpose

Generate clean, professional redirect URLs like:

⚑ Quick Start

# 1. Edit your product data
nano redirects.csv

# 2. Generate redirect pages
python3 generate_redirects.py redirects.csv

# 3. Test locally
bundle exec jekyll serve
# Visit http://localhost:4000/go/yourslug/

# 4. Deploy
git add go/ redirects.csv
git commit -m "Add new affiliate redirects"
git push

πŸ“ Data Formats

File: redirects.csv

slug,affiliate_link,product_name
anker67,https://amzn.to/4qhzGlu,Anker Prime 67W
logitechg305,https://amzn.to/47b37wC,Logitech G305
samsungg9,https://amzn.to/477v8VR,Samsung Odyssey G9

Usage:

python3 generate_redirects.py redirects.csv

JSON Format (Alternative)

File: redirects.json

{
  "redirects": [
    {
      "slug": "anker67",
      "affiliate_link": "https://amzn.to/4qhzGlu",
      "product_name": "Anker Prime 67W"
    },
    {
      "slug": "logitechg305",
      "affiliate_link": "https://amzn.to/47b37wC",
      "product_name": "Logitech G305"
    }
  ]
}

Usage:

python3 generate_redirects.py redirects.json

πŸ”§ Script Features

βœ… Batch Generation: Create multiple redirects at once
βœ… Auto-formatting: Proper YAML front matter & HTML
βœ… Overwrite Safe: Re-run anytime to update existing files
βœ… Validation: Skips invalid entries automatically
βœ… Clean Output: Shows exactly what was created

πŸ“‹ Field Descriptions

Field Required Description Example
slug βœ… Yes URL-friendly identifier anker67, logitechg305
affiliate_link βœ… Yes Full Amazon shortlink https://amzn.to/4qhzGlu
product_name ⚠️ Optional Product display name Anker Prime 67W

Notes:

🎨 Generated HTML Structure

Each redirect page includes:

---
layout: default
title: "Redirecting to {product_name}..."
permalink: /go/{slug}/
---

<meta http-equiv="refresh" content="0; url={affiliate_link}">
<link rel="canonical" href="https://www.th1nkn3st.com/go/{slug}/" />

<section style="text-align:center;margin:80px auto;max-width:600px;">
  <p>Redirecting you to Amazon...</p>
  <p style="font-size:0.9rem;color:#888;">
    As an Amazon Associate, Th1nkN3st earns from qualifying purchases.
  </p>
  <p>If you're not redirected automatically, 
     <a href="{affiliate_link}">click here</a>.
  </p>
</section>

πŸ”„ Typical Workflows

Adding One Product

# Add line to CSV
echo "newslug,https://amzn.to/XXXXX,Product Name" >> redirects.csv

# Regenerate all
python3 generate_redirects.py redirects.csv

# Test & deploy
git add go/ redirects.csv && git commit -m "Add redirect for Product Name" && git push

Bulk Update

# Edit CSV with multiple new products
nano redirects.csv

# Generate all redirects (overwrites existing)
python3 generate_redirects.py redirects.csv

# Review changes
git diff go/

# Deploy
git add go/ redirects.csv && git commit -m "Bulk update redirects" && git push

Testing Before Deploy

# Generate redirects
python3 generate_redirects.py redirects.csv

# Start local server
bundle exec jekyll serve

# Test in browser
open http://localhost:4000/go/yourslug/

# Should redirect to your affiliate link

πŸ› Troubleshooting

β€œFile not found” Error

# Make sure file exists
ls -la redirects.csv

# Check you're in the right directory
pwd
# Should show: /home/will/devops/th1nkn3st/site

β€œNo valid redirects found”

# Check CSV format (must have header row)
head -2 redirects.csv
# Should show:
# slug,affiliate_link,product_name
# anker67,https://amzn.to/4qhzGlu,Anker Prime 67W

# Check for required fields
cat redirects.csv | grep -v "^slug" | cut -d',' -f1,2

Redirect Not Working

# Rebuild Jekyll site
bundle exec jekyll clean
bundle exec jekyll build

# Check file was generated
ls -la _site/go/yourslug/

# Should show: index.html

πŸ“‚ File Structure

site/
β”œβ”€β”€ generate_redirects.py    # Generator script
β”œβ”€β”€ redirects.csv             # CSV data source
β”œβ”€β”€ redirects.json            # JSON data source (alternative)
└── go/
    β”œβ”€β”€ README.md             # Documentation
    β”œβ”€β”€ _template.html        # Manual template
    β”œβ”€β”€ anker67.html          # Generated redirect
    β”œβ”€β”€ logitechg305.html     # Generated redirect
    └── samsungg9.html        # Generated redirect

πŸš€ Advanced Usage

Custom Output Directory

Edit script line 86 to change output location:

go_dir = Path(__file__).parent / 'go'  # Change 'go' to your dir

Adding Custom Fields

Extend the template in REDIRECT_TEMPLATE variable and add fields to CSV/JSON.

Integration with CI/CD

# .github/workflows/generate-redirects.yml
- name: Generate redirects
  run: python3 generate_redirects.py redirects.csv
  
- name: Commit changes
  run: |
    git add go/
    git commit -m "Auto-generate redirects" || true

πŸ“Š Example Output

$ python3 generate_redirects.py redirects.csv

Reading CSV file: redirects.csv

Generating 3 redirect file(s)...

  βœ“ Created: go/anker67.html β†’ https://amzn.to/4qhzGlu
  βœ“ Created: go/logitechg305.html β†’ https://amzn.to/47b37wC
  βœ“ Created: go/samsungg9.html β†’ https://amzn.to/477v8VR

βœ… Successfully generated 3 redirect file(s)

Next steps:
  1. Test locally: http://localhost:4000/go/<slug>/
  2. Commit: git add go/ && git commit -m 'Add affiliate redirects'
  3. Push: git push
  4. Test live: https://www.th1nkn3st.com/go/<slug>/

πŸ“œ License

Part of the Th1nkN3st site project. For internal use.


Version: 1.0
Last Updated: October 16, 2025
Author: Th1nkN3st Team