File tree 16 files changed +137
-58
lines changed
16 files changed +137
-58
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " @example/basics " ,
2
+ "name" : " fairedesjeux " ,
3
3
"type" : " module" ,
4
4
"version" : " 0.0.1" ,
5
5
"private" : true ,
Original file line number Diff line number Diff line change
1
+ import type { MarkdownInstance } from "astro"
2
+ import type { BaseFrontmatter } from "./shared"
3
+
4
+ export interface Chapter extends BaseFrontmatter { }
5
+
6
+ export type ChapterInstance = MarkdownInstance < Chapter >
Original file line number Diff line number Diff line change
1
+ export * from "./chapters"
2
+ export * from "./courses"
3
+ export * from "./shared"
Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ export interface BaseFrontmatter {
3
3
description : string
4
4
opengraph_image : string | null
5
5
}
6
+
7
+ export type ContentType = "Course" | "Chapter" | "Page"
Original file line number Diff line number Diff line change 1
1
---
2
- import Footer from " ../ components/footer/Footer.astro"
3
- import Header from " ../ components/header/Header.astro"
2
+ import Footer from " $ components/footer/Footer.astro"
3
+ import Header from " $ components/header/Header.astro"
4
4
5
5
export interface Props {
6
6
title: string
Original file line number Diff line number Diff line change 1
1
---
2
- import type { CourseInstance } from " ../ data/courses "
2
+ import type { CourseInstance } from " $ data"
3
3
import AppLayout from " ./AppLayout.astro"
4
4
5
5
interface Props {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ ---
2
+ import type { Chapter , ChapterInstance } from " $data"
3
+ import { getStaticPathFromContentType } from " ../glob.astro"
4
+
5
+ interface Props {
6
+ slug: ChapterInstance
7
+ }
8
+ const { content } = Astro .props
9
+
10
+ export async function getStaticPaths() {
11
+ return await getStaticPathFromContentType (Astro , " Chapter" )
12
+ }
13
+ ---
Original file line number Diff line number Diff line change
1
+ ---
2
+ import type { CourseInstance } from " $data"
3
+ import { getStaticPathFromContentType } from " ./glob.astro"
4
+ import ContentLayout from " $layouts/ContentLayout.astro"
5
+
6
+ interface Props {
7
+ content: CourseInstance
8
+ }
9
+ const { content } = Astro .props
10
+
11
+ export async function getStaticPaths() {
12
+ return await getStaticPathFromContentType (Astro , " Course" )
13
+ }
14
+ ---
15
+
16
+ <ContentLayout content ={ content } />
Original file line number Diff line number Diff line change
1
+ ---
2
+ import type { Chapter , ContentType , Course } from " $data"
3
+ import { getSlugFromFilePath } from " $utils"
4
+ import type { AstroGlobal } from " astro"
5
+
6
+ /**
7
+ * A standardized way to get all Static Paths of a given content type.
8
+ * ==============================================
9
+ * Temporarily moved from `src/utils/glob.ts`,
10
+ * see this issue -> https://github.com/withastro/astro/issues/5552
11
+ * @param Astro needed to use Astro.glob<t> inside a TypeScript file
12
+ * @param contentType what's the type of content needed ?
13
+ * @returns A promise of an array with all Static Paths
14
+ */
15
+ export async function getStaticPathFromContentType(
16
+ Astro : Readonly <AstroGlobal >,
17
+ contentType : ContentType
18
+ ) {
19
+ let contents: Array <any > = []
20
+
21
+ switch (contentType ) {
22
+ case " Course" :
23
+ contents = await Astro .glob <Course >(" ../../content/**/index.md" )
24
+ break
25
+ case " Chapter" :
26
+ contents = await Astro .glob <Chapter >(" ../../content/**/**/chapter.md" )
27
+ case " Page" :
28
+ contents = await Astro .glob <Chapter >(" ../../content/**/**/*.md" )
29
+ default :
30
+ throw new Error (
31
+ ` [getStaticPathFromContentType] contentType not yet implemented: ${contentType } `
32
+ )
33
+ }
34
+
35
+ return contents .map ((content ) => ({
36
+ params: {
37
+ slug: getSlugFromFilePath (content .file , contentType ),
38
+ },
39
+ props: {
40
+ content: { ... content },
41
+ },
42
+ }))
43
+ }
44
+ ---
Original file line number Diff line number Diff line change 1
1
---
2
- import type { Course } from " ../ data/courses "
3
- import MainLayout from " ../layouts/MainLayout.astro "
4
- import { getSlugFromPath } from " ../utils "
2
+ import type { Course } from " $ data"
3
+ import { getSlugFromFilePath } from " $utils "
4
+ import MainLayout from " $layouts/MainLayout.astro "
5
5
6
6
const courses = await Astro .glob <Course >(" ../../content/**/index.md" )
7
7
---
@@ -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 = { " /" + getSlugFromFilePath (course .file , " Course" )} >
16
16
{ course .frontmatter .title }
17
17
</a >
18
18
</li >
Original file line number Diff line number Diff line change
1
+ import type { ContentType } from "$data"
2
+
3
+ /**
4
+ * Get content's slug from a content file path
5
+ * @param path where is the content file ?
6
+ * @param contentType what's the type of content ?
7
+ * @returns
8
+ */
9
+ export function getSlugFromFilePath (
10
+ path : string ,
11
+ contentType : ContentType
12
+ ) : string {
13
+ switch ( contentType ) {
14
+ case "Course" :
15
+ return path . substring (
16
+ // there is probably a smarter way
17
+ path . indexOf ( "content/" ) + 8 ,
18
+ path . indexOf ( "/index.md" )
19
+ )
20
+ default :
21
+ throw new Error (
22
+ `[getSlugFromFilePath] contentType not yet implemented: ${ contentType } `
23
+ )
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Temporarily moved to `src/pages/glob.astro`,
3
+ * see this issue -> https://github.com/withastro/astro/issues/5552
4
+ */
5
+ export async function getStaticPathFromContentType ( ) {
6
+ throw new Error ( "Temporarily moved to `src/pages/glob.astro`" )
7
+ }
Original file line number Diff line number Diff line change 1
- /**
2
- * Get content's slug from a content file path
3
- * @param path where is the content file ?
4
- * @param contentType what's the type of content ?
5
- * @returns
6
- */
7
- export function getSlugFromPath (
8
- path : string ,
9
- contentType : contentType
10
- ) : string {
11
- switch ( contentType ) {
12
- case "Course" :
13
- return path . substring (
14
- // there is probably a smarter way
15
- path . indexOf ( "content/" ) + 8 ,
16
- path . indexOf ( "/index.md" )
17
- )
18
- default :
19
- throw new Error ( `contentType not yet implemented: ${ contentType } ` )
20
- }
21
- }
22
-
23
- type contentType = "Course" | "Chapter" | "Page"
1
+ export * from "./files"
2
+ export * from "./glob"
Original file line number Diff line number Diff line change 1
1
{
2
- "extends" : " astro/tsconfigs/strict"
3
- }
2
+ "extends" : " astro/tsconfigs/strict" ,
3
+ "compilerOptions" : {
4
+ "baseUrl" : " ." ,
5
+ "paths" : {
6
+ "$components/*" : [" src/components/*" ],
7
+ "$data" : [" src/data/index.ts" ],
8
+ "$layouts/*" : [" src/layouts/*" ],
9
+ "$utils" : [" src/utils/index.ts" ]
10
+ }
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments