Feat/sub-route (#38)
* blog subroute support * docs: update readme and blog Co-authored-by: mrhut10 <ahut10@gmail.com>
This commit is contained in:
20
lib/utils/files.js
Normal file
20
lib/utils/files.js
Normal file
@ -0,0 +1,20 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x)
|
||||
|
||||
const flatternArray = (input) =>
|
||||
input.reduce((acc, item) => [...acc, ...(Array.isArray(item) ? item : [item])], [])
|
||||
|
||||
const map = (fn) => (input) => input.map(fn)
|
||||
|
||||
const walkDir = (fullPath) => {
|
||||
return fs.statSync(fullPath).isFile() ? fullPath : getAllFilesRecursively(fullPath)
|
||||
}
|
||||
|
||||
const pathJoinPrefix = (prefix) => (extraPath) => path.join(prefix, extraPath)
|
||||
|
||||
const getAllFilesRecursively = (folder) =>
|
||||
pipe(fs.readdirSync, map(pipe(pathJoinPrefix(folder), walkDir)), flatternArray)(folder)
|
||||
|
||||
export default getAllFilesRecursively
|
8
lib/utils/kebabCase.js
Normal file
8
lib/utils/kebabCase.js
Normal file
@ -0,0 +1,8 @@
|
||||
const kebabCase = (str) =>
|
||||
str &&
|
||||
str
|
||||
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
||||
.map((x) => x.toLowerCase())
|
||||
.join('-')
|
||||
|
||||
export default kebabCase
|
Reference in New Issue
Block a user