mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-17 16:00:50 -04:00
* refactor(client): relocate to learn path tests file * refactor(client): add docs for to learn path Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> * fix: order imports Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
31 lines
671 B
TypeScript
31 lines
671 B
TypeScript
import { withPrefix } from 'gatsby';
|
|
|
|
interface ToLearnPathKwargs {
|
|
block?: string;
|
|
challenge?: string;
|
|
superBlock?: string;
|
|
}
|
|
|
|
/**
|
|
* Builds a learning url path from folders.
|
|
* - /learn/:superBlock/:block/:challenge
|
|
* @params {Object} Path kwargs.
|
|
* @returns {string} A learning url path.
|
|
*/
|
|
export default function toLearnPath({
|
|
block,
|
|
challenge,
|
|
superBlock
|
|
}: ToLearnPathKwargs): string {
|
|
// Match path order /:super-block/:block/:challenge
|
|
const folders = [superBlock, block, challenge];
|
|
|
|
return folders.reduce((path: string, folder) => {
|
|
if (folder) {
|
|
return `${path}/${folder}`;
|
|
}
|
|
|
|
return path;
|
|
}, withPrefix('/learn'));
|
|
}
|