Skip to content

Commit

Permalink
feat: add redirects for backwards compatibility (#1439)
Browse files Browse the repository at this point in the history
Fixes first part of #1184.
  • Loading branch information
tobiasdiez committed Sep 24, 2022
1 parent d60eb62 commit 63b727d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion content/surveys/2015/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ layout: survey
In November 2015, the community was asked to fill a survey about JabRef usages and potential developments
About 400 responses were collected.
This page presents an overview of the results.
A detailed analysis is provided at [Analysis](analysis).
A detailed analysis is provided at [Analysis](./analysis).

## Current use of JabRef

Expand Down
6 changes: 0 additions & 6 deletions content/surveys/index.md

This file was deleted.

34 changes: 34 additions & 0 deletions modules/redirects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { addPluginTemplate, defineNuxtModule } from '@nuxt/kit'
type Redirect = { from: string; to: string; external?: boolean }

// For some reason nuxt converts an array as module option to an object of the form { 0: '...', 1: '...' }
export type ModuleOptions = {
[key: string]: Redirect
}

export default defineNuxtModule<ModuleOptions>({
meta: {
configKey: 'redirects',
},
setup(moduleOptions, _nuxt) {
addPluginTemplate({
filename: 'redirects.mjs',
write: true, // for easier debugging
getContents: () => `
import { createRouter } from 'radix3'
export default defineNuxtPlugin(nuxt => {
const redirects = createRouter()
const moduleOptions = ${JSON.stringify(moduleOptions)}
Object.values(moduleOptions).forEach(({ from, to, external }) => {
redirects.insert(from, { to, external })
})
addRouteMiddleware((to, _from) => {
const redirect = redirects.lookup(to.path)
if (redirect) {
return navigateTo(redirect.to, { external: redirect.external })
}
})
})`,
})
},
})
18 changes: 18 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default defineNuxtConfig({
'@nuxtjs/tailwindcss',
// Add support for naive-ui
'./modules/naive-ui',
// Add support for redirects
'./modules/redirects',
// Use Pinia for state management
'@pinia/nuxt',
// Add storybook support
Expand Down Expand Up @@ -98,6 +100,22 @@ export default defineNuxtConfig({
{ route: '/api/', handler: '~/server/index.ts' },
],

/**
* Add redirects, mostly for backwards compatibility
*/
redirects: [
{ from: '/faq', to: 'https://docs.jabref.org/faq', external: true },
{ from: '/paypal', to: '/donations' },
{
from: '/donations',
to: 'https://github.com/JabRef/jabref/wiki/Donations/',
external: true,
},
{ from: '/gsoc/**', to: '/codeprojects/gsoc' },
{ from: '/bluehat2022', to: '/codeprojects/bluehat2022' },
{ from: '/surveys/', to: '/surveys/2015' },
],

/**
* Storybook integration with Nuxt
* See https://storybook.nuxtjs.org/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
definePageMeta({ layout: 'content' })
const route = useRoute()
let markdownPath = 'surveys/'
let markdownPath = 'surveys/2015/'
if (typeof route.params.slug === 'string') {
markdownPath += route.params.slug
Expand Down

0 comments on commit 63b727d

Please sign in to comment.