File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,9 @@ exports.onCreatePage = async ({ page, actions }) => {
85
85
if ( page . path . startsWith ( '/blog' ) ) {
86
86
return ;
87
87
}
88
+ if ( page . path . startsWith ( '/tags' ) ) {
89
+ return ;
90
+ }
88
91
89
92
const { createPage, deletePage } = actions
90
93
deletePage ( page )
@@ -228,8 +231,8 @@ exports.createPages = async ({ graphql, actions }) => {
228
231
}
229
232
}
230
233
}
231
- tagsGroup: allMarkdownRemark {
232
- group(field: frontmatter___tags ) {
234
+ allBlogPost {
235
+ group(field: tags ) {
233
236
fieldValue
234
237
}
235
238
}
@@ -244,6 +247,17 @@ exports.createPages = async ({ graphql, actions }) => {
244
247
throw result . errors
245
248
}
246
249
250
+ const tags = result . data . allBlogPost . group . map ( group => group . fieldValue )
251
+ tags . forEach ( tag => {
252
+ createPage ( {
253
+ path : `/tags/${ tag . toLowerCase ( ) } /` ,
254
+ component : path . resolve ( "./src/templates/{BlogPost.tags}.tsx" ) ,
255
+ context : {
256
+ tag,
257
+ } ,
258
+ } )
259
+ } )
260
+
247
261
const markdownPages = result . data . allMarkdownRemark . edges
248
262
249
263
// foundation: [
Original file line number Diff line number Diff line change 1
1
import * as React from "react"
2
2
import type { PageProps } from "gatsby"
3
3
import { graphql } from "gatsby"
4
- import Layout from "../../ components/Layout"
5
- import BlogPostPreview from "../../ components/BlogPostPreview"
6
- import BlogSidebar from "../../ components/BlogSidebar"
4
+ import Layout from "../components/Layout"
5
+ import BlogPostPreview from "../components/BlogPostPreview"
6
+ import BlogSidebar from "../components/BlogSidebar"
7
7
8
8
export const query = graphql `
9
- query TagPage($tags: [ String!] !) {
9
+ query TagPage($tag: String!) {
10
10
allBlogPost(
11
- filter: { tags: { in: $tags } }
11
+ filter: { tags: { in: [$tag] } }
12
12
) {
13
13
nodes {
14
14
id
@@ -20,8 +20,8 @@ export const query = graphql`
20
20
21
21
type Props = PageProps < GatsbyTypes . TagPageQuery , GatsbyTypes . SitePageContext >
22
22
23
- const TagPage : React . FC < Props > = ( { data, params } ) => {
24
- const currentTag = params . tags !
23
+ const TagPage : React . FC < Props > = ( { data, pageContext } ) => {
24
+ const currentTag = pageContext . tag !
25
25
return (
26
26
< Layout title = { `Blog: ${ currentTag } | GraphQL` } pageContext = { { } } >
27
27
< section >
You can’t perform that action at this time.
0 commit comments