mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
feat: implement page navigation in resource pages
This commit is contained in:
@@ -58,6 +58,7 @@ const createResources = async ({ createPage, graphql }) => {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
relativePath
|
relativePath
|
||||||
|
relativeDirectory
|
||||||
sourceInstanceName
|
sourceInstanceName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +74,7 @@ const createResources = async ({ createPage, graphql }) => {
|
|||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
relativePath
|
relativePath
|
||||||
|
relativeDirectory
|
||||||
sourceInstanceName
|
sourceInstanceName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +120,7 @@ const createResources = async ({ createPage, graphql }) => {
|
|||||||
component: resourcePage,
|
component: resourcePage,
|
||||||
context: {
|
context: {
|
||||||
file: node.relativePath,
|
file: node.relativePath,
|
||||||
|
directory: node.relativeDirectory,
|
||||||
layout: LAYOUT_RESOURCES,
|
layout: LAYOUT_RESOURCES,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { graphql } from "gatsby"
|
import { graphql } from "gatsby"
|
||||||
import React, { FC, Fragment } from "react"
|
import React, { FC, Fragment } from "react"
|
||||||
|
import descend from "ramda/es/descend"
|
||||||
|
import sortWith from "ramda/es/sortWith"
|
||||||
|
|
||||||
import { Footer } from "../components/Footer"
|
import { Footer } from "../components/Footer"
|
||||||
import { Header } from "../components/Header"
|
import { Header } from "../components/Header"
|
||||||
import { Markdown } from "../components/Markdown"
|
import { Markdown } from "../components/Markdown"
|
||||||
import { PageContent } from "../components/PageContent"
|
import { PageContent } from "../components/PageContent"
|
||||||
|
import { PageNavigation } from "../components/PageNavigation"
|
||||||
import { SEO } from "../components/SEO"
|
import { SEO } from "../components/SEO"
|
||||||
import useSidebar from "../hooks/useSidebar"
|
import useSidebar from "../hooks/useSidebar"
|
||||||
import { buildToc } from "../utils"
|
import { buildToc } from "../utils"
|
||||||
@@ -30,6 +33,29 @@ const ResourcePage: FC<any> = ({ data }) => {
|
|||||||
toc.length
|
toc.length
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const pages = sortWith([
|
||||||
|
descend((f: any) => {
|
||||||
|
if (f.node.relativePath.includes("intro")) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
})
|
||||||
|
], data.allFile.edges)
|
||||||
|
const currentIndex = pages.findIndex(
|
||||||
|
(x: any) => x.node.relativePath === relativePath
|
||||||
|
)
|
||||||
|
|
||||||
|
const nextPage = pages[currentIndex + 1] && {
|
||||||
|
title: pages[currentIndex + 1].node.title.frontmatter.title,
|
||||||
|
relativePath: pages[currentIndex + 1].node.relativePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
const previousPage = pages[currentIndex - 1] && {
|
||||||
|
title: pages[currentIndex - 1].node.title.frontmatter.title,
|
||||||
|
relativePath: pages[currentIndex - 1].node.relativePath,
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<SEO
|
<SEO
|
||||||
@@ -50,6 +76,7 @@ const ResourcePage: FC<any> = ({ data }) => {
|
|||||||
content={
|
content={
|
||||||
<>
|
<>
|
||||||
<Markdown content={body} />
|
<Markdown content={body} />
|
||||||
|
<PageNavigation next={nextPage} previous={previousPage} />
|
||||||
<Footer />
|
<Footer />
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
@@ -64,7 +91,7 @@ const ResourcePage: FC<any> = ({ data }) => {
|
|||||||
export default ResourcePage
|
export default ResourcePage
|
||||||
|
|
||||||
export const query = graphql`
|
export const query = graphql`
|
||||||
query ResourcePage($file: String!) {
|
query ResourcePage($file: String!, $directory: String!) {
|
||||||
file(relativePath: { eq: $file }) {
|
file(relativePath: { eq: $file }) {
|
||||||
relativePath
|
relativePath
|
||||||
post: childMdx {
|
post: childMdx {
|
||||||
@@ -93,5 +120,20 @@ export const query = graphql`
|
|||||||
timeToRead
|
timeToRead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
allFile(
|
||||||
|
filter: { relativeDirectory: { eq: $directory } }
|
||||||
|
sort: { fields: relativePath, order: ASC }
|
||||||
|
) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
relativePath
|
||||||
|
title: childMdx {
|
||||||
|
frontmatter {
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user