The-DevOps-Daily/devops-daily

feat: Add canonical URL audit and consistency check

Open

#545 创建于 2025年12月2日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)TypeScript (392 fork)github user discovery
enhancementgood first issuehacktoberfest

仓库指标

Star
 (1,087 star)
PR 合并指标
 (PR 指标待抓取)

描述

Description

Audit all pages for proper canonical URL tags and ensure consistency across the site to prevent duplicate content SEO issues.

Problem

  • Canonical URLs may not be set on all pages
  • Risk of duplicate content penalties
  • Inconsistent URL patterns across site
  • No automated verification of canonical tags

SEO Impact

  • Search engines may index wrong version of pages
  • Duplicate content dilutes page authority
  • Could affect search rankings
  • Wasted crawl budget

Pages to Audit

Content Pages

  • Posts: /posts/[slug]
  • Guides: /guides/[slug] and /guides/[slug]/[part]
  • Quizzes: /quizzes/[slug]
  • Games: /games/[slug]
  • News: /news/[slug]
  • Exercises: /exercises/[id]

Listing Pages

  • Homepage: /
  • Posts index: /posts
  • Guides index: /guides
  • Quizzes index: /quizzes
  • Games index: /games
  • Tags: /tags/[tag]
  • Categories: /categories/[slug]
  • Authors: /authors/[slug]

Paginated Pages

  • Check if pagination exists
  • Ensure proper canonical for paginated results

Current State Check

# Search for canonical tags
rg '<link rel="canonical"' app/

# Check metadata generation
cat app/*/page.tsx | grep canonical

Proposed Solution

  1. Audit existing canonical tags
  2. Add canonical to all page metadata
  3. Create utility function for canonical URLs
  4. Add automated tests

Implementation Example

// lib/canonical.ts
export function getCanonicalUrl(path: string): string {
  const baseUrl = 'https://devops-daily.com';
  return `${baseUrl}${path}`;
}

// In page.tsx
export const metadata: Metadata = {
  title: 'Post Title',
  alternates: {
    canonical: getCanonicalUrl('/posts/my-post')
  }
};

Acceptance Criteria

  • Audit all pages for canonical tags
  • Create canonical URL utility function
  • Add canonical to all page metadata
  • Ensure consistent URL patterns (trailing slashes, etc.)
  • Add automated test for canonical tags
  • Verify in production with view-source
  • Add to SEO checklist
  • Document canonical URL conventions

Testing

// tests/canonical-urls.test.ts
import { describe, it, expect } from 'vitest';
import { getCanonicalUrl } from '@/lib/canonical';

describe('Canonical URLs', () => {
  it('generates correct canonical URL', () => {
    expect(getCanonicalUrl('/posts/test')).toBe(
      'https://devops-daily.com/posts/test'
    );
  });

  it('handles trailing slashes', () => {
    expect(getCanonicalUrl('/posts/test/')).toBe(
      'https://devops-daily.com/posts/test'
    );
  });
});

Files to Create/Modify

  • lib/canonical.ts - New utility
  • tests/canonical-urls.test.ts - New tests
  • All page.tsx files - Add canonical metadata
  • docs/seo.md - Document canonical URL strategy

贡献者指南