theme page moved to getStaticProps and getStaticPaths

This commit is contained in:
Hikmet 2023-07-19 12:13:20 +03:00
parent cf7fbf8837
commit 96edb85316
2 changed files with 26 additions and 1 deletions

View File

@ -26,6 +26,23 @@ export class ThemeReposityImplementation implements ThemeRepository {
return ThemeReposityImplementation.instance;
}
getThemeIds = async (): Promise<any> => {
const dbClient = DynamoDBClientSingleton.getInstance();
const queryCommand = new QueryCommand({
TableName: "themes",
KeyConditionExpression: "PK = :pk",
ExpressionAttributeValues: {
":pk": { S: "theme" },
},
ProjectionExpression: "SK",
});
const rawThemeIdDatas = await dbClient.send(queryCommand);
const themeIds = rawThemeIdDatas.Items!.map((item) => unmarshall(item));
return themeIds;
};
getThemeMetas = async (): Promise<ThemeMetaDTO[]> => {
const dbClient = DynamoDBClientSingleton.getInstance();
const queryCommand = new QueryCommand({

View File

@ -7,7 +7,7 @@ export default function ThemePage({ themeData }: { themeData: Theme }) {
return <ThemePageElement theme={Theme.from(themeData)} isAdmin={false} />;
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
export async function getStaticProps(context: GetServerSidePropsContext) {
const path = context.params as unknown as { theme: string };
const themeRepository = ThemeReposityImplementation.getInstance();
const themeData = await themeRepository.getThemeData(path.theme);
@ -18,3 +18,11 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
},
};
}
export async function getStaticPaths() {
const themeRepository = ThemeReposityImplementation.getInstance();
const themeIds = (await themeRepository.getThemeIds()) as { SK: string }[];
const themePaths = themeIds.map((item) => ({ params: { theme: item.SK } }));
return { paths: themePaths, fallback: false };
}