forked from btholt/gatsby-course-starter
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix section numbers, pull links out of lessons
- Loading branch information
Showing
8 changed files
with
7,754 additions
and
2,911 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function splitSections(str) { | ||
const validSectionTest = /^\d+[A-Z]+$/; | ||
const numbersRegex = /^\d+/; | ||
const lettersRegex = /[A-Z]+$/; | ||
if (!validSectionTest.test(str)) { | ||
throw new Error( | ||
`${str} does not match the section format. It must be <numbers><capital letters>, like 16A or 5F (case sensitive)` | ||
); | ||
} | ||
|
||
return [numbersRegex.exec(str)[0], lettersRegex.exec(str)[0]]; | ||
} | ||
|
||
const getCharScore = str => | ||
str | ||
.split("") | ||
.map((char, index) => char.charCodeAt(0) * 10 ** index) | ||
.reduce((acc, score) => acc + score); | ||
|
||
function sorter(a, b) { | ||
const [aSec, aSub] = splitSections(a.attributes.order); | ||
const [bSec, bSub] = splitSections(b.attributes.order); | ||
|
||
// sections first | ||
if (aSec !== bSec) { | ||
return aSec - bSec; | ||
} | ||
|
||
// subsections next | ||
return getCharScore(aSub) - getCharScore(bSub); | ||
} | ||
|
||
module.exports.splitSections = splitSections; | ||
module.exports.sorter = sorter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
path: "/page-3" | ||
title: "Page 3" | ||
order: "2B" | ||
description: "The third page" | ||
section: "The Second Section" | ||
--- | ||
|
||
This is page three. |
Oops, something went wrong.