Skip to content

feat(astro-redirects): Astro integration for _redirects and frontmatter redirects#1118

Merged
pcfreak30 merged 1 commit into
developfrom
feat/astro-redirects
Jul 21, 2026
Merged

feat(astro-redirects): Astro integration for _redirects and frontmatter redirects#1118
pcfreak30 merged 1 commit into
developfrom
feat/astro-redirects

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

Astro integration that generates redirects from _redirects files, Markdown frontmatter, and programmatic config. Compatible with the IPFS Web Redirects File spec and inspired by astro-redirect-from.

Features

  • Parse _redirects files (Netlify/IPFS spec):
    • Splats (*), placeholders (:id)
    • Status codes: 200, 301-308, 404, 410, 451
    • 64 KiB file size limit
  • Extract redirect_from from Markdown/MDX frontmatter via gray-matter
  • Skip draft: true posts in production builds
  • Optional emitFile to output _redirects text for static hosts
  • Extra static redirects via config

Usage

import redirects from '@lumeweb/astro-redirects';

export default defineConfig({
  integrations: [
    redirects({
      redirectsFile: true,
      frontmatter: true,
      emitFile: true,
      extra: { '/old': '/new' },
    }),
  ],
});

Package

  • libs/astro-redirects/ — new workspace package
  • private: true for now until ready to publish
  • 100% test coverage (25 tests)

Files Changed

  • libs/astro-redirects/* — new package (12 files)
  • pnpm-lock.yaml — gray-matter + deps

This pull request introduces a new @lumeweb/astro-redirects Astro integration library that centralizes redirect management for Astro-based projects.

The integration collects redirect rules from three sources:

  1. _redirects files (Netlify/IPFS Web Redirects format) located in the public directory or a custom path
  2. redirect_from frontmatter in Markdown/MDX content files under src/pages
  3. Additional static or dynamic redirects supplied via plugin configuration

Supported capabilities include splat patterns (*), dynamic placeholders, common HTTP status codes (200, 301–308, 404, 410, 451), and absolute destination URLs with allowed schemes (http, https, ipfs, ipns).

The integration registers valid 3xx redirects with Astro's built-in redirect config and can optionally emit a _redirects text file into the build output for deployment to static hosts. Draft content is excluded from production builds.

The change adds the full library source, unit tests, build configuration, documentation, and updates the lockfile with the new package dependencies.

@kody-ai

This comment has been minimized.

Comment thread libs/astro-redirects/src/frontmatter.ts Outdated
Comment thread libs/astro-redirects/src/index.ts Outdated
Comment thread libs/astro-redirects/src/index.ts
Comment thread libs/astro-redirects/src/parse.ts Outdated
@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from 9edb721 to 58930c7 Compare July 21, 2026 09:57
@kody-ai

This comment has been minimized.

@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from 58930c7 to 2b56c03 Compare July 21, 2026 09:59
Comment thread libs/astro-redirects/src/index.ts
Comment thread libs/astro-redirects/src/parse.ts
Comment thread libs/astro-redirects/src/parse.ts Outdated
@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from 2b56c03 to fdd3345 Compare July 21, 2026 10:02
@kody-ai

This comment has been minimized.

Comment thread libs/astro-redirects/src/frontmatter.ts
Comment thread libs/astro-redirects/src/index.ts Outdated
Comment thread libs/astro-redirects/src/index.ts

@kody-ai kody-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found critical issues please review the requested changes

@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from fdd3345 to 3f56eeb Compare July 21, 2026 10:19
@kody-ai

This comment has been minimized.

Comment thread libs/astro-redirects/src/frontmatter.ts Outdated
Comment thread libs/astro-redirects/src/index.ts Outdated
Comment thread libs/astro-redirects/src/index.ts Outdated
Comment thread libs/astro-redirects/src/index.ts
Comment thread libs/astro-redirects/src/index.ts
Comment thread libs/astro-redirects/src/index.ts Outdated

@kody-ai kody-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found critical issues please review the requested changes

@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from 3f56eeb to 1ecf3f3 Compare July 21, 2026 10:47
@kody-ai

This comment has been minimized.

Comment thread libs/astro-redirects/src/index.ts

@kody-ai kody-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from 1ecf3f3 to d6bfa36 Compare July 21, 2026 11:23
@kody-ai

kody-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

…matter redirects

Add @lumeweb/astro-redirects package that provides:
- Parse _redirects files (Netlify/IPFS spec compliant)
- Extract redirect_from frontmatter via gray-matter
- Support splats, placeholders, status codes (200, 301-308, 404, 410, 451)
- Optional emitFile to generate _redirects text output
- Skip draft posts in production builds
- 100% test coverage with vitest

Package is private for now until ready for publish.
@pcfreak30
pcfreak30 force-pushed the feat/astro-redirects branch from d6bfa36 to c045e8c Compare July 21, 2026 11:26
Comment thread libs/astro-redirects/src/frontmatter.ts
Comment thread libs/astro-redirects/src/index.ts
@pcfreak30
pcfreak30 merged commit 0d29a8c into develop Jul 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant