Skip to content

Commit

Permalink
Merge pull request #181 from MiyashitaLab/fix/config_redirect
Browse files Browse the repository at this point in the history
Fix/config redirect
  • Loading branch information
HoorayTritium committed Sep 9, 2023
2 parents df5eff9 + e615717 commit a109eb1
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 171 deletions.
42 changes: 31 additions & 11 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
const redirects = require("./redirects.json");
const redirects = require('./redirects.json')

const encodeRedirectURL = (text) => {
const regHttp = /^(https?)/
if (regHttp.test(text)) {
// 外部リンク
const splitIndex = text.indexOf(':')+1
const http = text.substring(0, splitIndex)
const url = text.substring(splitIndex)
return http + encodeRedirectURL(url)
} else {
const separators = /([/ /? = &])/g
return text
.split(separators)
.map((e) => {
if (separators.test(e)) return e
else return encodeURIComponent(e)
})
.join('')
}
}

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
remotePatterns: [
{
hostname: "images.ctfassets.net",
protocol: "https",
hostname: 'images.ctfassets.net',
protocol: 'https',
pathname: `/${process.env.CONTENTFUL_SPACE_ID}/**`,
},
],
},
rewrites: async () => {
return [
{
source: "/researches/:slug/assets/:name",
destination: "/api/asset-paper/:slug",
source: '/researches/:slug/assets/:name',
destination: '/api/asset-paper/:slug',
},
];
]
},
redirects: async () => {
return [...redirects].map((item) => ({
source: item.source.split('/').map(e=>encodeURIComponent(e)).join('/'),
destination: item.destination.split('/').map(e=>encodeURIComponent(e)).join('/'),
source: encodeRedirectURL(item.source),
destination: encodeRedirectURL(item.destination),
permanent: item.permanent,
}));
}))
},
experimental: {
scrollRestoration: true,
largePageDataBytes: 1024 * 1000, //1MB
},
};
}

module.exports = nextConfig;
module.exports = nextConfig

0 comments on commit a109eb1

Please sign in to comment.