Skip to content

Commit

Permalink
feat: update blog
Browse files Browse the repository at this point in the history
7sferry committed Mar 25, 2020
1 parent 2ec583b commit 8d980c6
Showing 20 changed files with 991 additions and 906 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ typings/

# dotenv environment variables file
.env
.env.build

# gatsby files
.cache/
8 changes: 8 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"use strict";

const siteConfig = require("./config");
const contentfulConfig = {
spaceId: process.env.SPACEID,
accessToken: process.env.TOKEN,
};

module.exports = {
siteMetadata: {
@@ -24,6 +28,10 @@ module.exports = {
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
`gatsby-plugin-minify`,
{
resolve: 'gatsby-source-contentful',
options: contentfulConfig,
},
{
resolve: `gatsby-source-filesystem`,
options: {
196 changes: 135 additions & 61 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -2,86 +2,160 @@ const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);
const _ = require("lodash");

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

// exports.createPages = ({ graphql, actions }) => {
// const { createPage } = actions;
// return graphql(`
// {
// allMarkdownRemark {
// edges {
// node {
// frontmatter {
// tags
// }
// fields {
// slug
// }
// }
// }
// }
// }
// `).then(result => {
// const posts = result.data.allMarkdownRemark.edges;
// posts.forEach(({ node }) => {
// createPage({
// path: node.fields.slug,
// component: path.resolve(`./src/templates/blog-post.js`),
// context: {
// // Data passed to context is available
// // in page queries as GraphQL variables.
// slug: node.fields.slug,
// },
// });
// });
//
// // Tag pages:
// let tags = [];
// // Iterate through each post, putting all found tags into `tags`
// _.each(posts, edge => {
// if (_.get(edge, "node.frontmatter.tags")) {
// tags = tags.concat(edge.node.frontmatter.tags);
// }
// });
//
// // Eliminate duplicate tags
// tags = _.uniq(tags);
//
// // Make tag pages
// tags.forEach(tag => {
// createPage({
// path: `/tags/${_.kebabCase(tag)}/`,
// component: path.resolve("src/templates/tag.js"),
// context: {
// tag,
// },
// });
// });
//
// const postsPerPage = 5;
// const numPages = Math.ceil(posts.length / postsPerPage);
//
// Array.from({ length: numPages }).forEach((_, i) => {
// createPage({
// path: i === 0 ? `/` : `/${i + 1}`,
// component: path.resolve("./src/templates/post-list.js"),
// context: {
// limit: postsPerPage,
// skip: i * postsPerPage,
// numPages,
// currentPage: i + 1,
// },
// });
// });
// });
// };

exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return graphql(`
{
allMarkdownRemark {
edges {
node {
frontmatter {
tags
}
fields {
slug

return new Promise((resolve, reject) => {
const blogPost = path.resolve("./src/templates/blog-post.js");
resolve(
graphql(
`
{
allContentfulBlogPost {
edges {
node {
tags
title
slug
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}
}
}
`).then(result => {
const posts = result.data.allMarkdownRemark.edges;
posts.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/blog-post.js`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.fields.slug,
},
});
});

// Tag pages:
let tags = [];
const posts = result.data.allContentfulBlogPost.edges;
posts.forEach(post => {
createPage({
path: `/blog/${post.node.slug}/`,
component: blogPost,
context: {
slug: post.node.slug,
},
});
});

const postsPerPage = 2;
const numPages = Math.ceil(posts.length / postsPerPage);
Array.from({ length: numPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/` : `/${i + 1}`,
component: path.resolve("./src/pages/index.js"),
context: {
limit: postsPerPage,
skip: i * postsPerPage,
},
});
});
// // Tag pages:
let tags = new Set();
// Iterate through each post, putting all found tags into `tags`
_.each(posts, edge => {
if (_.get(edge, "node.frontmatter.tags")) {
tags = tags.concat(edge.node.frontmatter.tags);
if (_.get(edge, "node.tags")) {
edge.node.tags.forEach(tag => {
tags.add(tag);
})
}
});

// Eliminate duplicate tags
tags = _.uniq(tags);

// Make tag pages
tags.forEach(tag => {
createPage({
path: `/tags/${_.kebabCase(tag)}/`,
component: path.resolve("src/templates/tag.js"),
component: path.resolve("src/pages/index.js"),
context: {
tag,
},
});
});

const postsPerPage = 5;
const numPages = Math.ceil(posts.length / postsPerPage);

Array.from({ length: numPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/` : `/${i + 1}`,
component: path.resolve("./src/templates/post-list.js"),
context: {
limit: postsPerPage,
skip: i * postsPerPage,
numPages,
currentPage: i + 1,
},
});
});
})
);
});
};
6 changes: 3 additions & 3 deletions graphql.config.json
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@
"README_endpoints": "A list of GraphQL endpoints that can be queried from '.graphql' files in the IDE",
"endpoints" : [
{
"name": "Default (http://localhost:8080/graphql)",
"url": "http://localhost:8080/graphql",
"name": "Default (http://localhost:8000/___graphql)",
"url": "http://localhost:8000/___graphql",
"options" : {
"headers": {
"user-agent" : "JS GraphQL"
@@ -35,4 +35,4 @@
}
]

}
}
8 changes: 8 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"build": {
"env": {
"SPACEID": "@spaceid",
"TOKEN": "@token"
}
}
}
22 changes: 16 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/CustomShareBlock.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const CustomShareBlock = props => {
return (
<div className="mt-4">
<ShareBlockStandard {...shareBlockProps} />
<p className="text-center"><i>If you like it, share it!</i></p>
<p className="text-center"><i>Share it if you like it!</i></p>
</div>
)
};
26 changes: 26 additions & 0 deletions src/components/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/************************
* Made by [MR Ferry™] *
* on March 2020 *
************************/

import React from "react";
import { Link } from "gatsby";

export const getTechTags = tags => {
const techTags = [];
if(tags !== undefined && tags !== null){
tags.forEach((tag, i) =>{
techTags.push(
<span key={tag}>
{i > 0 ? ", " : ""}
<Link to={`/tags/${tag}/`}>{tag}</Link>
</span>
);
});
}
return techTags;
};

export const getPlurals = count => {
return count > 1 ? "s" : ""
};
8 changes: 4 additions & 4 deletions src/components/header/MobileBio.js
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ const MobileBio = (props) => {
<Mobsoc contacts={props.contacts}/>
<div className="mobile-bio-main">
<img src={bioImg} className="ml-4 mt-2" style={{ maxWidth: `75px`, maxHeight: `75px`, borderRadius: `50%`,boxShadow: `1px 1px 3px`}} alt="author-pic" />
<p className="ml-3 mt-2 mb-0">
<h4 className="mb-1">{props.author}</h4>
<h7>{props.tagline}</h7>
</p>
<div className="ml-3 mt-2 mb-0">
<p className="mb-1">{props.author}</p>
<small>{props.tagline}</small>
</div>
</div></>
)
};
4 changes: 3 additions & 1 deletion src/components/sidebar/Bio.js
Original file line number Diff line number Diff line change
@@ -10,10 +10,12 @@ const PhotoImage = (
file(relativePath: { eq: "ferry.jpg" }) {
childImageSharp {
fixed(width: 150, quality: 100) {
tracedSVG
width
height
src
srcSet
srcSetWebp
base64
}
}
}
Loading

0 comments on commit 8d980c6

Please sign in to comment.