-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
4,126 additions
and
290 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"builder": "node ./src/builder.js", | ||
"dev": "parcel website/index.html", | ||
"build": "parcel build website/index.html -d docs/ --public-url ./", | ||
"format": "prettier --write '**/*.js'", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Stefan Fejes <[email protected]> (https://stefanfejes.com)", | ||
|
@@ -40,6 +41,7 @@ | |
"fs-extra": "^7.0.1", | ||
"markdown-builder": "^0.9.0", | ||
"node-sass": "^4.11.0", | ||
"parcel-bundler": "^1.11.0" | ||
"parcel-bundler": "^1.11.0", | ||
"prettier": "^1.16.4" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,47 +1,48 @@ | ||
// This script converts markdown files into JSON format | ||
const fs = require("fs-extra") | ||
const path = require("path") | ||
const chalk = require("chalk") | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const { | ||
attempt, | ||
readData, | ||
getSection, | ||
getShortTip, | ||
getLongTip, | ||
CATEGORY_NAMES | ||
} = require("./util") | ||
attempt, | ||
readData, | ||
getSection, | ||
getShortTip, | ||
getLongTip, | ||
CATEGORY_NAMES | ||
} = require("./util"); | ||
|
||
console.time("Extractor") | ||
console.time("Extractor"); | ||
|
||
attempt("data.json generation", () => { | ||
const output = Object.entries(readData()).map(([name, contents]) => { | ||
const shortTip = getShortTip(contents) | ||
const longTip = getLongTip(contents) | ||
const output = Object.entries(readData()).map(([name, contents]) => { | ||
const shortTip = getShortTip(contents); | ||
const longTip = getLongTip(contents); | ||
|
||
const links = getSection("### Resources", contents) | ||
.split("\n") | ||
.filter(v => | ||
/(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/.test( | ||
v | ||
) | ||
) | ||
.map(v => v.replace(/[*-] /g, "")) | ||
.filter(v => v.trim() !== "" && !v.includes("category")) | ||
const links = getSection("### Resources", contents) | ||
.split("\n") | ||
.filter(v => | ||
/(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)/.test( | ||
v | ||
) | ||
) | ||
.map(v => v.replace(/[*-] /g, "")) | ||
.filter(v => v.trim() !== "" && !v.includes("category")); | ||
|
||
const categoryNum = parseInt( | ||
(contents.match(/<!--\s*category:\s*\((.+)\)/) || [])[1], | ||
10) | ||
return { | ||
name, | ||
shortTip, | ||
longTip, | ||
links, | ||
category: CATEGORY_NAMES[categoryNum] | ||
} | ||
}) | ||
const categoryNum = parseInt( | ||
(contents.match(/<!--\s*category:\s*\((.+)\)/) || [])[1], | ||
10 | ||
); | ||
return { | ||
name, | ||
shortTip, | ||
longTip, | ||
links, | ||
category: CATEGORY_NAMES[categoryNum] | ||
}; | ||
}); | ||
|
||
fs.writeFileSync("./data.json", JSON.stringify(output, null, 2)) | ||
}) | ||
fs.writeFileSync("./data.json", JSON.stringify(output, null, 2)); | ||
}); | ||
|
||
console.log(`${chalk.green("SUCCESS!")} data.json file generated!`) | ||
console.timeEnd("Extractor") | ||
console.log(`${chalk.green("SUCCESS!")} data.json file generated!`); | ||
console.timeEnd("Extractor"); |
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 |
---|---|---|
@@ -1,86 +1,85 @@ | ||
const fs = require("fs-extra") | ||
const path = require("path") | ||
const chalk = require("chalk") | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
|
||
const DATA_PATH = "./data" | ||
const DATA_PATH = "./data"; | ||
|
||
const CATEGORY_NAMES = { | ||
0: "tip", | ||
1: "pro tip", | ||
2: "you should know" | ||
} | ||
0: "tip", | ||
1: "pro tip", | ||
2: "you should know" | ||
}; | ||
|
||
const attempt = (task, cb) => { | ||
try { | ||
return cb() | ||
} catch (e) { | ||
console.log(`${chalk.red("ERROR!")} During ${task}: ${e}`) | ||
process.exit(1) | ||
return null | ||
} | ||
} | ||
try { | ||
return cb(); | ||
} catch (e) { | ||
console.log(`${chalk.red("ERROR!")} During ${task}: ${e}`); | ||
process.exit(1); | ||
return null; | ||
} | ||
}; | ||
|
||
const readData = () => | ||
attempt("read accessibility tips", () => | ||
fs | ||
.readdirSync(DATA_PATH) | ||
.filter(f => !f.includes("eslint")) | ||
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1)) | ||
.reduce((acc, name) => { | ||
acc[name] = fs | ||
.readFileSync(path.join(DATA_PATH, name), "utf8") | ||
.replace(/\r\n/g, "\n") | ||
return acc | ||
}, {}) | ||
) | ||
attempt("read accessibility tips", () => | ||
fs | ||
.readdirSync(DATA_PATH) | ||
.filter(f => !f.includes("eslint")) | ||
.sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1)) | ||
.reduce((acc, name) => { | ||
acc[name] = fs | ||
.readFileSync(path.join(DATA_PATH, name), "utf8") | ||
.replace(/\r\n/g, "\n"); | ||
return acc; | ||
}, {}) | ||
); | ||
|
||
const capitalize = ([first, ...rest], lowerRest = false) => | ||
first.toUpperCase() + | ||
(lowerRest ? rest.join("").toLowerCase() : rest.join("")) | ||
first.toUpperCase() + | ||
(lowerRest ? rest.join("").toLowerCase() : rest.join("")); | ||
|
||
const getSection = (searchString, contents, includeSubsections = true) => { | ||
const indexOfSearch = contents.indexOf(searchString) | ||
if (indexOfSearch < 0) return "" | ||
const indexOfSearch = contents.indexOf(searchString); | ||
if (indexOfSearch < 0) return ""; | ||
|
||
let endSearch = "\\n#" | ||
if (includeSubsections) { | ||
let i | ||
for (i = 0; searchString[i] === "#" && i < searchString.length; i++); | ||
let endSearch = "\\n#"; | ||
if (includeSubsections) { | ||
let i; | ||
for (i = 0; searchString[i] === "#" && i < searchString.length; i++); | ||
|
||
if (i > 0) { | ||
endSearch += `{${i - 1},${i}}[^#]` | ||
} | ||
if (i > 0) { | ||
endSearch += `{${i - 1},${i}}[^#]`; | ||
} | ||
const endRegex = new RegExp(endSearch) | ||
} | ||
const endRegex = new RegExp(endSearch); | ||
|
||
const sliceStart = indexOfSearch + searchString.length + 1 | ||
const endIndex = contents.slice(sliceStart).search(endRegex) | ||
const sliceEnd = endIndex === -1 ? undefined : endIndex + sliceStart | ||
const sliceStart = indexOfSearch + searchString.length + 1; | ||
const endIndex = contents.slice(sliceStart).search(endRegex); | ||
const sliceEnd = endIndex === -1 ? undefined : endIndex + sliceStart; | ||
|
||
return contents.slice(sliceStart, sliceEnd).trim() | ||
} | ||
return contents.slice(sliceStart, sliceEnd).trim(); | ||
}; | ||
|
||
const getFirstSection = (contents, includeSubsections) => | ||
getSection("", contents.slice(3), includeSubsections) | ||
getSection("", contents.slice(3), includeSubsections); | ||
|
||
const getLongTip = str => { | ||
const regex = /^.*\n*([\s\S]*?)(###)|(<!--)/; | ||
const results = []; | ||
let m = regex.exec(str); | ||
return m[1]; | ||
const regex = /^.*\n*([\s\S]*?)(###)|(<!--)/; | ||
const results = []; | ||
let m = regex.exec(str); | ||
return m[1]; | ||
}; | ||
|
||
const getShortTip = (contents) => | ||
contents.split('\n')[0].replace(/^#+\s+/g, ''); | ||
const getShortTip = contents => contents.split("\n")[0].replace(/^#+\s+/g, ""); | ||
|
||
module.exports = { | ||
attempt, | ||
readData, | ||
capitalize, | ||
DATA_PATH, | ||
CATEGORY_NAMES, | ||
getSection, | ||
getFirstSection, | ||
getLongTip, | ||
getShortTip | ||
} | ||
attempt, | ||
readData, | ||
capitalize, | ||
DATA_PATH, | ||
CATEGORY_NAMES, | ||
getSection, | ||
getFirstSection, | ||
getLongTip, | ||
getShortTip | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { app } from "hyperapp" | ||
import "./css/index.scss" | ||
import "./js/browser" | ||
import { app } from "hyperapp"; | ||
import "./css/index.scss"; | ||
import "./js/browser"; | ||
|
||
import state from "./js/state" | ||
import actions from "./js/actions" | ||
import view from "./js/view" | ||
import state from "./js/state"; | ||
import actions from "./js/actions"; | ||
import view from "./js/view"; | ||
|
||
app(state, actions, view, document.body) | ||
app(state, actions, view, document.body); |
Oops, something went wrong.