Skip to content

Commit

Permalink
🌟projects and blog posts now actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesjarvis committed Feb 4, 2019
1 parent 6b66c7b commit 73d795e
Show file tree
Hide file tree
Showing 30 changed files with 1,607 additions and 447 deletions.
5 changes: 5 additions & 0 deletions assets/content/about/aboutMe.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
type: about
path: '/'
---

Hi, I'm James.
I'm currently on industrial placement in [Silicon Valley](https://en.wikipedia.org/wiki/Silicon_Valley) at [Cisco Systems](https://www.cisco.com) in between my studies at the [University of Kent](https://www.kent.ac.uk), and between my day to day work I actively contribute to my ongoing projects.
In my spare time you'll probably find me hopping on a cheap plane somewhere, camera in my hand and in search for an adventure.
Expand Down
4 changes: 4 additions & 0 deletions assets/content/blog/blog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Blog",
"about": "This is where I write things. Or at least it will be where I write things, as soon as I start writing things."
}
4 changes: 4 additions & 0 deletions assets/content/projects/projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Projects",
"about": "Here are some of the projects I have worked on and am proud enough of to publicise here."
}
6 changes: 6 additions & 0 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/* eslint-disable import/prefer-default-export */
import './src/styles/global.scss';
import React from 'react';
import { CodeProvider } from './src/components/common/CodeContext';

