-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix `/category/ page creation, sort by fields_category - fix `/tag` group by published posts only
- Loading branch information
1 parent
4d8537f
commit 7fff028
Showing
8 changed files
with
151 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const kebabCase = require("lodash.kebabcase"); | ||
const path = require("path"); | ||
const siteConfig = require("../../config"); | ||
|
||
module.exports = async (graphql, actions) => { | ||
const { createPage } = actions; | ||
const { postsPerPage } = siteConfig; | ||
|
||
const result = await graphql(` | ||
{ | ||
allMdx( | ||
filter: { | ||
frontmatter: { publish: { ne: false } } | ||
fileAbsolutePath: { regex: "/vault/" } | ||
} | ||
) { | ||
group(field: fields___stage) { | ||
fieldValue | ||
totalCount | ||
} | ||
} | ||
} | ||
`); | ||
|
||
result.data.allMdx.group.forEach((stage) => { | ||
const numPages = Math.ceil(stage.totalCount / postsPerPage); | ||
const stageSlug = `/stage/${kebabCase(stage.fieldValue)}`; | ||
|
||
for (let i = 0; i < numPages; i += 1) { | ||
createPage({ | ||
path: i === 0 ? `${stageSlug}/` : `${stageSlug}/page/${i}`, | ||
component: path.resolve("./src/templates/stage-template.tsx"), | ||
context: { | ||
stage: stage.fieldValue, | ||
slug: stageSlug, | ||
currentPage: i, | ||
postsLimit: postsPerPage, | ||
postsOffset: i * postsPerPage, | ||
prevPagePath: i <= 1 ? stageSlug : `${stageSlug}/page/${i - 1}`, | ||
nextPagePath: `${stageSlug}/page/${i + 1}`, | ||
hasPrevPage: i !== 0, | ||
hasNextPage: i !== numPages - 1, | ||
}, | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Layout from "@/components/Layout"; | ||
import React from "react"; | ||
import ListNote from "@/components/ListNote"; | ||
import { graphql } from "gatsby"; | ||
import { SITE_TITLE } from "../../config"; | ||
|
||
type Props = { | ||
data: AllMdx; | ||
pageContext: PageContext; | ||
}; | ||
|
||
const StageTemplate = ({ data, pageContext }: Props) => { | ||
const { edges } = data.allMdx; | ||
const { | ||
stage, | ||
slug, | ||
currentPage, | ||
prevPagePath, | ||
nextPagePath, | ||
hasPrevPage, | ||
hasNextPage, | ||
} = pageContext; | ||
const pageTitle = | ||
currentPage > 0 | ||
? `${stage} - Page ${currentPage} - ${SITE_TITLE}` | ||
: `${stage} - ${SITE_TITLE}`; | ||
|
||
return ( | ||
<Layout title={pageTitle}> | ||
<div className="my-2 py-4 border-b border-slate-200"> | ||
<h1 className="capitalize inline-block mr-2 text-5xl md:text-7xl font-black"> | ||
{stage} | ||
</h1> | ||
</div> | ||
<ListNote edges={edges} /> | ||
{/* {(hasPrevPage || hasNextPage) && ( | ||
<Pagination | ||
prevPagePath={prevPagePath} | ||
nextPagePath={nextPagePath} | ||
hasPrevPage={hasPrevPage} | ||
hasNextPage={hasNextPage} | ||
/> | ||
)} */} | ||
</Layout> | ||
); | ||
}; | ||
|
||
export const query = graphql` | ||
query StagePage($stage: String) { | ||
allMdx( | ||
filter: { | ||
frontmatter: { publish: { ne: false } } | ||
fields: { stage: { eq: $stage } } | ||
} | ||
sort: { order: DESC, fields: fields___date } | ||
) { | ||
edges { | ||
node { | ||
...postList | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default StageTemplate; |