From b4cde4c777668aedefe253b372480f203fb15199 Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Sat, 22 Aug 2020 23:06:37 +0530 Subject: [PATCH] Make category pages work. --- app/gatsby-node.js | 25 +++++++++--- app/src/components/sidebar.js | 38 ++++++++++++++++++ app/src/data/categories.json | 56 +++++++++++++++++++++++++++ app/src/styles/sidebar.css | 27 +++++++++++++ app/src/templates/categoryTemplate.js | 14 +++++++ 5 files changed, 154 insertions(+), 6 deletions(-) create mode 100644 app/src/components/sidebar.js create mode 100644 app/src/data/categories.json create mode 100644 app/src/styles/sidebar.css create mode 100644 app/src/templates/categoryTemplate.js diff --git a/app/gatsby-node.js b/app/gatsby-node.js index 2f42665..05a5668 100644 --- a/app/gatsby-node.js +++ b/app/gatsby-node.js @@ -1,7 +1,20 @@ -/** - * Implement Gatsby's Node APIs in this file. - * - * See: https://www.gatsbyjs.org/docs/node-apis/ - */ +const fs = require("fs") +const categories = JSON.parse(fs.readFileSync("src/data/categories.json")) -// You can delete this file if you're not using it +function createSlug (categoryName) { + const categoryNameLower = categoryName.toLowerCase(); + return categoryNameLower.replace(" ", "-"); +}; + +exports.createPages = ({ actions }) => { + const { createPage } = actions + categories.forEach(category => { + createPage({ + path: createSlug(category.name), + component: require.resolve("./src/templates/categoryTemplate.js"), + context: { + categoryName: category.name + }, + }) + }) +} diff --git a/app/src/components/sidebar.js b/app/src/components/sidebar.js new file mode 100644 index 0000000..14b613a --- /dev/null +++ b/app/src/components/sidebar.js @@ -0,0 +1,38 @@ +import React from "react"; +import { Nav } from "react-bootstrap"; +import { StaticQuery, graphql } from "gatsby" +import '../styles/sidebar.css' + +export default () => { + return ( + ( + + )} + /> + ); +}; + diff --git a/app/src/data/categories.json b/app/src/data/categories.json new file mode 100644 index 0000000..c3146f6 --- /dev/null +++ b/app/src/data/categories.json @@ -0,0 +1,56 @@ +[ + { + "name": "Startups and Business" + }, + { + "name": "Philosophy and Psychology" + }, + { + "name": "Autobiographies and Biographies" + }, + { + "name": "History" + }, + { + "name": "Evolution, Science and Medicine" + }, + { + "name": "Logic and Problem Solving" + }, + { + "name": "Politics" + }, + { + "name": "Economics" + }, + { + "name": "Gender" + }, + { + "name": "Sexuality" + }, + { + "name": "Education" + }, + { + "name": "Writing" + }, + { + "name": "Theater and Film" + }, + { + "name": "Fiction" + }, + { + "name": "Health" + }, + { + "name": "Travel" + }, + { + "name": "Language" + }, + { + "name": "Nature" + } +] \ No newline at end of file diff --git a/app/src/styles/sidebar.css b/app/src/styles/sidebar.css new file mode 100644 index 0000000..71c962b --- /dev/null +++ b/app/src/styles/sidebar.css @@ -0,0 +1,27 @@ +.sidebar { + position: fixed; + top: 0; + bottom: 0; + left: 0; + min-height: 100vh !important; + padding: 48px 0 0; + box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1); +} +#sidebar-wrapper{ + min-height: 100vh !important; + width: 100vw; + margin-left: -1rem; + -webkit-transition: margin .25s ease-out; + -moz-transition: margin .25s ease-out; + -o-transition: margin .25s ease-out; + transition: margin .25s ease-out; +} +#sidebar-wrapper .sidebar-heading { + padding: 0.875rem 1.25rem; + font-size: 1.2rem; +} + +#page-content-wrapper { + min-width: 0; + width: 100%; +} \ No newline at end of file diff --git a/app/src/templates/categoryTemplate.js b/app/src/templates/categoryTemplate.js new file mode 100644 index 0000000..593e7c1 --- /dev/null +++ b/app/src/templates/categoryTemplate.js @@ -0,0 +1,14 @@ +import React from "react"; +import { Link } from "gatsby"; + +const basicTemplate = props => { + const { pageContext } = props + const { categoryName } = pageContext + + return ( +
+ {categoryName} +
+ ) +} +export default basicTemplate