Skip to content

Commit

Permalink
docs: allow specifying order via front matter (#3818)
Browse files Browse the repository at this point in the history
* docs: allow specifying order via front matter

* Update article.js

Co-authored-by: Maël Nison <nison.mael@gmail.com>
  • Loading branch information
kidonng and arcanis committed Dec 1, 2021
1 parent 7e8c822 commit 4bf39c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby/content/getting-started/install.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
category: getting-started
path: /getting-started/install
title: "2 - Installation"
title: Installation
description: Yarn's in-depth installation guide.
order: 2
---

## Install Corepack
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/content/getting-started/intro.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
category: getting-started
path: /getting-started
title: "1 - Introduction"
title: Introduction
description: An introduction to Yarn, a package manager for your code.
order: 1
---

Yarn is a package manager for your code. It allows you to use and share code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don't ever have to worry.
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/content/getting-started/usage.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
category: getting-started
path: /getting-started/usage
title: "3 - Usage"
title: Usage
description: A short overview of Yarn's most used commands.
order: 3
---

Now that you have Yarn [installed](/getting-started/install), you can start using it! Here are some of the most common commands you'll need.
Expand Down
25 changes: 20 additions & 5 deletions packages/gatsby/src/templates/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ function getGitPageUrl(postAbsolutePath) {
}

// eslint-disable-next-line arca/no-default-export
export default function Template({data, pageContext: {category}}) {
export default function Template({data}) {
const {allMarkdownRemark, markdownRemark} = data;
const {frontmatter, html, fileAbsolutePath} = markdownRemark;

const orderedItems = [];
const items = [];

for (const {node} of allMarkdownRemark.edges) {
const {path, title, order} = node.frontmatter;
const item = {
to: path,
name: title,
};

if (typeof order === `number`) {
orderedItems[order - 1] = item;
} else {
items.push(item);
}
}

return <>
<Global styles={GlobalStyleOverrides} />
<LayoutContentNav items={allMarkdownRemark.edges.map(({node}) => ({
to: node.frontmatter.path,
name: node.frontmatter.title,
}))}>
<LayoutContentNav items={orderedItems.concat(items)}>
<SEO
title={frontmatter.title}
description={frontmatter.description}
Expand All @@ -56,6 +70,7 @@ export const pageQuery = graphql`
frontmatter {
path
title
order
}
}
}
Expand Down

0 comments on commit 4bf39c9

Please sign in to comment.