Skip to content

Set page layout dynamically #4084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion beta/plugins/md-layout-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fm = require('gray-matter');
const path = require('path');

// Makes mdx in next.js suck less by injecting necessary exports so that
// the docs are still readable on github.
Expand All @@ -15,7 +16,16 @@ const fm = require('gray-matter');
module.exports = async function (src) {
const callback = this.async();
const {content, data} = fm(src);
const layout = data.layout || 'Home';
const pageParentDir = path
.dirname(path.relative('./src/pages', this.resourcePath))
.split(path.sep)
.shift();
const layoutMap = {
blog: 'Post',
learn: 'Learn',
reference: 'API',
};
const layout = layoutMap[pageParentDir] || 'Home';
const code =
`import withLayout from 'components/Layout/Layout${layout}';

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/02/jsfiddle-integration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: JSFiddle Integration
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/05/why-react.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: Why did we build React?
layout: Post
author: [petehunt]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/12/community-roundup.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #1'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/19/community-roundup-2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #2'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/21/react-v0-3-3.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.3.3'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/06/27/community-roundup-3.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #3'
layout: Post
author: [vjeux]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "New in React v0.4: Autobind by Default"
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/07/03/community-roundup-4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #4'
layout: Post
author: [vjeux]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'New in React v0.4: Prop Validation and Default Values'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/07/17/react-v0-4-0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.4.0'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/07/23/community-roundup-5.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #5'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/07/26/react-v0-4-1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.4.1'
layout: Post
author: [zpao]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Use React and JSX in Ruby on Rails'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/08/05/community-roundup-6.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #6'
layout: Post
author: [vjeux]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Use React and JSX in Python Applications'
layout: Post
author: [kmeht]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/08/26/community-roundup-7.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #7'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/09/24/community-roundup-8.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #8'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/10/03/community-roundup-9.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #9'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/10/16/react-v0.5.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.5'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/10/29/react-v0-5-1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.5.1'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/11/06/community-roundup-10.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #10'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/11/18/community-roundup-11.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #11'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/12/18/react-v0.5.2-v0.4.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.5.2, v0.4.2'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/12/19/react-v0.8.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.8'
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/12/23/community-roundup-12.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #12'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2013/12/30/community-roundup-13.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #13'
layout: Post
author: [vjeux]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React Chrome Developer Tools'
layout: Post
author: [sebmarkbage]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/01/06/community-roundup-14.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #14'
layout: Post
author: [vjeux]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/02/05/community-roundup-15.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #15'
layout: Post
author: [jgebhardt]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/02/15/community-roundup-16.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #16'
layout: Post
author: [jgebhardt]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/02/16/react-v0.9-rc1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.9 RC
layout: Post
author: [sophiebits]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/02/20/react-v0.9.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.9
layout: Post
author: [sophiebits]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/02/24/community-roundup-17.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #17'
layout: Post
author: [jgebhardt]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/03/14/community-roundup-18.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #18'
layout: Post
author: [jgebhardt]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/03/19/react-v0.10-rc1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.10 RC
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/03/21/react-v0.10.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.10
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/03/28/the-road-to-1.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: The Road to 1.0
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/04/04/reactnet.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Use React and JSX in ASP.NET MVC'
layout: Post
author: [Daniel15]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/05/06/flux.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Flux: An Application Architecture for React'
layout: Post
author: [fisherwebdev, jingc]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'One Year of Open-Source React'
layout: Post
author: [chenglou]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/06/27/community-roundup-19.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #19'
layout: Post
author: [chenglou]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/07/13/react-v0.11-rc1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.11 RC
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/07/17/react-v0.11.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.11
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/07/25/react-v0.11.1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.11.1
layout: Post
author: [zpao]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/07/28/community-roundup-20.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #20'
layout: Post
author: [LoukaN]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Flux: Actions and the Dispatcher'
layout: Post
author: [fisherwebdev]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/08/03/community-roundup-21.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #21'
layout: Post
author: [LoukaN]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Introducing the JSX Specification'
layout: Post
author: [sebmarkbage]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/09/12/community-round-up-22.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Community Round-up #22'
layout: Post
author: [LoukaN]
---

Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/09/16/react-v0.11.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: React v0.11.2
layout: Post
author: [zpao]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Testing Flux Applications'
layout: Post
author: [fisherwebdev]
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'Introducing React Elements'
layout: Post
author: [sebmarkbage]
redirect_from:
- 'blog/2014/10/14/introducting-react-elements.html'
Expand Down
1 change: 0 additions & 1 deletion beta/src/pages/blog/2014/10/16/react-v0.12-rc1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: 'React v0.12 RC'
layout: Post
author: [sebmarkbage]
---

Expand Down
Loading