> don_kitchen
// TODO: write witty tagline
cd /projects

Affilinker

"Manage affiliate links across your content."

━━━

If you run a blog or content site with affiliate links, you know the pain. Links scattered across dozens of files. Old Amazon URLs with tracking parameters from 2012. No way to know which links are actually getting clicks. And when Amazon changes their URL format (again), you get to do a find-and-replace across your entire codebase.

I built Affilinker to solve this for my own site, then open-sourced it so others could use it too.

What It Does

Affilinker is a CLI tool that scans your content files (MDX, Markdown, HTML), finds all outbound links, and gives you tools to manage them:

  • Scan - Find every outbound link in your content
  • Convert - Clean up messy affiliate URLs (especially Amazon)
  • Report - Export links as JSON, CSV, SQL, or Markdown
  • Transform - Replace URLs with centralized tracking links
  • Sync - Push links to Supabase or save as JSON

The Problem It Solves

I had 86 blog posts with 250+ outbound links. Some were Amazon affiliate links from over a decade ago - long, ugly URLs with outdated tracking parameters. Others were regular links to tools and resources. I had no visibility into which links were getting clicks, and updating them meant editing dozens of files.

With Affilinker, I transformed all those links to use a centralized/link/[slug] format. Now every click is tracked, I can update destinations without touching content files, and my Amazon links are clean and properly tagged.

How It Works

Install it globally or use npx:

npx affilinker scan

Configure it with an affilinker.config.mjs file:

export default {
  content: {
    include: ['content/**/*.mdx'],
  },
  siteUrl: 'https://yoursite.com',
  tracking: {
    baseUrl: '/link/',
  },
  networks: {
    amazon: {
      tag: 'yourtag-20',
    },
  },
};

Then scan, transform, and sync:

affilinker scan              # Find all links
affilinker report --sql      # Generate SQL insert statements
affilinker transform         # Replace URLs in content
affilinker sync              # Push to database

The Stack

  • TypeScript for type safety
  • Commander.js for the CLI framework
  • Remark/Unified for parsing MDX and Markdown
  • Supabase adapter for database sync

Why Open Source

Affiliate link management is a common problem for content creators, but most solutions are either WordPress plugins or expensive SaaS tools. I wanted something that works with modern static site generators like Next.js, Astro, and Gatsby - tools that use MDX and Markdown for content.

The tool is MIT licensed and available on npm. PRs welcome.

Get Started

Check out the GitHub repo for full documentation, or install it directly:

npm install -g affilinker