Skip to content

5.2: Create URL Domain Extractor #95

@justin808

Description

@justin808

Overview

Create utility to extract domain from story URLs.

Parent Epic: #70
Priority: P2

Prerequisites

Next Issues (after this is complete)

  • Can be used by Story component

Acceptance Criteria

  • app/javascript/lib/urlUtils.ts created
  • Extracts domain from full URLs
  • Handles edge cases (no URL, malformed URL, no protocol)
  • Strips "www." prefix
  • Unit tests with Jest/Vitest
  • TypeScript types exported

Implementation Notes

export function extractDomain(url: string | null | undefined): string | null {
  if (!url) return null;
  
  try {
    const parsed = new URL(url);
    return parsed.hostname.replace(/^www\./, '');
  } catch {
    return null;
  }
}

// Examples:
// "https://www.example.com/path" -> "example.com"
// "http://github.com/user/repo" -> "github.com"
// null -> null
// "not a url" -> null

Note: This could also be done server-side in the Story presenter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    HN-RSCHacker News RSC DemoRSCReact Server Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions