Skip to content

Commit

Permalink
Added Static Site Generate for all pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvp5464 committed Apr 17, 2024
1 parent a13e99f commit b4c455f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 26 additions & 1 deletion src/app/courses/[courseId]/[...moduleId]/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 14 additions & 1 deletion src/app/courses/[courseId]/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/db/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
34 changes: 12 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
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/[email protected]":
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/[email protected]":
"@img/[email protected]":
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/[email protected]":
version "0.33.2"
Expand Down Expand Up @@ -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/[email protected]":
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/[email protected]":
version "14.0.2"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b4c455f

Please sign in to comment.