From 4233a96ad82091110f3aae336698963314ad7bf4 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 18 May 2021 18:12:54 +0200 Subject: [PATCH] Improvement: Rename variables --- src/templates/MarkdownList.jsx | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/templates/MarkdownList.jsx b/src/templates/MarkdownList.jsx index 69a769ec..309a5e1c 100644 --- a/src/templates/MarkdownList.jsx +++ b/src/templates/MarkdownList.jsx @@ -10,9 +10,9 @@ import sidebarStyles from '../components/Sidebar.module.scss' export default function MarkdownList({ pageContext }) { const modules = {} - const nested = {} + const nestedModules = {} - function generatedNested(obj, keyPath, value) { + function generatedNested(obj, keyPath, node) { var lastKeyIndex = keyPath.length - 1 for (var i = 0; i < lastKeyIndex; ++i) { var key = keyPath[i] @@ -23,8 +23,8 @@ export default function MarkdownList({ pageContext }) { } if (!obj[keyPath[lastKeyIndex]]) { obj[keyPath[lastKeyIndex]] = { - id: value.id, - label: value.frontmatter.title + id: node.id, + label: node.frontmatter.title } } } @@ -40,7 +40,7 @@ export default function MarkdownList({ pageContext }) { } modules[key].push(node) - generatedNested(nested, modulePath, node) + generatedNested(nestedModules, modulePath, node) }) const moduleKeys = Object.keys(modules).sort() @@ -61,28 +61,28 @@ export default function MarkdownList({ pageContext }) { } } - const g = (title, nested) => { - if (nested.id) { + const generateNestedSidebarList = (title, nestedModules) => { + if (nestedModules.id) { return ( -
  • +
  • changeNodeid(nested.id)} + onClick={() => changeNodeid(nestedModules.id)} style={{ cursor: 'pointer', - color: selectedNodeId === nested.id ? 'black' : '#8b98a9' + color: selectedNodeId === nestedModules.id ? 'black' : '#8b98a9' }} > - {nested.label} + {nestedModules.label}
  • ) } else { - const keys = Object.keys(nested).sort() + const keys = Object.keys(nestedModules).sort() const children = [] children.push(
  • @@ -91,14 +91,16 @@ export default function MarkdownList({ pageContext }) { ) keys.forEach((element) => { children.push( - + ) }) return children } } - const n2 = g(null, nested) + const nestedSidebarList = generateNestedSidebarList(null, nestedModules) return ( @@ -111,7 +113,7 @@ export default function MarkdownList({ pageContext }) {