Skip to content

Commit b464c40

Browse files
authored
Merge pull request #256 from dotCMS/course-slug-fix
Fixed the URLs to allow `-` characters to be used in the course slugs…
2 parents e13652c + 437dbaf commit b464c40

8 files changed

Lines changed: 308 additions & 296 deletions

File tree

app/api/sitemap/route.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { getSideNav } from "@/services/docs/getSideNav";
22
import { Config } from "@/util/config";
33
import { getBlogListing } from "@/services/blog/getBlogListing";
44
import { getDevResources } from "@/services/learning/getDevResources";
5+
6+
/** Aggregates many GraphQL calls; never freeze this into a static build artifact. */
7+
export const dynamic = "force-dynamic";
58
const extractHrefs = (obj) => {
69
const baseURL = `${Config.CDNHost}/docs/`;
710
let hrefs = [];

app/docs/authoring/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Metadata } from "next";
22
import { PersonaLandingPage } from "@/components/persona-landing/PersonaLandingPage";
33

4+
/** CMS nav is fetched at request time so a slow or unavailable GraphQL during `next build` does not fail the deploy. */
5+
export const dynamic = "force-dynamic";
6+
47
const hostname = "https://dev.dotcms.com";
58

69
export const metadata: Metadata = {

app/docs/developer/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Metadata } from "next";
22
import { PersonaLandingPage } from "@/components/persona-landing/PersonaLandingPage";
33

4+
/** CMS nav is fetched at request time so a slow or unavailable GraphQL during `next build` does not fail the deploy. */
5+
export const dynamic = "force-dynamic";
6+
47
const hostname = "https://dev.dotcms.com";
58

69
export const metadata: Metadata = {

app/docs/devops/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Metadata } from "next";
22
import { PersonaLandingPage } from "@/components/persona-landing/PersonaLandingPage";
33

4+
/** CMS nav is fetched at request time so a slow or unavailable GraphQL during `next build` does not fail the deploy. */
5+
export const dynamic = "force-dynamic";
6+
47
const hostname = "https://dev.dotcms.com";
58

69
export const metadata: Metadata = {

app/learn/[slug]/[chapter]/page.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1-
import { getCourseDetail } from "@/services/courses/getCourse";
1+
import { courseTitleForMetadata, getCourseDetail } from "@/services/courses/getCourse";
22
import MarkdownContent from "@/components/MarkdownContent";
33
import { notFound } from "next/navigation";
44
import ChapterFooter from "../ChapterFooter";
55

6+
export async function generateMetadata({ params }) {
7+
const { slug, chapter } = await params;
8+
const { course } = await getCourseDetail({ slug });
9+
if (!course) {
10+
return { title: "Course not found" };
11+
}
12+
13+
const match = chapter.match(/^chapter-(\d+)$/);
14+
if (!match) {
15+
return { title: "Chapter not found" };
16+
}
17+
18+
const index = parseInt(match[1], 10) - 1;
19+
const chapterData = course.chapters[index];
20+
if (!chapterData) {
21+
return { title: "Chapter not found" };
22+
}
23+
24+
const total = course.chapters?.length ?? 0;
25+
const n = index + 1;
26+
const label = courseTitleForMetadata(course);
27+
return { title: `${label} · Ch. ${n}/${total}${chapterData.title}` };
28+
}
29+
630
export default async function ChapterPage({ params }) {
731
const { slug, chapter } = await params;
832
const { course } = await getCourseDetail({ slug });

app/learn/[slug]/page.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import { getCourseDetail } from "@/services/courses/getCourse";
1+
import { courseTitleForMetadata, getCourseDetail } from "@/services/courses/getCourse";
22
import ChapterFooter from "./ChapterFooter";
33
import CourseIntroduction from "./CourseIntroduction";
44
import { notFound } from "next/navigation";
55

6+
export async function generateMetadata({ params }) {
7+
const { slug } = await params;
8+
const { course } = await getCourseDetail({ slug });
9+
if (!course) {
10+
return { title: "Course not found" };
11+
}
12+
return { title: courseTitleForMetadata(course) };
13+
}
14+
615
export default async function CoursePage({ params }) {
716
const { slug } = await params;
817
const { course } = await getCourseDetail({ slug });

0 commit comments

Comments
 (0)