2019-11-12 04:09:29 +01:00
|
|
|
import React, { StatelessComponent, ReactElement, useEffect } from 'react';
|
2019-11-08 03:40:20 +01:00
|
|
|
import { graphql } from 'gatsby';
|
|
|
|
import SEO from '../components/SEO';
|
|
|
|
import { SingleFileQuery } from '../types';
|
|
|
|
import parseHTML from '../utils/parseHTML';
|
2019-11-12 04:09:29 +01:00
|
|
|
import { setCurrentNode } from '../utils/nodes';
|
2019-11-08 03:40:20 +01:00
|
|
|
|
|
|
|
const Template: StatelessComponent<SingleFileQuery> = (result): ReactElement => {
|
2019-11-12 04:09:29 +01:00
|
|
|
const currentNode = result.data.silverstripeDocument;
|
2019-11-08 03:40:20 +01:00
|
|
|
const { html } = currentNode.parent;
|
2019-11-12 04:09:29 +01:00
|
|
|
const { title, slug } = currentNode;
|
2019-11-18 05:51:57 +01:00
|
|
|
const { relativePath, gitRemote: { ref, webLink } } = currentNode.parent.parent;
|
2019-11-08 03:40:20 +01:00
|
|
|
const editLink = `${webLink}/edit/${ref}/${relativePath}`;
|
2019-11-12 04:09:29 +01:00
|
|
|
useEffect(() => {
|
|
|
|
setCurrentNode(slug);
|
|
|
|
}, []);
|
2019-11-08 03:40:20 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SEO title={title} />
|
|
|
|
{parseHTML(html)}
|
|
|
|
<div className="github-edit">
|
|
|
|
<a target="_blank" href={editLink} title="Edit on Github">
|
|
|
|
<i className="fas fa-pen fa-fw" />{` `}
|
|
|
|
Edit on Github
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Template;
|
|
|
|
|
|
|
|
export const pageQuery = graphql`
|
|
|
|
query DocsBySlug($slug: String!) {
|
|
|
|
silverstripeDocument(slug: { eq: $slug }) {
|
|
|
|
parent {
|
|
|
|
... on MarkdownRemark {
|
|
|
|
html
|
|
|
|
parent {
|
|
|
|
... on File {
|
|
|
|
relativePath
|
|
|
|
gitRemote {
|
|
|
|
ref
|
|
|
|
webLink
|
2019-11-12 04:09:29 +01:00
|
|
|
sourceInstanceName
|
2019-11-08 03:40:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
title
|
2019-11-12 04:09:29 +01:00
|
|
|
slug
|
2019-11-08 03:40:20 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
;
|