https://github.com/sergeyzwezdin/hexo-generator-redirect
Redirect pages generator for Hexo static site generator
https://github.com/sergeyzwezdin/hexo-generator-redirect
hexo hexo-plugin
Last synced: about 1 year ago
JSON representation
Redirect pages generator for Hexo static site generator
- Host: GitHub
- URL: https://github.com/sergeyzwezdin/hexo-generator-redirect
- Owner: sergeyzwezdin
- License: mit
- Created: 2020-04-04T14:49:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-25T04:02:36.000Z (almost 3 years ago)
- Last Synced: 2024-08-09T05:12:10.727Z (almost 2 years ago)
- Topics: hexo, hexo-plugin
- Language: JavaScript
- Homepage: https://hexo.io/
- Size: 117 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-generator-redirect  
`hexo-generator-redirect` is a plugin for Hexo static site generator that generates additional redirect pages. It's useful if you migrate your website and changed addresses for some posts.
* Migrate to new URLs **without the pain**.
* **Easy to install** and use.
* **Custom templates** for the redirect page.
## How it works
The plugin generates additional HTML page for "outdated" URLs. These pages will contain information on where the page was moved to.
## Requirements
- Hexo: 4.x
- Node 12+
## Usage
1. Install the plugin using npm:
```bash
$ npm install hexo-generator-redirect --save-dev
```
2. Add `redirect_from` key into frontmatter of the page:
```yaml
layout: post
title: Page
redirect_from:
- /old-url1
- /old-url2
```
3. Create a layout template for the redirect page (for more details see below).
4. Build the website 🤝.
## Creating the template
Create `redirect.ejs` in the `layout` folder of your theme.
You can use the `post` variable in the template. To access the target page information, use `page.target.path`.
Here is an example of the redirect page layout (`redirect.ejs`):
```html
<% const newUrl = full_url_for(page.target.path) %>
Page address was changed
The new page address is <%= newUrl %>
setTimeout(function(){ document.location.href = '<%= newUrl %>'; }, 5000);
```