This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(attributes): add link to edit article into article footer (close #…
…92)
- Loading branch information
hitsuji_no_shippo
committed
Jan 8, 2020
1 parent
b024821
commit b19efb6
Showing
8 changed files
with
207 additions
and
6 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
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,75 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { graphql, useStaticQuery } from 'gatsby'; | ||
|
||
import minimatch from 'minimatch'; | ||
|
||
const Footer = ({post}) => { | ||
const { | ||
site: { | ||
siteMetadata: { repository, articles }, | ||
}, | ||
} = useStaticQuery( | ||
graphql` | ||
query { | ||
site { | ||
siteMetadata { | ||
repository { | ||
url | ||
} | ||
articles { | ||
dir | ||
filePath { | ||
Asciidoc | ||
} | ||
isOtherRepositroy | ||
ignore | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
); | ||
|
||
// Can't use `null` in siteMetadata. #103 | ||
if (articles.dir === '' || articles.filePath === '') { | ||
return null; | ||
} | ||
|
||
const filePath = (() => { | ||
let value = post; | ||
|
||
articles.filePath[post.internal.type].split('.').some(path => { | ||
value = Object.prototype.hasOwnProperty.call(value, path) | ||
? value[path] | ||
: null; | ||
|
||
return Object.prototype.toString.call(value) !== `[object Object]`; | ||
}); | ||
|
||
return typeof value === 'string' ? value : null; | ||
})(); | ||
|
||
if (!filePath || articles.ignore.some(pattern => minimatch(filePath, pattern))) { | ||
return null; | ||
} | ||
|
||
const articlesDir = `${articles.isOtherRepositroy ? 'https://github.com' : repository.url | ||
}/${articles.dir}`; | ||
|
||
return ( | ||
<p> | ||
<a href={`${articlesDir}/edit/master/${filePath}`} | ||
target="_blank" | ||
rel="noopener noreferrer"> | ||
Edit on GitHub | ||
</a> | ||
</p> | ||
); | ||
} | ||
|
||
Footer.propTypes = { | ||
post: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default Footer; |
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