Skip to content

Commit 393d1f3

Browse files
committed
Finally!
1 parent 2bb0392 commit 393d1f3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

astro.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export default defineConfig({
1919
logo: {
2020
src: './src/assets/logo.svg',
2121
},
22+
head: [
23+
{
24+
tag: 'script',
25+
attrs: {
26+
src: '/nodify/public/redirect.js',
27+
},
28+
},
29+
],
2230
credits: true,
2331
pagination: false,
2432
plugins: [starlightThemeObsidian({ graph: false, backlinks: false })],

public/redirect.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const url = window.location;
2+
3+
if (url.pathname.includes('wiki/') && !url.pathname.includes('.html')) {
4+
const redirectUrl = `${url.pathname.toLocaleLowerCase()}.html`;
5+
window.location.href = redirectUrl;
6+
}

src/middleware.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { MiddlewareHandler } from 'astro';
22

33
/**
44
* This middleware converts the pathname to lowercase and adds .html to the final path for documentation pages and redirects the request to the URL with a 301 status code.
5+
*
6+
* NOTE! This is running only for server side rendering.
57
*/
68
export const onRequest: MiddlewareHandler = async (context, next) => {
79
const url = new URL(context.request.url);

0 commit comments

Comments
 (0)