Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/api/paths/[pathSlug]/[topicSlug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getTopic } from "@/data";

export async function GET(req: Request, { params }: { params: Promise<{ pathSlug: string; topicSlug: string }> }) {
const { pathSlug, topicSlug } = await params

const topics = getTopic(pathSlug, topicSlug)

if (!topics) return Response.json(false)

return Response.json(topics)
}
14 changes: 14 additions & 0 deletions src/app/api/paths/[pathSlug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getPath } from "@/data"


export async function GET(req: Request,
{ params } : {params: Promise<{pathSlug: string}>}) {

const { pathSlug } = await params

const paths = getPath(pathSlug)

if (!paths) return Response.json(false)

return Response.json(paths)
}
6 changes: 6 additions & 0 deletions src/app/api/paths/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { paths } from "@/data";

export async function GET() {

return Response.json(paths)
}
5 changes: 3 additions & 2 deletions src/app/paths/[pathSlug]/[topicSlug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { notFound } from "next/navigation";
import Link from "next/link";
import { paths, getTopic } from "@/data";
import { paths, getTopic, Path, Topic } from "@/data";
import ReactMarkdown from "react-markdown";

export function generateStaticParams() {
Expand Down Expand Up @@ -31,7 +31,8 @@ export default async function TopicPage({
params: Promise<{ pathSlug: string; topicSlug: string }>;
}) {
const { pathSlug, topicSlug } = await params;
const result = getTopic(pathSlug, topicSlug);
const response = await fetch(`http://localhost:3000/api/paths/${pathSlug}/${topicSlug}`)
const result = await response.json() as { path: Path; topic: Topic } | undefined;
if (!result) notFound();

const { path, topic } = result;
Expand Down
5 changes: 4 additions & 1 deletion src/app/paths/[pathSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export default async function PathPage({
params: Promise<{ pathSlug: string }>;
}) {
const { pathSlug } = await params;
const path = getPath(pathSlug);

const response = await fetch(`http://localhost:3000/api/paths/${pathSlug}`)
const path = await response.json()

if (!path) notFound();

const sorted = [...path.topics].sort((a, b) => a.order - b.order);
Expand Down
7 changes: 5 additions & 2 deletions src/app/paths/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import PathsClient from "@/components/PathsClient";
import { paths } from "@/data";


export const metadata = {
title: "All Paths | WebPath",
description: "Explore all web development learning paths.",
};

export default function PathsPage() {
export default async function PathsPage() {

const response = await fetch("http://localhost:3000/api/paths");
const paths = await response.json()

return (
<>
<div className="page-header">
Expand Down