From 167a8e7638bcbceb44d036a81e8b6888f42f6c20 Mon Sep 17 00:00:00 2001 From: Tom <20648924+moT01@users.noreply.github.com> Date: Thu, 8 Jun 2023 01:28:56 -0500 Subject: [PATCH] refactor: remove dasherize (#50620) --- .gitignore | 4 -- .prettierignore | 4 -- client/gatsby-node.js | 1 + .../components/completion-modal.tsx | 21 ++++--- client/src/utils/get-completion-percentage.ts | 5 +- client/utils/gatsby/challenge-page-creator.js | 5 +- .../build-a-caesars-cipher-project/meta.json | 3 +- .../build-a-cash-register-project/meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../build-a-survey-form-project/meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../build-a-tribute-page-project/meta.json | 3 +- .../meta.json | 3 +- .../build-three-math-games-project/meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../learn-nano-by-building-a-castle/meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../project-euler-problems-1-to-100/meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../meta.json | 3 +- .../top-build-a-recipe-project/meta.json | 3 +- .../meta.json | 3 +- .../_meta/top-learn-css-foundations/meta.json | 3 +- .../top-learn-html-foundations/meta.json | 3 +- curriculum/get-challenges.js | 8 ++- utils/index.ts | 60 +++++-------------- utils/slugs.test.ts | 49 --------------- utils/slugs.ts | 24 -------- 48 files changed, 115 insertions(+), 180 deletions(-) delete mode 100644 utils/slugs.test.ts delete mode 100644 utils/slugs.ts diff --git a/.gitignore b/.gitignore index 675f2b9f6c6..612c9dc555f 100644 --- a/.gitignore +++ b/.gitignore @@ -170,10 +170,6 @@ config/superblocks.js config/superblocks.test.js ### Generated utils files ### -utils/block-nameify.js -utils/block-nameify.test.js -utils/slugs.js -utils/slugs.test.js utils/index.js utils/get-lines.js utils/get-lines.test.js diff --git a/.prettierignore b/.prettierignore index 0699a7fe9c3..220a81c610b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,10 +12,6 @@ config/certification-settings.js config/donation-settings.js config/superblocks.js config/superblocks.test.js -utils/block-nameify.js -utils/block-nameify.test.js -utils/slugs.js -utils/slugs.test.js utils/index.js utils/get-lines.js utils/get-lines.test.js diff --git a/client/gatsby-node.js b/client/gatsby-node.js index 311dd807ae9..c1c91a486ec 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -77,6 +77,7 @@ exports.createPages = function createPages({ graphql, actions, reporter }) { block certification challengeType + dashedName fields { slug } diff --git a/client/src/templates/Challenges/components/completion-modal.tsx b/client/src/templates/Challenges/components/completion-modal.tsx index 0b355f496e2..5d9beabf6e0 100644 --- a/client/src/templates/Challenges/components/completion-modal.tsx +++ b/client/src/templates/Challenges/components/completion-modal.tsx @@ -8,7 +8,6 @@ import { withTranslation } from 'react-i18next'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import { dasherize } from '../../../../../utils/slugs'; import Login from '../../../components/Header/components/login'; import { executeGA } from '../../../redux/actions'; import { @@ -40,7 +39,7 @@ const mapStateToProps = createSelector( ( challengeFiles: ChallengeFiles, - { title }: { title: string; id: string }, + { dashedName }: { dashedName: string }, completedChallengesIds: string[], isOpen: boolean, isSignedIn: boolean, @@ -48,7 +47,7 @@ const mapStateToProps = createSelector( message: string ) => ({ challengeFiles, - title, + dashedName, completedChallengesIds, isOpen, isSignedIn, @@ -144,16 +143,20 @@ class CompletionModal extends Component< } render(): JSX.Element { - const { close, isOpen, isSignedIn, message, t, title, submitChallenge } = - this.props; + const { + close, + isOpen, + isSignedIn, + message, + t, + dashedName, + submitChallenge + } = this.props; if (isOpen) { executeGA({ event: 'pageview', pagePath: '/completion-modal' }); } - // normally dashedName should be graphQL queried and then passed around, - // but it's only used to make a nice filename for downloading, so dasherize - // is fine here. - const dashedName = dasherize(title); + return ( dasherize(node.challenge.certification) === certification - )[0] + .filter(node => node.challenge.certification === certification)[0] ?.challenge.tests.map(test => test.id) ?? []; const currentBlockIds = challengeEdges .filter(edge => edge.node.challenge.block === block) diff --git a/client/utils/gatsby/challenge-page-creator.js b/client/utils/gatsby/challenge-page-creator.js index 8b1f2726295..423d7b5c04b 100644 --- a/client/utils/gatsby/challenge-page-creator.js +++ b/client/utils/gatsby/challenge-page-creator.js @@ -1,5 +1,4 @@ const path = require('path'); -const { dasherize } = require('../../../utils/slugs'); const { sortChallengeFiles } = require('../../../utils/sort-challengefiles'); const { challengeTypes, viewTypes } = require('../challenge-types'); @@ -79,6 +78,7 @@ function getTemplateComponent(challengeType) { exports.createChallengePages = function (createPage) { return function ({ node: { challenge } }, index, allChallengeEdges) { const { + dashedName, certification, superBlock, block, @@ -96,6 +96,7 @@ exports.createChallengePages = function (createPage) { component: getTemplateComponent(challengeType), context: { challengeMeta: { + dashedName, certification, superBlock, block, @@ -163,7 +164,7 @@ exports.createBlockIntroPages = function (createPage) { path: slug, component: intro, context: { - block: dasherize(block), + block, slug } }); diff --git a/curriculum/challenges/_meta/build-a-caesars-cipher-project/meta.json b/curriculum/challenges/_meta/build-a-caesars-cipher-project/meta.json index dbf6f9cbde1..918302141c8 100644 --- a/curriculum/challenges/_meta/build-a-caesars-cipher-project/meta.json +++ b/curriculum/challenges/_meta/build-a-caesars-cipher-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Caesars Cipher Project", "isUpcomingChange": true, + "dashedName": "build-a-caesars-cipher-project", "usesMultifileEditor": false, "helpCategory": "JavaScript", "order": 17, @@ -14,4 +15,4 @@ "Build a Caesars Cipher" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-cash-register-project/meta.json b/curriculum/challenges/_meta/build-a-cash-register-project/meta.json index 9233b69cb21..444989aa820 100644 --- a/curriculum/challenges/_meta/build-a-cash-register-project/meta.json +++ b/curriculum/challenges/_meta/build-a-cash-register-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Cash Register Project", "isUpcomingChange": true, + "dashedName": "build-a-cash-register-project", "usesMultifileEditor": false, "helpCategory": "JavaScript", "order": 14, @@ -14,4 +15,4 @@ "Build a Cash Register" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-celestial-bodies-database-project/meta.json b/curriculum/challenges/_meta/build-a-celestial-bodies-database-project/meta.json index cdcf4b18a56..dd8a00bbde6 100644 --- a/curriculum/challenges/_meta/build-a-celestial-bodies-database-project/meta.json +++ b/curriculum/challenges/_meta/build-a-celestial-bodies-database-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Celestial Bodies Database Project", "isUpcomingChange": false, + "dashedName": "build-a-celestial-bodies-database-project", "order": 2, "helpCategory": "Backend Development", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Celestial Bodies Database" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-data-graph-explorer-project/meta.json b/curriculum/challenges/_meta/build-a-data-graph-explorer-project/meta.json index c4a23874cc5..9d468a936a9 100644 --- a/curriculum/challenges/_meta/build-a-data-graph-explorer-project/meta.json +++ b/curriculum/challenges/_meta/build-a-data-graph-explorer-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Data Graph Explorer Project", "isUpcomingChange": false, + "dashedName": "build-a-data-graph-explorer-project", "order": 19, "helpCategory": "Python", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Data Graph Explorer" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-financial-calculator-project/meta.json b/curriculum/challenges/_meta/build-a-financial-calculator-project/meta.json index 91bb5c23be5..9db6b35884a 100644 --- a/curriculum/challenges/_meta/build-a-financial-calculator-project/meta.json +++ b/curriculum/challenges/_meta/build-a-financial-calculator-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Financial Calculator Project", "isUpcomingChange": false, + "dashedName": "build-a-financial-calculator-project", "order": 17, "helpCategory": "Python", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Financial Calculator" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-graphing-calculator-project/meta.json b/curriculum/challenges/_meta/build-a-graphing-calculator-project/meta.json index 140cfee6912..e2c47f2df1d 100644 --- a/curriculum/challenges/_meta/build-a-graphing-calculator-project/meta.json +++ b/curriculum/challenges/_meta/build-a-graphing-calculator-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Graphing Calculator Project", "isUpcomingChange": false, + "dashedName": "build-a-graphing-calculator-project", "order": 11, "helpCategory": "Python", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Graphing Calculator" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-multi-function-calculator-project/meta.json b/curriculum/challenges/_meta/build-a-multi-function-calculator-project/meta.json index 5e47c1a0e13..75461dfd971 100644 --- a/curriculum/challenges/_meta/build-a-multi-function-calculator-project/meta.json +++ b/curriculum/challenges/_meta/build-a-multi-function-calculator-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Multi-Function Calculator Project", "isUpcomingChange": false, + "dashedName": "build-a-multi-function-calculator-project", "order": 6, "helpCategory": "Python", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Multi-Function Calculator" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-number-guessing-game-project/meta.json b/curriculum/challenges/_meta/build-a-number-guessing-game-project/meta.json index e1152f5adc9..b3b795f9064 100644 --- a/curriculum/challenges/_meta/build-a-number-guessing-game-project/meta.json +++ b/curriculum/challenges/_meta/build-a-number-guessing-game-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Number Guessing Game Project", "isUpcomingChange": false, + "dashedName": "build-a-number-guessing-game-project", "order": 13, "helpCategory": "Backend Development", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Number Guessing Game" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-palindrome-checker-project/meta.json b/curriculum/challenges/_meta/build-a-palindrome-checker-project/meta.json index c7f813364b1..6dd561122e6 100644 --- a/curriculum/challenges/_meta/build-a-palindrome-checker-project/meta.json +++ b/curriculum/challenges/_meta/build-a-palindrome-checker-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Palindrome Checker Project", "isUpcomingChange": true, + "dashedName": "build-a-palindrome-checker-project", "usesMultifileEditor": false, "helpCategory": "JavaScript", "order": 3, @@ -14,4 +15,4 @@ "Build a Palindrome Checker" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-periodic-table-database-project/meta.json b/curriculum/challenges/_meta/build-a-periodic-table-database-project/meta.json index e6efb4a0039..ccdd74459e2 100644 --- a/curriculum/challenges/_meta/build-a-periodic-table-database-project/meta.json +++ b/curriculum/challenges/_meta/build-a-periodic-table-database-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Periodic Table Database Project", "isUpcomingChange": false, + "dashedName": "build-a-periodic-table-database-project", "order": 12, "helpCategory": "Backend Development", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Periodic Table Database" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-personal-portfolio-webpage-project/meta.json b/curriculum/challenges/_meta/build-a-personal-portfolio-webpage-project/meta.json index 4bfa867903c..f5c0dfe1785 100644 --- a/curriculum/challenges/_meta/build-a-personal-portfolio-webpage-project/meta.json +++ b/curriculum/challenges/_meta/build-a-personal-portfolio-webpage-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Personal Portfolio Webpage Project", "isUpcomingChange": false, + "dashedName": "build-a-personal-portfolio-webpage-project", "usesMultifileEditor": true, "helpCategory": "HTML-CSS", "order": 19, @@ -14,4 +15,4 @@ "Build a Personal Portfolio Webpage" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-product-landing-page-project/meta.json b/curriculum/challenges/_meta/build-a-product-landing-page-project/meta.json index abae168424c..af974364507 100644 --- a/curriculum/challenges/_meta/build-a-product-landing-page-project/meta.json +++ b/curriculum/challenges/_meta/build-a-product-landing-page-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Product Landing Page Project", "isUpcomingChange": false, + "dashedName": "build-a-product-landing-page-project", "usesMultifileEditor": true, "helpCategory": "HTML-CSS", "order": 16, @@ -14,4 +15,4 @@ "Build a Product Landing Page" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-roman-numeral-converter-project/meta.json b/curriculum/challenges/_meta/build-a-roman-numeral-converter-project/meta.json index 4bdfd14c29c..4320f0676c2 100644 --- a/curriculum/challenges/_meta/build-a-roman-numeral-converter-project/meta.json +++ b/curriculum/challenges/_meta/build-a-roman-numeral-converter-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Roman Numeral Converter Project", "isUpcomingChange": true, + "dashedName": "build-a-roman-numeral-converter-project", "usesMultifileEditor": false, "helpCategory": "JavaScript", "order": 6, @@ -14,4 +15,4 @@ "Build a Roman Numeral Converter" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-salon-appointment-scheduler-project/meta.json b/curriculum/challenges/_meta/build-a-salon-appointment-scheduler-project/meta.json index 8185305f94d..3c33ecca2f1 100644 --- a/curriculum/challenges/_meta/build-a-salon-appointment-scheduler-project/meta.json +++ b/curriculum/challenges/_meta/build-a-salon-appointment-scheduler-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Salon Appointment Scheduler Project", "isUpcomingChange": false, + "dashedName": "build-a-salon-appointment-scheduler-project", "order": 9, "helpCategory": "Backend Development", "time": "30 hours", @@ -13,4 +14,4 @@ "Build a Salon Appointment Scheduler" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-survey-form-project/meta.json b/curriculum/challenges/_meta/build-a-survey-form-project/meta.json index 032a879e6e3..959bab6a4d2 100644 --- a/curriculum/challenges/_meta/build-a-survey-form-project/meta.json +++ b/curriculum/challenges/_meta/build-a-survey-form-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Survey Form Project", "isUpcomingChange": false, + "dashedName": "build-a-survey-form-project", "usesMultifileEditor": true, "helpCategory": "HTML-CSS", "order": 4, @@ -14,4 +15,4 @@ "Build a Survey Form" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-technical-documentation-page-project/meta.json b/curriculum/challenges/_meta/build-a-technical-documentation-page-project/meta.json index fe2bb83360d..1d93db157b9 100644 --- a/curriculum/challenges/_meta/build-a-technical-documentation-page-project/meta.json +++ b/curriculum/challenges/_meta/build-a-technical-documentation-page-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Technical Documentation Page Project", "isUpcomingChange": false, + "dashedName": "build-a-technical-documentation-page-project", "usesMultifileEditor": true, "helpCategory": "HTML-CSS", "order": 13, @@ -14,4 +15,4 @@ "Build a Technical Documentation Page" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-telephone-number-validator-project/meta.json b/curriculum/challenges/_meta/build-a-telephone-number-validator-project/meta.json index e6322749b1e..93fd2bd661e 100644 --- a/curriculum/challenges/_meta/build-a-telephone-number-validator-project/meta.json +++ b/curriculum/challenges/_meta/build-a-telephone-number-validator-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Telephone Number Validator Project", "isUpcomingChange": true, + "dashedName": "build-a-telephone-number-validator-project", "usesMultifileEditor": false, "helpCategory": "JavaScript", "order": 10, @@ -14,4 +15,4 @@ "Build a Telephone Number Validator" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-tribute-page-project/meta.json b/curriculum/challenges/_meta/build-a-tribute-page-project/meta.json index c0903b18388..1481a53dc54 100644 --- a/curriculum/challenges/_meta/build-a-tribute-page-project/meta.json +++ b/curriculum/challenges/_meta/build-a-tribute-page-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a Tribute Page Project", "isUpcomingChange": false, + "dashedName": "build-a-tribute-page-project", "usesMultifileEditor": true, "helpCategory": "HTML-CSS", "order": 9, @@ -14,4 +15,4 @@ "Build a Tribute Page" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-a-world-cup-database-project/meta.json b/curriculum/challenges/_meta/build-a-world-cup-database-project/meta.json index 73991429da6..767e8b0bcd2 100644 --- a/curriculum/challenges/_meta/build-a-world-cup-database-project/meta.json +++ b/curriculum/challenges/_meta/build-a-world-cup-database-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build a World Cup Database Project", "isUpcomingChange": false, + "dashedName": "build-a-world-cup-database-project", "helpCategory": "Backend Development", "order": 6, "time": "30 hours", @@ -13,4 +14,4 @@ "Build a World Cup Database" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/build-three-math-games-project/meta.json b/curriculum/challenges/_meta/build-three-math-games-project/meta.json index d7182341ce0..450d71bd250 100644 --- a/curriculum/challenges/_meta/build-three-math-games-project/meta.json +++ b/curriculum/challenges/_meta/build-three-math-games-project/meta.json @@ -1,6 +1,7 @@ { "name": "Build Three Math Games Project", "isUpcomingChange": false, + "dashedName": "build-three-math-games-project", "helpCategory": "Python", "order": 13, "time": "30 hours", @@ -13,4 +14,4 @@ "Build Three Math Games" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-advanced-bash-by-building-a-kitty-ipsum-translator/meta.json b/curriculum/challenges/_meta/learn-advanced-bash-by-building-a-kitty-ipsum-translator/meta.json index 88ddf2818f6..75dc187c063 100644 --- a/curriculum/challenges/_meta/learn-advanced-bash-by-building-a-kitty-ipsum-translator/meta.json +++ b/curriculum/challenges/_meta/learn-advanced-bash-by-building-a-kitty-ipsum-translator/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Advanced Bash by Building a Kitty Ipsum Translator", "isUpcomingChange": false, + "dashedName": "learn-advanced-bash-by-building-a-kitty-ipsum-translator", "helpCategory": "Backend Development", "order": 7, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Kitty Ipsum Translator" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-bash-and-sql-by-building-a-bike-rental-shop/meta.json b/curriculum/challenges/_meta/learn-bash-and-sql-by-building-a-bike-rental-shop/meta.json index 7a46bf66326..2fb927c8180 100644 --- a/curriculum/challenges/_meta/learn-bash-and-sql-by-building-a-bike-rental-shop/meta.json +++ b/curriculum/challenges/_meta/learn-bash-and-sql-by-building-a-bike-rental-shop/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Bash and SQL by Building a Bike Rental Shop", "isUpcomingChange": false, + "dashedName": "learn-bash-and-sql-by-building-a-bike-rental-shop", "helpCategory": "Backend Development", "order": 8, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Bike Rental Shop" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-bash-by-building-a-boilerplate/meta.json b/curriculum/challenges/_meta/learn-bash-by-building-a-boilerplate/meta.json index a826a2963a4..ca99c40bb62 100644 --- a/curriculum/challenges/_meta/learn-bash-by-building-a-boilerplate/meta.json +++ b/curriculum/challenges/_meta/learn-bash-by-building-a-boilerplate/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Bash by Building a Boilerplate", "isUpcomingChange": false, + "dashedName": "learn-bash-by-building-a-boilerplate", "helpCategory": "Backend Development", "order": 0, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Boilerplate" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-bash-scripting-by-building-five-programs/meta.json b/curriculum/challenges/_meta/learn-bash-scripting-by-building-five-programs/meta.json index 1ad1434090f..1593788f53f 100644 --- a/curriculum/challenges/_meta/learn-bash-scripting-by-building-five-programs/meta.json +++ b/curriculum/challenges/_meta/learn-bash-scripting-by-building-five-programs/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Bash Scripting by Building Five Programs", "isUpcomingChange": false, + "dashedName": "learn-bash-scripting-by-building-five-programs", "helpCategory": "Backend Development", "order": 3, "time": "5 hours", @@ -13,4 +14,4 @@ "Build Five Programs" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-git-by-building-an-sql-reference-object/meta.json b/curriculum/challenges/_meta/learn-git-by-building-an-sql-reference-object/meta.json index 8c5b99caabe..5e00a89765f 100644 --- a/curriculum/challenges/_meta/learn-git-by-building-an-sql-reference-object/meta.json +++ b/curriculum/challenges/_meta/learn-git-by-building-an-sql-reference-object/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Git by Building an SQL Reference Object", "isUpcomingChange": false, + "dashedName": "learn-git-by-building-an-sql-reference-object", "helpCategory": "Backend Development", "order": 11, "time": "5 hours", @@ -13,4 +14,4 @@ "Build an SQL Reference Object" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-nano-by-building-a-castle/meta.json b/curriculum/challenges/_meta/learn-nano-by-building-a-castle/meta.json index eb4dcde4677..e3c4be1e420 100644 --- a/curriculum/challenges/_meta/learn-nano-by-building-a-castle/meta.json +++ b/curriculum/challenges/_meta/learn-nano-by-building-a-castle/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Nano by Building a Castle", "isUpcomingChange": false, + "dashedName": "learn-nano-by-building-a-castle", "helpCategory": "Backend Development", "order": 10, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Castle" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-relational-databases-by-building-a-mario-database/meta.json b/curriculum/challenges/_meta/learn-relational-databases-by-building-a-mario-database/meta.json index c1355b402b7..df21feefb84 100644 --- a/curriculum/challenges/_meta/learn-relational-databases-by-building-a-mario-database/meta.json +++ b/curriculum/challenges/_meta/learn-relational-databases-by-building-a-mario-database/meta.json @@ -1,6 +1,7 @@ { "name": "Learn Relational Databases by Building a Mario Database", "isUpcomingChange": false, + "dashedName": "learn-relational-databases-by-building-a-mario-database", "helpCategory": "Backend Development", "order": 1, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Mario Database" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-1/meta.json b/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-1/meta.json index 5e9a46ff3c2..3c150cb8592 100644 --- a/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-1/meta.json +++ b/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-1/meta.json @@ -1,6 +1,7 @@ { "name": "Learn SQL by Building a Student Database: Part 1", "isUpcomingChange": false, + "dashedName": "learn-sql-by-building-a-student-database-part-1", "helpCategory": "Backend Development", "order": 4, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Student Database: Part 1" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-2/meta.json b/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-2/meta.json index c3367cd9e2d..d43f31a5ecb 100644 --- a/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-2/meta.json +++ b/curriculum/challenges/_meta/learn-sql-by-building-a-student-database-part-2/meta.json @@ -1,6 +1,7 @@ { "name": "Learn SQL by Building a Student Database: Part 2", "isUpcomingChange": false, + "dashedName": "learn-sql-by-building-a-student-database-part-2", "helpCategory": "Backend Development", "order": 5, "time": "5 hours", @@ -13,4 +14,4 @@ "Build a Student Database: Part 2" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/project-euler-problems-1-to-100/meta.json b/curriculum/challenges/_meta/project-euler-problems-1-to-100/meta.json index ab6d8e72427..86be07a9b3e 100644 --- a/curriculum/challenges/_meta/project-euler-problems-1-to-100/meta.json +++ b/curriculum/challenges/_meta/project-euler-problems-1-to-100/meta.json @@ -1,6 +1,7 @@ { "name": "project euler problems 1 to 100", "isUpcomingChange": false, + "dashedName": "project-euler-problems-1-to-100", "helpCategory": "JavaScript", "order": 0, "time": "", @@ -409,4 +410,4 @@ "Problem 100: Arranged probability" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/project-euler-problems-101-to-200/meta.json b/curriculum/challenges/_meta/project-euler-problems-101-to-200/meta.json index 33ec041d095..31a4c4c6b9a 100644 --- a/curriculum/challenges/_meta/project-euler-problems-101-to-200/meta.json +++ b/curriculum/challenges/_meta/project-euler-problems-101-to-200/meta.json @@ -1,6 +1,7 @@ { "name": "project euler problems 101 to 200", "isUpcomingChange": false, + "dashedName": "project-euler-problems-101-to-200", "helpCategory": "JavaScript", "order": 1, "time": "", @@ -409,4 +410,4 @@ "Problem 200: Find the 200th prime-proof sqube containing the contiguous sub-string \"200\"" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/project-euler-problems-201-to-300/meta.json b/curriculum/challenges/_meta/project-euler-problems-201-to-300/meta.json index f91a6f374ed..b24cb55fa1d 100644 --- a/curriculum/challenges/_meta/project-euler-problems-201-to-300/meta.json +++ b/curriculum/challenges/_meta/project-euler-problems-201-to-300/meta.json @@ -1,6 +1,7 @@ { "name": "project euler problems 201 to 300", "isUpcomingChange": false, + "dashedName": "project-euler-problems-201-to-300", "helpCategory": "JavaScript", "order": 2, "time": "", @@ -409,4 +410,4 @@ "Problem 300: Protein folding" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/project-euler-problems-301-to-400/meta.json b/curriculum/challenges/_meta/project-euler-problems-301-to-400/meta.json index a32685dfb34..29c8c9c06f5 100644 --- a/curriculum/challenges/_meta/project-euler-problems-301-to-400/meta.json +++ b/curriculum/challenges/_meta/project-euler-problems-301-to-400/meta.json @@ -1,6 +1,7 @@ { "name": "project euler problems 301 to 400", "isUpcomingChange": false, + "dashedName": "project-euler-problems-301-to-400", "helpCategory": "JavaScript", "order": 3, "time": "", @@ -409,4 +410,4 @@ "Problem 400: Fibonacci tree game" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/project-euler-problems-401-to-480/meta.json b/curriculum/challenges/_meta/project-euler-problems-401-to-480/meta.json index de1390dff95..ce1830429d1 100644 --- a/curriculum/challenges/_meta/project-euler-problems-401-to-480/meta.json +++ b/curriculum/challenges/_meta/project-euler-problems-401-to-480/meta.json @@ -1,6 +1,7 @@ { "name": "project euler problems 401 to 480", "isUpcomingChange": false, + "dashedName": "project-euler-problems-401-to-480", "helpCategory": "JavaScript", "order": 4, "time": "", @@ -329,4 +330,4 @@ "Problem 480: The Last Question" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/top-build-a-recipe-project/meta.json b/curriculum/challenges/_meta/top-build-a-recipe-project/meta.json index 669b0ef5bb9..2b2902242b4 100644 --- a/curriculum/challenges/_meta/top-build-a-recipe-project/meta.json +++ b/curriculum/challenges/_meta/top-build-a-recipe-project/meta.json @@ -1,6 +1,7 @@ { "name": "TOP build a recipe project", "isUpcomingChange": true, + "dashedName": "top-build-a-recipe-project", "helpCategory": "HTML-CSS", "order": 1, "time": "", @@ -13,4 +14,4 @@ "Build a Recipe Page Project" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/top-learn-css-foundations-projects/meta.json b/curriculum/challenges/_meta/top-learn-css-foundations-projects/meta.json index 9b431a6034a..4bc81a07df3 100644 --- a/curriculum/challenges/_meta/top-learn-css-foundations-projects/meta.json +++ b/curriculum/challenges/_meta/top-learn-css-foundations-projects/meta.json @@ -1,6 +1,7 @@ { "name": "TOP Learn CSS Foundations Projects", "isUpcomingChange": true, + "dashedName": "top-learn-css-foundations-projects", "helpCategory": "HTML-CSS", "order": 3, "time": "", @@ -29,4 +30,4 @@ "CSS Foundations Exercise E" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/top-learn-css-foundations/meta.json b/curriculum/challenges/_meta/top-learn-css-foundations/meta.json index 76623b5a33c..bfa7a69c94f 100644 --- a/curriculum/challenges/_meta/top-learn-css-foundations/meta.json +++ b/curriculum/challenges/_meta/top-learn-css-foundations/meta.json @@ -1,6 +1,7 @@ { "name": "TOP Learn CSS Foundations", "isUpcomingChange": true, + "dashedName": "top-learn-css-foundations", "helpCategory": "HTML-CSS", "order": 2, "time": "", @@ -41,4 +42,4 @@ "CSS Foundations Question H" ] ] -} \ No newline at end of file +} diff --git a/curriculum/challenges/_meta/top-learn-html-foundations/meta.json b/curriculum/challenges/_meta/top-learn-html-foundations/meta.json index 0e8a42599ca..db2dc677376 100644 --- a/curriculum/challenges/_meta/top-learn-html-foundations/meta.json +++ b/curriculum/challenges/_meta/top-learn-html-foundations/meta.json @@ -1,6 +1,7 @@ { "name": "TOP Learn HTML Foundations", "isUpcomingChange": true, + "dashedName": "top-learn-html-foundations", "helpCategory": "HTML-CSS", "order": 0, "time": "", @@ -121,4 +122,4 @@ "Links and Images Question D" ] ] -} \ No newline at end of file +} diff --git a/curriculum/get-challenges.js b/curriculum/get-challenges.js index 2cd636d6781..e6950f9496d 100644 --- a/curriculum/get-challenges.js +++ b/curriculum/get-challenges.js @@ -16,7 +16,6 @@ const { const { isAuditedCert } = require('../utils/is-audited'); const { createPoly } = require('../utils/polyvinyl'); -const { dasherize } = require('../utils/slugs'); const { getSuperOrder, getSuperBlockFromDir } = require('./utils'); const access = util.promisify(fs.access); @@ -293,7 +292,12 @@ Challenges that have been already audited cannot fall back to their English vers ([id]) => id === challenge.id ); - challenge.block = meta.name ? dasherize(meta.name) : null; + if (!meta.dashedName) + throw Error( + `The 'meta.json' file for the block with challenge '${challenge.title}' has no 'dashedName' property` + ); + + challenge.block = meta.dashedName; challenge.hasEditableBoundaries = !!meta.hasEditableBoundaries; challenge.order = meta.order; // const superOrder = getSuperOrder(meta.superBlock); diff --git a/utils/index.ts b/utils/index.ts index 60e4d572167..97831d89cd1 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,51 +1,23 @@ -import { dasherize } from './slugs'; - -const idToTitle = new Map( +const idToPath = new Map( Object.entries({ - '561add10cb82ac38a17523bc': 'Back End Development and APIs', - '5a553ca864b52e1d8bceea14': 'Data Visualization', - '561acd10cb82ac38a17513bc': 'Front End Development Libraries', - '5e611829481575a52dc59c0e': 'Quality Assurance', - '5e6021435ac9d0ecd8b94b00': 'Information Security', - '561abd10cb81ac38a17513bc': 'JavaScript Algorithms and Data Structures', - '561add10cb82ac38a17513bc': 'Responsive Web Design', - '660add10cb82ac38a17513be': 'Legacy Back End', - '561add10cb82ac39a17513bc': 'Legacy Data Visualization', - '561add10cb82ac38a17513be': 'Legacy Front End', - '561add10cb82ac38a17213bc': - 'Legacy Information Security and Quality Assurance', - '561add10cb82ac38a17213bd': 'Legacy Full Stack', - '5e44431b903586ffb414c951': 'Scientific Computing with Python', - '5e46fc95ac417301a38fb934': 'Data Analysis with Python', - '5e46fc95ac417301a38fb935': 'Machine Learning with Python' + '561add10cb82ac38a17523bc': 'back-end-development-and-apis', + '5a553ca864b52e1d8bceea14': 'data-visualization', + '561acd10cb82ac38a17513bc': 'front-end-development-libraries', + '5e611829481575a52dc59c0e': 'quality-assurance-v7', + '5e6021435ac9d0ecd8b94b00': 'information-security-v7', + '561abd10cb81ac38a17513bc': 'javascript-algorithms-and-data-structures', + '561add10cb82ac38a17513bc': 'responsive-web-design', + '660add10cb82ac38a17513be': 'legacy-back-end', + '561add10cb82ac39a17513bc': 'legacy-data-visualization', + '561add10cb82ac38a17513be': 'legacy-front-end', + '561add10cb82ac38a17213bc': 'information-security-and-quality-assurance', + '561add10cb82ac38a17213bd': 'full-stack', + '5e44431b903586ffb414c951': 'scientific-computing-with-python-v7', + '5e46fc95ac417301a38fb934': 'data-analysis-with-python-v7', + '5e46fc95ac417301a38fb935': 'machine-learning-with-python-v7' }) ); -const idToPath = new Map(); - -// Keep the timeline slugs the same so -// we don't break existing links -const specialPaths: Record = { - 'Legacy Full Stack': 'Full Stack', - 'Legacy Information Security and Quality Assurance': - 'Information Security and Quality Assurance', - 'Scientific Computing with Python': 'Scientific Computing with Python V7', - 'Data Analysis with Python': 'Data Analysis with Python V7', - 'Machine Learning with Python': 'Machine Learning with Python V7', - 'Quality Assurance': 'Quality Assurance V7', - 'Information Security': 'Information Security V7' -}; - -for (const [id, title] of idToTitle) { - if (specialPaths[title]) { - idToPath.set(id, dasherize(specialPaths[title])); - } else { - idToPath.set(id, dasherize(title)); - } -} - export const getCertIds = (): IterableIterator => idToPath.keys(); export const getPathFromID = (id: string): string | undefined => idToPath.get(id); -export const getTitleFromId = (id: string): string | undefined => - idToTitle.get(id); diff --git a/utils/slugs.test.ts b/utils/slugs.test.ts deleted file mode 100644 index 26a41635cf1..00000000000 --- a/utils/slugs.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { dasherize, nameify, unDasherize } from './slugs'; - -describe('dasherize', () => { - it('returns a string', () => { - expect(dasherize('')).toBe(''); - }); - it('converts characters to lower case', () => { - expect(dasherize('UPPERCASE')).toBe('uppercase'); - }); - it('converts spaces to dashes', () => { - expect(dasherize('the space between')).toBe('the-space--between'); - }); - - it('converts dots to dashes', () => { - expect(dasherize('the..dots.. between')).toBe('the--dots---between'); - }); - - it('trims off surrounding whitespace', () => { - expect(dasherize(' the space between ')).toBe('the-space--between'); - }); - - it('removes everything except letters, numbers and -', () => { - expect(dasherize('1a!"£$%^*()_+=-.b2')).toBe('1a--b2'); - }); -}); - -describe('nameify', () => { - it('returns a string', () => { - expect(nameify('')).toBe(''); - }); - it('removes everything except letters, numbers and spaces', () => { - expect(nameify('1A !"£$%^*()_+=-.b 2')).toBe('1A b 2'); - }); -}); - -describe('unDasherize', () => { - it('returns a string', () => { - expect(unDasherize('')).toBe(''); - }); - it('converts dashes to spaces', () => { - expect(unDasherize('the-space--between')).toBe('the space between'); - }); - it('removes everything except letters, numbers and spaces', () => { - expect(unDasherize('1A !"£$%^*()_+=-.b 2')).toBe('1A b 2'); - }); - it('trims off surrounding whitespace', () => { - expect(unDasherize('--the-space--between----')).toBe('the space between'); - }); -}); diff --git a/utils/slugs.ts b/utils/slugs.ts deleted file mode 100644 index c4567d32cc1..00000000000 --- a/utils/slugs.ts +++ /dev/null @@ -1,24 +0,0 @@ -function dasherize(name: string): string { - return ('' + name) - .toLowerCase() - .trim() - .replace(/\s|\./g, '-') - .replace(/[^a-z\d\-.]/g, ''); -} - -function nameify(str: string): string { - return ('' + str).replace(/[^a-z\d\s]/gi, ''); -} - -function unDasherize(name: string): string { - return ( - ('' + name) - // replace dash with space - .replace(/-/g, ' ') - // strip nonalphanumarics chars except whitespace - .replace(/[^a-z\d\s]/gi, '') - .trim() - ); -} - -export { dasherize, nameify, unDasherize };