-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
96 lines (86 loc) · 2.35 KB
/
gatsby-node.js
File metadata and controls
96 lines (86 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const path = require("path");
// Configure Webpack aliases for shadcn/ui
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
"@/components": path.resolve(__dirname, "src/components"),
"@/utils": path.resolve(__dirname, "src/utils"),
"@/lib": path.resolve(__dirname, "src/lib"),
"@/hooks": path.resolve(__dirname, "src/hooks"),
},
},
});
};
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions;
// Query for all MDX content (articles and notes)
const result = await graphql(`
query {
articles: allMdx(
filter: {
internal: { contentFilePath: { regex: "/content/articles/" } }
}
) {
nodes {
id
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
notes: allMdx(
filter: { internal: { contentFilePath: { regex: "/content/notes/" } } }
) {
nodes {
id
frontmatter {
slug
title
}
internal {
contentFilePath
}
}
}
}
`);
if (result.errors) {
reporter.panicOnBuild("Error loading MDX result", result.errors);
}
// Create article pages
const articles = result.data.articles.nodes;
articles.forEach((article) => {
const { slug } = article.frontmatter;
createPage({
path: `/articles/${slug}`,
component: `${path.resolve("./src/templates/article.tsx")}?__contentFilePath=${article.internal.contentFilePath}`,
context: {
id: article.id,
},
});
});
// Create note pages
const notes = result.data.notes.nodes;
notes.forEach((note) => {
// Generate slug from title if not provided, or from file path
const slug =
note.frontmatter.slug ||
note.frontmatter.title
?.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "") ||
path.basename(note.internal.contentFilePath, ".mdx").toLowerCase();
createPage({
path: `/notes/${slug}`,
component: `${path.resolve("./src/templates/note.tsx")}?__contentFilePath=${note.internal.contentFilePath}`,
context: {
id: note.id,
},
});
});
};