forked from CaiJimmy/hugo-theme-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge branch 'canary' into master" (CaiJimmy#712)
Revert "Merge branch 'canary' into master (CaiJimmy#711)" This reverts commit 8a597a5.
- Loading branch information
Showing
73 changed files
with
1,981 additions
and
897 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ date: {{ .Date }} | |
image: | ||
math: | ||
license: | ||
hidden: false | ||
comments: true | ||
draft: true | ||
--- |
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
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 was deleted.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
interface colorScheme { | ||
hash: string, /// Regenerate color scheme when the image hash is changed | ||
DarkMuted: { | ||
hex: string, | ||
rgb: Number[], | ||
bodyTextColor: string | ||
}, | ||
Vibrant: { | ||
hex: string, | ||
rgb: Number[], | ||
bodyTextColor: string | ||
} | ||
} | ||
|
||
let colorsCache: { [key: string]: colorScheme } = {}; | ||
|
||
if (localStorage.hasOwnProperty('StackColorsCache')) { | ||
try { | ||
colorsCache = JSON.parse(localStorage.getItem('StackColorsCache')); | ||
} | ||
catch (e) { | ||
colorsCache = {}; | ||
} | ||
} | ||
|
||
async function getColor(key: string, hash: string, imageURL: string) { | ||
if (!key) { | ||
/** | ||
* If no key is provided, do not cache the result | ||
*/ | ||
return await Vibrant.from(imageURL).getPalette(); | ||
} | ||
|
||
if (!colorsCache.hasOwnProperty(key) || colorsCache[key].hash !== hash) { | ||
/** | ||
* If key is provided, but not found in cache, or the hash mismatches => Regenerate color scheme | ||
*/ | ||
const palette = await Vibrant.from(imageURL).getPalette(); | ||
|
||
colorsCache[key] = { | ||
hash: hash, | ||
Vibrant: { | ||
hex: palette.Vibrant.hex, | ||
rgb: palette.Vibrant.rgb, | ||
bodyTextColor: palette.Vibrant.bodyTextColor | ||
}, | ||
DarkMuted: { | ||
hex: palette.DarkMuted.hex, | ||
rgb: palette.DarkMuted.rgb, | ||
bodyTextColor: palette.DarkMuted.bodyTextColor | ||
} | ||
} | ||
|
||
/* Save the result in localStorage */ | ||
localStorage.setItem('StackColorsCache', JSON.stringify(colorsCache)); | ||
} | ||
|
||
return colorsCache[key]; | ||
} | ||
|
||
export { | ||
getColor | ||
} |
Oops, something went wrong.