mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 15:17:09 +00:00
Make generator config more robust
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import config from '../config.json'
|
||||
|
||||
export function isPromise(obj: any): obj is Promise<any> {
|
||||
return typeof (obj as any)?.then === 'function'
|
||||
}
|
||||
@@ -26,6 +28,11 @@ export function cleanUrl(url: string) {
|
||||
return `/${url}/`.replaceAll('//', '/')
|
||||
}
|
||||
|
||||
export function getGenerator(url: string) {
|
||||
const trimmedUrl = url.replace(/^\//, '').replace(/\/$/, '')
|
||||
return config.generators.find(g => g.url === trimmedUrl)
|
||||
}
|
||||
|
||||
export function stringToColor(str: string): [number, number, number] {
|
||||
const h = Math.abs(hashString(str))
|
||||
return [h % 256, (h >> 8) % 256, (h >> 16) % 256]
|
||||
|
||||
Reference in New Issue
Block a user