Add year filter redirects

This commit is contained in:
Neeldhara Misra 2026-07-06 22:05:27 +05:30
parent 6e7eb9ce52
commit 7cb63470cd
3 changed files with 52 additions and 0 deletions

View file

@ -10,6 +10,7 @@ RUN npm run build
FROM nginx:1.29-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80

15
nginx.conf Normal file
View file

@ -0,0 +1,15 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location ~ "^/([0-9]{4})/?$" {
return 302 "/?year=$1#events";
}
location / {
try_files $uri $uri/ =404;
}
}

View file

@ -0,0 +1,36 @@
---
import { organizedEvents } from "../../data/events";
export function getStaticPaths() {
const years = Array.from(new Set(organizedEvents.map((event) => event.year)));
return years.map((year) => ({
params: { year },
props: { year },
}));
}
type Props = {
year: string;
};
const { year } = Astro.props;
const target = `/?year=${encodeURIComponent(year)}#events`;
---
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<meta http-equiv="refresh" content={`0; url=${target}`} />
<link rel="canonical" href={target} />
<title>Redirecting to {year} events</title>
<script is:inline define:vars={{ target }}>
window.location.replace(target);
</script>
</head>
<body>
<p>Redirecting to <a href={target}>{year} events</a>.</p>
</body>
</html>