Generating a github link for each of the markdown files (#29)

Generating a github link for each of the markdown files
This commit is contained in:
Jean-Philippe Sirois
2019-07-29 22:44:58 -04:00
committed by GitHub
2 changed files with 20 additions and 0 deletions
+8
View File
@@ -62,6 +62,14 @@ exports.onCreateNode = async ({ node, getNode, actions }) => {
const { frontmatter } = node
const isDoc = Boolean(!frontmatter.path)
const githubLink = helper.findMarkdownLink(node.fileAbsolutePath)
createNodeField({
node,
name: "githubLink",
value: githubLink,
})
if (!isDoc) {
return
}
+12
View File
@@ -1,5 +1,17 @@
const DEFAULT_AVATAR_MODULO = 5
module.exports = {
findMarkdownLink(absolutePath) {
// We're assuming this path isn't going to change
const start = absolutePath.lastIndexOf("src/content")
if (!start) {
throw Error(`Markdown file ${absolutePath} is outside of src/content`)
}
const route = absolutePath.slice(start)
// Same as this
return `https://github.com/the-programmers-hangout/website/tree/master/${route}`
},
splitHash(identifier) {
const hashLocation = identifier.lastIndexOf("#")