Skip to content
This repository was archived by the owner on Jan 1, 2022. It is now read-only.

Commit dd2ea66

Browse files
committed
feat: Added edit link to MDX pages
1 parent b8844d9 commit dd2ea66

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/components/layouts/default.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import React from 'react'
22
import BreadCrumbs from '../breadcrumbs'
33
import PrevNext from '../prev-next'
4+
import EditIcon from '@material-ui/icons/Edit'
5+
import IconButton from '@material-ui/core/IconButton'
46
import './default.scss'
57

8+
const EditLink = ({edit=false}) => edit
9+
? <IconButton
10+
className='editpencil'
11+
href={`https://github.com/freesewing/markdown/edit/develop/dev/${edit}/en.md`}
12+
target='_BLANK'
13+
rel='nofollow'
14+
size='small'
15+
title='Edit this page'
16+
><EditIcon /></IconButton>
17+
: null
18+
619
const DefaultLayout = (props) => {
720
return (
821
<div className="layout-wrapper">
@@ -14,7 +27,7 @@ const DefaultLayout = (props) => {
1427
</aside>
1528
<section>
1629
{!props.noCrumbs && <BreadCrumbs crumbs={props.crumbs} pageTitle={props.title} />}
17-
{!props.noTitle && <h1>{props.title}</h1>}
30+
{!props.noTitle && <h1>{props.title}<EditLink edit={props.edit}/></h1>}
1831
<div className={`content ${props.wide ? 'wide' : ''}`}>
1932
{props.children}
2033
<PrevNext prev={props.prev} next={props.next} />

src/components/layouts/default.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ section#mdx table {
3131
}
3232
}
3333

34+
a.editpencil {
35+
margin: 0 0 0 1rem;
36+
}
37+
3438
// Main page content layout
3539
div.layout-wrapper {
3640
width: 100%;

src/pages/_mdx.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Page = props => {
2121
title={props.pageContext.title}
2222
description={node.excerpt}
2323
{...app.treeProps(props.path)}
24+
edit={props.data.allMdx.edges[0].node.parent.relativeDirectory}
2425
>
2526
<Mdx node={props.data.allMdx.edges[0].node} offspring={app.getOffspring(props.path)} />
2627
{props.path === '/tutorials/' && <Tutorials list/>}
@@ -39,6 +40,7 @@ export const pageQuery = graphql`
3940
allMdx(filter: { fileAbsolutePath: { eq: $file } }) {
4041
edges {
4142
node {
43+
parent { ... on File { relativeDirectory } }
4244
body
4345
excerpt
4446
frontmatter {

0 commit comments

Comments
 (0)