diff --git a/README.md b/README.md index 67ec8e1..a01b0b5 100644 --- a/README.md +++ b/README.md @@ -16,50 +16,24 @@ **Table of Contents** -- [How it Works](#how-it-works) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Options](#options) - [`contentDir: string`](#contentdir-string) - [`getSlug: (filePath: string) => string`](#getslug-filepath-string--string) - [Usage](#usage) +- [More Documentation](#more-documentation) - [Plugin Development](#plugin-development) - [Changelog](#changelog) - [License](#license) --- -Imagine you've just revamped your blog, and some of your old URLs have changed. You don't want to lose the SEO juice, nor do you want to leave your readers with broken links. This is where redirects come into play. But managing redirects can be cumbersome, especially if you have to do it manually or through server configurations. - -This plugin automates this process by reading the `redirect_from` field in the frontmatter of your Markdown files and updating Astro's configuration to handle these redirects automatically. - -## How it Works - -By adding a `redirect_from` list in your Markdown frontmatter, the plugin integrates these redirects into Astro's [`redirects`](https://docs.astro.build/en/reference/configuration-reference/#redirects) configuration automatically, whether you're running the development server or building your project. - -The plugin operates during the [`astro:config:setup`](https://docs.astro.build/en/reference/integrations-reference/#astroconfigsetup) lifecycle hook. It scans all Markdown files for the `redirect_from` key and updates Astro's configuration using [`updateConfig()`](https://docs.astro.build/en/reference/integrations-reference/#updateconfig-option). This ensures that any existing redirects are merged with new ones generated by the plugin. - -Astro takes over from there, handling the redirects based on your site's build mode and in combination with any other integrations you might be using: - -> For statically-generated sites with no adapter installed, this will produce a client redirect using a `` tag and does not support status codes. -> -> When using SSR or with a static adapter in `output: static` mode, status codes are supported. Astro will serve redirected `GET` requests with a status of `301` and use a status of `308` for any other request method. -> [Astro Configuration Reference: redirects](https://docs.astro.build/en/reference/configuration-reference/#redirects) - -The plugin is designed to work with various Astro hosting integrations, most of them generate further redirect files in the places they require so this plugin works in combination with them: - -- [ ] Netlify -- [ ] Vercel -- [ ] Cloudflare -- [ ] S3 - -Because Astro integrations are run in the order they are defined in the `integrations` array, this plugin should come before any other integrations which make use of the `redirects` config. - ## Prerequisites The plugin is designed to work without configuration, especially if your project aligns with Astro's default settings. -- Requires Astro v3 (v2 probably works too, but is not tested) +- Astro v3 (v2 probably works too, but is not tested) - Markdown files should be in a directory (default is `src/pages/`) - Slugs are extracted either from the frontmatter or the file/folder path @@ -82,7 +56,7 @@ If installing manually: npm i astro-redirect-from ``` -Then load the plugin in your Astro config file: +Then load the plugin in your Astro config file, making sure this plugin comes before any other integrations which make use of the `redirects` config: ```js title="astro.config.mjs" import { defineConfig } from 'astro/config' @@ -91,8 +65,7 @@ import redirectFrom from 'astro-redirect-from' export default defineConfig({ // ... integrations: [ - // make sure this is listed before any - // hosting integration + // make sure this is listed before any hosting integration redirectFrom() ] // ... @@ -105,7 +78,7 @@ That's it. Your redirects will be automatically added the next time you run `ast ### Options -Options are all optional and can be passed in Astro's config file: +All options are optional and can be passed in Astro's config file: ```js title="astro.config.mjs" import { defineConfig } from 'astro/config' @@ -171,6 +144,12 @@ redirect_from: --- ``` +## [More Documentation](https://kremalicious.com/astro-redirect-from/) + +Find more explanations, all about server-side redirects, and learn about additional integrations which can be used in combination with astro-redirect-from. + +- **[Documentation →](https://kremalicious.com/astro-redirect-from/)** + ## Plugin Development ```bash