File tree 7 files changed +32
-18
lines changed 7 files changed +32
-18
lines changed Original file line number Diff line number Diff line change
1
+ import type { MarkdownInstance } from "astro"
1
2
import type { BaseFrontmatter } from "./shared"
2
3
3
4
export interface Course extends BaseFrontmatter {
4
- type : string
5
+ type : "SKILL" | "ENGINE"
5
6
short_title : string
6
7
date : string
7
8
author : string
8
- medal : string
9
+ medal : "SILVER" | "BRONZE" | "GOLD" | "PLATINIUM"
9
10
medal_message : string
10
11
cover_wide : string
11
12
cover_tall : string
12
13
}
14
+
15
+ export type CourseInstance = MarkdownInstance < Course >
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import Header from "../components/header/Header.astro"
5
5
export interface Props {
6
6
title: string
7
7
}
8
-
9
8
const { title } = Astro .props
10
9
---
11
10
Original file line number Diff line number Diff line change 1
1
---
2
- import type { Course } from " ../data/courses"
2
+ import type { CourseInstance } from " ../data/courses"
3
3
import AppLayout from " ./AppLayout.astro"
4
4
5
+ interface Props {
6
+ content: CourseInstance
7
+ }
5
8
const { content } = Astro .props
6
- const frontmatter: Course = content .frontmatter
7
9
---
8
10
9
- <AppLayout title ={ frontmatter .title } >
11
+ <AppLayout title ={ content . frontmatter .title } >
10
12
<main class =" max-w-screen-md mx-auto px-4 py-2" >
11
13
<h2 >
12
- { frontmatter .title }
14
+ { content . frontmatter .title }
13
15
</h2 >
14
16
<content .Content />
15
17
</main >
Original file line number Diff line number Diff line change 1
1
---
2
2
import AppLayout from " ./AppLayout.astro"
3
3
4
+ interface Props {
5
+ title: string
6
+ }
4
7
const { title } = Astro .props
5
8
---
6
9
Original file line number Diff line number Diff line change 1
1
---
2
+ import type { Course , CourseInstance } from " ../data/courses"
2
3
import ContentLayout from " ../layouts/ContentLayout.astro"
3
4
import { getSlugFromPath } from " ../utils"
4
5
6
+ interface Props {
7
+ course: CourseInstance
8
+ }
9
+ const { course } = Astro .props
10
+
5
11
export async function getStaticPaths() {
6
- const courses = await Astro .glob (" ../../content/**/index.md" )
12
+ const courses = await Astro .glob < Course > (" ../../content/**/index.md" )
7
13
8
14
return courses .map ((course ) => ({
9
15
params: {
10
- course: getSlugFromPath (course .file , " course " ),
16
+ course: getSlugFromPath (course .file , " Course " ),
11
17
},
12
18
props: {
13
- course: { ... course , frontmatter: course . frontmatter },
19
+ course: { ... course },
14
20
},
15
21
}))
16
22
}
17
-
18
- const { course } = Astro .props
19
23
---
20
24
21
25
<ContentLayout content ={ course } />
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ const courses = await Astro.glob<Course>("../../content/**/index.md")
12
12
{
13
13
courses .map ((course ) => (
14
14
<li >
15
- <a href = { " /" + getSlugFromPath (course .file , " course " )} >
15
+ <a href = { " /" + getSlugFromPath (course .file , " Course " )} >
16
16
{ course .frontmatter .title }
17
17
</a >
18
18
</li >
Original file line number Diff line number Diff line change 4
4
* @param contentType what's the type of content ?
5
5
* @returns
6
6
*/
7
- export function getSlugFromPath ( path : String , contentType : String ) : String {
7
+ export function getSlugFromPath (
8
+ path : string ,
9
+ contentType : contentType
10
+ ) : string {
8
11
switch ( contentType ) {
9
- case "course " :
12
+ case "Course " :
10
13
return path . substring (
11
14
// there is probably a smarter way
12
15
path . indexOf ( "content/" ) + 8 ,
13
16
path . indexOf ( "/index.md" )
14
17
)
15
18
default :
16
- throw new Error (
17
- `contentType from getSlugFromPath() is invalid: ${ contentType } `
18
- )
19
+ throw new Error ( `contentType not yet implemented: ${ contentType } ` )
19
20
}
20
21
}
22
+
23
+ type contentType = "Course" | "Chapter" | "Page"
You can’t perform that action at this time.
0 commit comments