// eslint-disable-next-line react/prop-types
export const wrapRootElement = ({ element }) => <CodeProvider>{element}</CodeProvider>;
28 changes: 24 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`,
name: `pages`,
path: `${__dirname}/src/pages/`,
},
},
{
Expand All @@ -26,20 +26,40 @@ module.exports = {
path: `${__dirname}/assets/content/about/`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `projects`,
path: `${__dirname}/assets/content/projects/`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `blog`,
path: `${__dirname}/assets/content/blog/`,
},
},
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: 'UA-133320080-1',
trackingId: `UA-133320080-1`,
},
},
{
resolve: 'gatsby-plugin-web-font-loader',
resolve: `gatsby-plugin-web-font-loader`,
options: {
google: {
families: ['Major Mono Display', 'Roboto Mono', 'Titillium Web'],
},
},
},
{
resolve: `gatsby-plugin-favicon`,
options: {
logo: './assets/images/avatar.jpg',
},
},
`gatsby-plugin-react-helmet`,
`gatsby-plugin-sass`,
`gatsby-plugin-sharp`,
Expand Down
73 changes: 73 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const path = require('path');

const { createFilePath } = require(`gatsby-source-filesystem`);

exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
const { createNodeField } = boundActionCreators;
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode, basePath: `pages` });
createNodeField({
node,
name: 'slug',
value: slug,
});

const dirSplit = path.parse(slug).dir.split(path.sep);
if (dirSplit.length > 0 && dirSplit[0] === '') {
dirSplit.shift(); // because path starts with /, '' is always at position 0
}

let type = 'page';
switch (dirSplit[0]) {
case 'projects':
type = 'project';
break;
case 'blog':
type = 'post';
break;
}

createNodeField({
node,
name: 'type',
value: type,
});
}
};

exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;

return new Promise((resolve, reject) => {
graphql(`
{
allMarkdownRemark {
edges {
node {
fields {
slug
type
}
}
}
}
}
`).then(result => {
result.data.allMarkdownRemark.edges.map(({ node }) => {
const templatePath =
node.fields.type === 'project'
? './src/templates/project.jsx'
: './src/templates/blogPost.jsx';
createPage({
path: node.fields.slug,
component: path.resolve(templatePath),
context: {
// Data passed to context is available in page queries as GraphQL variables.
slug: node.fields.slug,
},
});
});
resolve();
});
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@fortawesome/react-fontawesome": "^0.1.4",
"gatsby": "^2.0.76",
"gatsby-image": "^2.0.29",
"gatsby-plugin-favicon": "^3.1.5",
"gatsby-plugin-google-analytics": "^2.0.10",
"gatsby-plugin-react-helmet": "^3.0.5",
"gatsby-plugin-sass": "^2.0.8",
Expand Down
59 changes: 59 additions & 0 deletions src/components/common/CodeContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import PropTypes from 'prop-types';

const defaultState = {
language: 'java',
changeLanguage: () => {},
};

const CodeContext = React.createContext(defaultState);

class CodeProvider extends React.Component {
state = {
language: 'java',
};

changeLanguage = language => {
let newLanguage = '';
switch (language.toLowerCase()) {
case 'javascript':
newLanguage = 'javascript';
break;
case 'react':
newLanguage = 'javascript';
break;
case 'python':
newLanguage = 'python';
break;
case 'java':
newLanguage = 'java';
break;
default:
newLanguage = 'java';
}
this.setState({ language: newLanguage });
};

render() {
const { children } = this.props;
const { language } = this.state;
return (
<CodeContext.Provider
value={{
language,
changeLanguage: this.changeLanguage,
}}
>
{children}
</CodeContext.Provider>
);
}
}

CodeProvider.propTypes = {
children: PropTypes.any.isRequired,
};

export default CodeContext;

export { CodeProvider };
17 changes: 8 additions & 9 deletions src/components/common/header/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react';
import NavBar from './navbar';
import '../../../styles/codestyle.scss';
import './header.scss';
import CodeContext from '../CodeContext';

export default class Header extends React.Component {
render() {
return (
<header className="translucent">
<NavBar language="java" />
</header>
);
}
}
const Header = () => (
<header className="translucent">
<CodeContext.Consumer>{({ language }) => <NavBar language={language} />}</CodeContext.Consumer>
</header>
);

export default Header;
36 changes: 17 additions & 19 deletions src/components/common/header/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ import { Link } from 'gatsby';
import PropTypes from 'prop-types';
import './header.scss';

export default class NavBar extends React.Component {
render() {
return (
<nav className={`navbar ${this.props.language}`}>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/projects">Projects</Link>
</li>
<li>
<Link to="/blog">Blog</Link>
</li>
</ul>
</nav>
);
}
}
const NavBar = ({ language }) => (
<nav className={`navbar ${language}`}>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/projects">Projects</Link>
</li>
<li>
<Link to="/blog">Blog</Link>
</li>
</ul>
</nav>
);

NavBar.propTypes = {
language: PropTypes.string.isRequired,
};

export default NavBar;
19 changes: 19 additions & 0 deletions src/components/containers/complexWrapper.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';
import Me from '../me/me';
import './complexWrapper.scss';

const ComplexWrapper = ({ children }) => (
<div id={'content'}>
<aside id={'content_left'}>
<Me />
</aside>
<section id={'main'}>{children}</section>
</div>
);

ComplexWrapper.propTypes = {
children: PropTypes.any.isRequired,
};

export default ComplexWrapper;
36 changes: 36 additions & 0 deletions src/components/containers/complexWrapper.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#content {
display: flex;
position: relative;
margin: 0;

$leftWidth: 300px;

letter-spacing: 0.15ch;

@media (min-width: 750px) {
#content_left {
width: $leftWidth;
position: fixed;
z-index: 1;
height: 100%;
}
#main {
width: 100%;
margin-top: 80px;
margin-bottom: 50px;
padding-left: $leftWidth;
max-width: 800px;
}
}
@media (max-width: 750px) {
#content_left {
display: none;
}
#main {
width: 100%;
margin-top: 80px;
margin-bottom: 50px;
padding: 0 40px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import PropTypes from 'prop-types';
import { library } from '@fortawesome/fontawesome-svg-core';
import { fab } from '@fortawesome/free-brands-svg-icons';
import { faAngleDown } from '@fortawesome/free-solid-svg-icons';
import Header from './common/header/header';
import Footer from './common/footer/footer';
import SEO from './common/seo';
import Header from '../common/header/header';
import Footer from '../common/footer/footer';
import SEO from '../common/seo';
import './wrapper.scss';

library.add(faAngleDown, fab);

const Wrapper = ({ title, children }) => (
<div id={'body'}>
<div id={'wrapper'}>
<SEO title={title} />
<Header />
{children}
Expand Down
4 changes: 4 additions & 0 deletions src/components/containers/wrapper.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#wrapper {
// margin: 0 20px;
height: 100vh;
}
Loading

0 comments on commit 73d795e

Please sign in to comment.