Fix the category names.

This commit is contained in:
Vishnu KS
2020-08-23 13:26:16 +05:30
parent 1593c00620
commit 828a68fa75
5 changed files with 19 additions and 28 deletions

View File

@@ -1,12 +1,6 @@
const fs = require("fs") const fs = require("fs")
const categories = JSON.parse(fs.readFileSync("src/data/categories.json")) const categories = JSON.parse(fs.readFileSync("src/data/categories.json"))
var slugify = require('slugify')
function createSlug (categoryName) {
categoryName = categoryName.toLowerCase();
categoryName = categoryName.replace(/ /g, "-");
categoryName = categoryName.replace(/,/g, "");
return categoryName;
};
exports.createPages = async function ({ actions, graphql }) { exports.createPages = async function ({ actions, graphql }) {
const { createPage } = actions const { createPage } = actions
@@ -34,8 +28,9 @@ exports.createPages = async function ({ actions, graphql }) {
} }
`, `,
{categoryName: category.name}) {categoryName: category.name})
console.log(category.name, data.data)
createPage({ createPage({
path: createSlug(category.name), path: slugify(category.name),
component: require.resolve("./src/templates/categoryTemplate.js"), component: require.resolve("./src/templates/categoryTemplate.js"),
context: { context: {
categoryName: category.name, categoryName: category.name,

6
app/package-lock.json generated
View File

@@ -19779,9 +19779,9 @@
} }
}, },
"slugify": { "slugify": {
"version": "1.4.0", "version": "1.4.5",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.4.0.tgz", "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.4.5.tgz",
"integrity": "sha512-FtLNsMGBSRB/0JOE2A0fxlqjI6fJsgHGS13iTuVT28kViI4JjUiNqp/vyis0ZXYcMnpR3fzGNkv+6vRlI2GwdQ==" "integrity": "sha512-WpECLAgYaxHoEAJ8Q1Lo8HOs1ngn7LN7QjXgOLbmmfkcWvosyk4ZTXkTzKyhngK640USTZUlgoQJfED1kz5fnQ=="
}, },
"snapdragon": { "snapdragon": {
"version": "0.8.2", "version": "0.8.2",

View File

@@ -22,7 +22,8 @@
"react-dom": "^16.10.2", "react-dom": "^16.10.2",
"react-helmet": "^5.2.1", "react-helmet": "^5.2.1",
"react-star-rating-component": "^1.4.1", "react-star-rating-component": "^1.4.1",
"react-star-ratings": "^2.3.0" "react-star-ratings": "^2.3.0",
"slugify": "^1.4.5"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.7.0", "eslint": "^7.7.0",

View File

@@ -2,13 +2,7 @@ import React from "react"
import { Nav } from "react-bootstrap" import { Nav } from "react-bootstrap"
import { StaticQuery, graphql } from "gatsby" import { StaticQuery, graphql } from "gatsby"
import "../styles/sidebar.css" import "../styles/sidebar.css"
var slugify = require('slugify')
function createSlug(categoryName) {
categoryName = categoryName.toLowerCase()
categoryName = categoryName.replace(/ /g, "-")
categoryName = categoryName.replace(/,/g, "")
return categoryName
}
export default () => { export default () => {
return ( return (
@@ -20,6 +14,7 @@ export default () => {
node { node {
id id
name name
emoji
} }
} }
} }
@@ -34,8 +29,8 @@ export default () => {
{data.allCategoriesJson.edges.map(function(x, index) { {data.allCategoriesJson.edges.map(function(x, index) {
return ( return (
<Nav.Item> <Nav.Item>
<Nav.Link href={createSlug(x.node.name)}> <Nav.Link href={slugify(x.node.name)}>
{x.node.name} {x.node.emoji} {x.node.name}
</Nav.Link> </Nav.Link>
</Nav.Item> </Nav.Item>
) )

View File

@@ -1,18 +1,21 @@
[ [
{ {
"name": "🚀 Startups and Business" "name": "Startups and Business",
"emoji": "🚀"
}, },
{ {
"name": "☯️ Philosophy and Psychology" "name": "Philosophy And Psychology",
"emoji": "☯️"
}, },
{ {
"name": "👩🏾 Autobiographies and Biographies" "name": "Autobiographies and Biographies",
"emoji": "👩🏾"
}, },
{ {
"name": "History" "name": "History"
}, },
{ {
"name": "Evolution, Science and Medicine" "name": "Science and Medicine"
}, },
{ {
"name": "Logic and Problem Solving" "name": "Logic and Problem Solving"
@@ -38,9 +41,6 @@
{ {
"name": "Theater and Film" "name": "Theater and Film"
}, },
{
"name": "Fiction"
},
{ {
"name": "Health" "name": "Health"
}, },