From b4c455f40ce3d91e29d24cfbf68cd94728256dff Mon Sep 17 00:00:00 2001 From: mvking5464 Date: Wed, 17 Apr 2024 20:11:28 +0530 Subject: [PATCH] Added Static Site Generate for all pages --- package.json | 2 +- .../courses/[courseId]/[...moduleId]/page.tsx | 27 ++++++++++++++- src/app/courses/[courseId]/page.tsx | 15 +++++++- src/db/course.ts | 13 +++++++ yarn.lock | 34 +++++++------------ 5 files changed, 66 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index fb7561020..32ea8eb4a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "lint:fix": "eslint --max-warnings 0 --config .eslintrc . --fix", "format:fix": "prettier --write \"**/*.{ts,tsx,json}\"", "format:check": "prettier --check \"**/*.{ts,tsx,json}\"", - "prisma:docker" : "npm run prisma:migrate && npm run db:seed && npm run studio", + "prisma:docker": "npm run prisma:migrate && npm run db:seed && npm run studio", "dev:docker": "npm run prisma:docker & next dev", "prisma:migrate": "prisma migrate deploy", "db:seed": "prisma db seed", diff --git a/src/app/courses/[courseId]/[...moduleId]/page.tsx b/src/app/courses/[courseId]/[...moduleId]/page.tsx index 576c9eb51..8208c8ae1 100644 --- a/src/app/courses/[courseId]/[...moduleId]/page.tsx +++ b/src/app/courses/[courseId]/[...moduleId]/page.tsx @@ -1,8 +1,33 @@ import { QueryParams } from '@/actions/types'; import { CourseView } from '@/components/CourseView'; -import { Folder, getCourse, getFullCourseContent } from '@/db/course'; +import { + Folder, + getContentNested, + getCourse, + getFullCourseContent, +} from '@/db/course'; import findContentById from '@/lib/find-content-by-id'; +export async function generateStaticParams() { + const courses = await getContentNested(); + const courseIds = courses.map((courseId: any) => { + const getFolder = courseId.content.flatMap((folderId: any) => { + const getContent = folderId.content.children.map((contentId: any) => { + return { + courseId: `${courseId.id}`, + moduleId: [`${folderId.contentId}`, `${contentId.id}`], + }; + }); + return [ + ...getContent, + { courseId: `${courseId.id}`, moduleId: [`${folderId.contentId}`] }, + ]; + }); + return getFolder; + }); + return courseIds.flat(); +} + export default async function Course({ params, searchParams, diff --git a/src/app/courses/[courseId]/page.tsx b/src/app/courses/[courseId]/page.tsx index c0c42098c..1a8e4f2a8 100644 --- a/src/app/courses/[courseId]/page.tsx +++ b/src/app/courses/[courseId]/page.tsx @@ -1,8 +1,21 @@ import { QueryParams } from '@/actions/types'; import { CourseView } from '@/components/CourseView'; -import { Folder, getCourse, getFullCourseContent } from '@/db/course'; +import { + Folder, + getAllCourses, + getCourse, + getFullCourseContent, +} from '@/db/course'; import findContentById from '@/lib/find-content-by-id'; +export async function generateStaticParams() { + const courses = await getAllCourses(); + const courseIds = courses.map((i: any) => { + return { courseId: `${i.id}` }; + }); + return courseIds.flat(); +} + export default async function Course({ params, searchParams, diff --git a/src/db/course.ts b/src/db/course.ts index 348ba0bf9..44ab3d2c3 100644 --- a/src/db/course.ts +++ b/src/db/course.ts @@ -373,3 +373,16 @@ export const getCurrentContentType = async ( return content.type; }; + +export async function getContentNested() { + const courses = await db.course.findMany({ + orderBy: { + id: 'desc', + }, + include: { + content: { include: { content: { include: { children: true } } } }, + }, + }); + + return courses; +} diff --git a/yarn.lock b/yarn.lock index 897b33742..d77c4bfb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -293,22 +293,12 @@ resolved "https://registry.npmjs.org/@icons-pack/react-simple-icons/-/react-simple-icons-9.4.0.tgz" integrity sha512-fZtC4Zv53hE+IQE2dJlFt3EB6UOifwTrUNMuEu4hSXemtqMahd05Dpvj2K0j2ewVc+j/ibavud3xjfaMB2Nj7g== -"@img/sharp-libvips-linux-x64@1.0.1": - version "1.0.1" - resolved "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.1.tgz" - integrity sha512-3NR1mxFsaSgMMzz1bAnnKbSAI+lHXVTqAHgc1bgzjHuXjo4hlscpUxc0vFSAPKI3yuzdzcZOkq7nDPrP2F8Jgw== - -"@img/sharp-libvips-linuxmusl-x64@1.0.1": - version "1.0.1" - resolved "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.1.tgz" - integrity sha512-dcT7inI9DBFK6ovfeWRe3hG30h51cBAP5JXlZfx6pzc/Mnf9HFCQDLtYf4MCBjxaaTfjCCjkBxcy3XzOAo5txw== - -"@img/sharp-linux-x64@0.33.2": +"@img/sharp-darwin-arm64@0.33.2": version "0.33.2" - resolved "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.2.tgz" - integrity sha512-xUT82H5IbXewKkeF5aiooajoO1tQV4PnKfS/OZtb5DDdxS/FCI/uXTVZ35GQ97RZXsycojz/AJ0asoz6p2/H/A== + resolved "https://registry.yarnpkg.com/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.2.tgz#0a52a82c2169112794dac2c71bfba9e90f7c5bd1" + integrity sha512-itHBs1rPmsmGF9p4qRe++CzCgd+kFYktnsoR1sbIAfsRMrJZau0Tt1AH9KVnufc2/tU02Gf6Ibujx+15qRE03w== optionalDependencies: - "@img/sharp-libvips-linux-x64" "1.0.1" + "@img/sharp-libvips-darwin-arm64" "1.0.1" "@img/sharp-darwin-x64@0.33.2": version "0.33.2" @@ -493,15 +483,10 @@ resolved "https://registry.npmjs.org/@next/env/-/env-14.0.2.tgz" integrity sha512-HAW1sljizEaduEOes/m84oUqeIDAUYBR1CDwu2tobNlNDFP3cSm9d6QsOsGeNlIppU1p/p1+bWbYCbvwjFiceA== -"@next/swc-linux-x64-gnu@14.0.2": +"@next/swc-darwin-arm64@14.0.2": version "14.0.2" - resolved "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.2.tgz" - integrity sha512-WC9KAPSowj6as76P3vf1J3mf2QTm3Wv3FBzQi7UJ+dxWjK3MhHVWsWUo24AnmHx9qDcEtHM58okgZkXVqeLB+Q== - -"@next/swc-linux-x64-musl@14.0.2": - version "14.0.2" - resolved "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.2.tgz" - integrity sha512-KSSAwvUcjtdZY4zJFa2f5VNJIwuEVnOSlqYqbQIawREJA+gUI6egeiRu290pXioQXnQHYYdXmnVNZ4M+VMB7KQ== + resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.2.tgz#eba35a1425fee5d305903c85ae0d6d2b0d512c7b" + integrity sha512-i+jQY0fOb8L5gvGvojWyZMfQoQtDVB2kYe7fufOEiST6sicvzI2W5/EXo4lX5bLUjapHKe+nFxuVv7BA+Pd7LQ== "@next/swc-darwin-x64@14.0.2": version "14.0.2" @@ -2205,6 +2190,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@~2.3.2: + version "2.3.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"