Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wonism committed Jul 8, 2018
1 parent 387c64b commit ccb61d1
Show file tree
Hide file tree
Showing 52 changed files with 16,904 additions and 13,919 deletions.
50 changes: 42 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ module.exports = {
},
],
'function-paren-newline': [error, 'consistent'],
'import/no-unresolved': off,
'global-require': off,
'implicit-arrow-linebreak': off,
'import/extensions': off,
'import/no-deprecated': warn,
'import/no-dynamic-require': off,
'import/no-unresolved': off,
'import/no-webpack-loader-syntax': off,
'import/prefer-default-export': off,
indent: off,
'jsx-a11y/anchor-is-valid': off,
'jsx-a11y/click-events-have-key-events': error,
Expand Down Expand Up @@ -56,7 +61,7 @@ module.exports = {
'lodash-fp/preferred-alias': off,
'lodash-fp/use-fp': error,
'max-len': [error, 150, { ignoreComments: true }],
'no-console': error,
'no-console': isProduction ? error : off,
'no-multiple-empty-lines': [error, { max: error, maxEOF: error }],
'no-implicit-coercion': error,
'no-shadow': off,
Expand All @@ -67,13 +72,42 @@ module.exports = {
'react/jsx-filename-extension': [error, { extensions: ['.js', '.jsx'] }],
'react/jsx-no-target-blank': error,
'react/no-typos': error,
'react/no-unescaped-entities': off,
},
parser: 'babel-eslint',
overrides: [{
files: ['src/layouts/index.jsx', 'src/components/Home/index.jsx', 'src/templates/Portfolio.jsx', 'src/templates/Portfolios.jsx'],
rules: {
'global-require': off,
'import/no-dynamic-require': off,
overrides: [
{
files: ['src/components/HigherOrderLayout/index.jsx'],
rules: {
'react/prefer-stateless-function': off,
},
},
{
files: ['src/components/Post/index.jsx', 'src/templates/*.jsx'],
rules: {
'react/no-danger': off,
},
},
{
files: ['src/html.jsx'],
rules: {
'react/prefer-stateless-function': off,
'react/prop-types': off,
'react/no-danger': off,
},
},
{
files: ['src/store/**/*.js'],
rules: {
'react/button-has-type': off,
},
},
{
files: ['src/**/*.test.js'],
rules: {
'max-len': off,
'no-undef': off,
},
},
}],
],
};
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@
- fix bug (post's html)
- remove console
- change eslint rules

## 0.2.0 - 2018-07-08
- migrate `gatsby` into `v2 beta` (from `v2 alpha`)
- add `gatsby` with specific `version` into `peerDependencies`
- use `css` instead of `less`
- update `dependencides`
- `babel`, `redux`, `react` etcetera
2 changes: 1 addition & 1 deletion gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'babel-polyfill';
// import '@babel/polyfill';

export const onClientEntry = () => {
console.log('%cStart Gatsby Advanced Blog!', 'display: block; color: #9f63f0; font-size: 40px;');
Expand Down
2 changes: 0 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ module.exports = {
},
'gatsby-plugin-offline',
'gatsby-plugin-react-helmet',
'gatsby-plugin-styled-components',
'gatsby-plugin-less',
{
resolve: 'gatsby-plugin-manifest',
options: {
Expand Down
88 changes: 52 additions & 36 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require('dotenv').config({
});

const path = require('path');
const fp = require('lodash/fp');
const { flow, isNull, isArray, isString, each, filter, reduce, range, flatten, uniq, includes, get, size } = require('lodash/fp');
const { createFilePath } = require('gatsby-source-filesystem');
const {
CONTENT_PER_PAGE,
POST,
Expand Down Expand Up @@ -66,24 +67,25 @@ exports.createPages = ({ graphql, actions }) => {
}
`).then((result) => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}

const edges = fp.get('data.allMarkdownRemark.edges')(result);
const edges = get('data.allMarkdownRemark.edges')(result);
const tagMatrix = [];
const categoryMatrix = [];

// Create blog posts pages.
fp.each((edge) => {
const frontmatter = fp.get('node.frontmatter')(edge);
each((edge) => {
const frontmatter = get('node.frontmatter')(edge);
const { tags, category, type, hide } = frontmatter;

if (hide !== true) {
if (fp.isArray(tags)) {
if (isArray(tags)) {
tagMatrix.push(tags);
}

if (fp.isString(category)) {
if (isString(category)) {
categoryMatrix.push(category);
}

Expand All @@ -101,7 +103,7 @@ exports.createPages = ({ graphql, actions }) => {
break;
}

if (!fp.isNull(component)) {
if (!isNull(component)) {
createPage({
path: edge.node.frontmatter.path,
component,
Expand All @@ -112,14 +114,14 @@ exports.createPages = ({ graphql, actions }) => {
}
})(edges);

const portfoliosCount = fp.flow(
fp.filter((edge) => {
const frontmatter = fp.get('node.frontmatter')(edge);
const portfoliosCount = flow(
filter((edge) => {
const frontmatter = get('node.frontmatter')(edge);
const { type } = frontmatter;

return type === PORTFOLIO;
}),
fp.size
size
)(edges);

if (portfoliosCount) {
Expand All @@ -131,20 +133,20 @@ exports.createPages = ({ graphql, actions }) => {
});
}

const postsCount = fp.flow(
fp.filter((edge) => {
const frontmatter = fp.get('node.frontmatter')(edge);
const postsCount = flow(
filter((edge) => {
const frontmatter = get('node.frontmatter')(edge);
const { hide, type } = frontmatter;

return !hide && (type || POST) === POST;
}),
fp.size
size
)(edges);
const pagesCount = postsCount ? (Math.ceil(postsCount / CONTENT_PER_PAGE) + 1) : 1;
const pages = fp.range(1, pagesCount);
const pages = range(1, pagesCount);

if (fp.size(pages)) {
fp.each((page) => {
if (size(pages)) {
each((page) => {
createPage({
path: `/pages/${page}`,
component: list,
Expand All @@ -161,26 +163,26 @@ exports.createPages = ({ graphql, actions }) => {
});
}

const tags = fp.flow(
fp.flatten,
fp.uniq
const tags = flow(
flatten,
uniq
)(tagMatrix);

fp.each((tag) => {
const taggedPostCount = fp.reduce((count, edge) => {
const postTags = fp.get('node.frontmatter.tags')(edge);
each((tag) => {
const taggedPostCount = reduce((count, edge) => {
const postTags = get('node.frontmatter.tags')(edge);

if (fp.includes(tag)(postTags)) {
if (includes(tag)(postTags)) {
return count + 1;
}

return count;
}, 0)(edges);
const taggedListCount = taggedPostCount ?
(Math.ceil(taggedPostCount / CONTENT_PER_PAGE) + 1) : 1;
const taggedListPages = fp.range(1, taggedListCount);
const taggedListPages = range(1, taggedListCount);

fp.each((taggedListPage) => {
each((taggedListPage) => {
createPage({
path: `/tags/${tag}/${taggedListPage}`,
component: taggedList,
Expand All @@ -190,26 +192,26 @@ exports.createPages = ({ graphql, actions }) => {
})(taggedListPages);
})(tags);

const categories = fp.flow(
fp.flatten,
fp.uniq
const categories = flow(
flatten,
uniq
)(categoryMatrix);

fp.each((category) => {
const categorizedPostCount = fp.reduce((count, edge) => {
const postCategory = fp.get('node.frontmatter.category')(edge);
each((category) => {
const categorizedPostCount = reduce((count, edge) => {
const postCategory = get('node.frontmatter.category')(edge);

if (fp.includes(category)(postCategory)) {
if (includes(category)(postCategory)) {
return count + 1;
}

return count;
}, 0)(edges);
const categorizedListCount = categorizedPostCount ?
(Math.ceil(categorizedPostCount / CONTENT_PER_PAGE) + 1) : 1;
const categorizedListPages = fp.range(1, categorizedListCount);
const categorizedListPages = range(1, categorizedListCount);

fp.each((categorizedListPage) => {
each((categorizedListPage) => {
createPage({
path: `/categories/${category}/${categorizedListPage}`,
component: categorizedList,
Expand All @@ -222,3 +224,17 @@ exports.createPages = ({ graphql, actions }) => {
);
});
};

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;

if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode });

createNodeField({
name: `slug`,
node,
value,
});
}
};
Loading

0 comments on commit ccb61d1

Please sign in to comment.