diff --git a/src/pages/events/[id].tsx b/src/pages/events/[id].tsx index 0b810ac..310eca1 100644 --- a/src/pages/events/[id].tsx +++ b/src/pages/events/[id].tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NextPage, GetServerSideProps } from "next"; +import { NextPage, GetStaticProps, GetStaticPaths } from "next"; import Head from "next/head"; import { useRouter } from "next/router"; import { @@ -32,14 +32,30 @@ const EventPage: NextPage = ({ initialEvent }) => { ); }; -export const getServerSideProps: GetServerSideProps = async (context) => { - const { id } = context.query; +export const getStaticPaths: GetStaticPaths = async () => { + const { url, config } = generateFetchParams(); + const allEvents = await eventFetcher(url, config); + const paths = allEvents.results.map((e: Event) => ({ + params: { + id: String(e.id), + }, + } + )); + return { + paths, + fallback: false, + }; +}; + +export const getStaticProps: GetStaticProps = async ({ params }) => { + const { id } = params; const { url, config } = generateFetchParams(id as string); const initialEvent = await eventFetcher(url, config); return { props: { initialEvent, }, + revalidate: 60, }; }; diff --git a/src/pages/in_english.tsx b/src/pages/in_english.tsx index 7fee87b..b5e702e 100644 --- a/src/pages/in_english.tsx +++ b/src/pages/in_english.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NextPage, GetServerSideProps } from "next"; +import { NextPage, GetStaticProps } from "next"; import Head from "next/head"; import { Event, useFetchEvents, eventFetcher, generateFetchParams as eventParams, @@ -36,7 +36,7 @@ const InEnglishPage: NextPage = ({ initialEvents, initialFeed }) = ); }; -export const getServerSideProps: GetServerSideProps = async () => { +export const getStaticProps: GetStaticProps = async () => { let url: string; let config: any; ({ url, config } = eventParams("", eventOptions)); @@ -48,6 +48,7 @@ export const getServerSideProps: GetServerSideProps = async () => initialEvents, initialFeed, }, + revalidate: 60, }; }; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b4350ad..312f9e2 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NextPage, GetServerSideProps } from "next"; +import { NextPage, GetStaticProps } from "next"; import Head from "next/head"; import { Event, useFetchEvents, eventFetcher, generateFetchParams as eventParams, @@ -36,7 +36,7 @@ const FrontPage: NextPage = ({ initialEvents, initialFeed }) => { ); }; -export const getServerSideProps: GetServerSideProps = async () => { +export const getStaticProps: GetStaticProps = async () => { let url: string; let config: any; ({ url, config } = eventParams("", eventOptions)); @@ -48,6 +48,7 @@ export const getServerSideProps: GetServerSideProps = async () => initialEvents, initialFeed, }, + revalidate: 60, }; }; diff --git a/src/pages/kilta/toiminta.tsx b/src/pages/kilta/toiminta.tsx index 1353b9b..23b0d45 100644 --- a/src/pages/kilta/toiminta.tsx +++ b/src/pages/kilta/toiminta.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NextPage, GetServerSideProps } from "next"; +import { NextPage, GetStaticProps } from "next"; import Head from "next/head"; import { Event, useFetchEvents, eventFetcher, generateFetchParams as eventParams, @@ -35,7 +35,7 @@ const ActualPage: NextPage = ({ initialEvents, initialFeed }) => { ); }; -export const getServerSideProps: GetServerSideProps = async () => { +export const getStaticProps: GetStaticProps = async () => { let url: string; let config: any; ({ url, config } = eventParams("", eventOptions)); @@ -47,6 +47,7 @@ export const getServerSideProps: GetServerSideProps = async () => initialEvents, initialFeed, }, + revalidate: 60, }; }; diff --git a/src/pages/yritysyhteistyo.tsx b/src/pages/yritysyhteistyo.tsx index 0d4ae57..ad05dd9 100644 --- a/src/pages/yritysyhteistyo.tsx +++ b/src/pages/yritysyhteistyo.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { NextPage, GetServerSideProps } from "next"; +import { NextPage, GetStaticProps } from "next"; import Head from "next/head"; import { JobAd, useFetchJobAds, jobAdFetcher, generateFetchParams, @@ -26,13 +26,14 @@ const CorporatePage: NextPage = ({ initialJobAds }) => { ); }; -export const getServerSideProps: GetServerSideProps = async () => { +export const getStaticProps: GetStaticProps = async () => { const { url } = generateFetchParams(); const initialJobAds = await jobAdFetcher(url); return { props: { initialJobAds, }, + revalidate: 60, }; };