-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
302388e
commit 82d69de
Showing
8 changed files
with
165 additions
and
13 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
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,59 @@ | ||
// This file is for all of the "magic" autoconfig we do | ||
// For example, we select the background color from the logo | ||
// No config needed! | ||
import { decode } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import type { Magic } from "./types.ts"; | ||
|
||
function saturation(r: number, g: number, b: number) { | ||
r = r / 255; | ||
g = g / 255; | ||
b = b / 255; | ||
|
||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
|
||
const lum = max - min; | ||
|
||
if (lum < 0.5) { | ||
return (max - min) / (max + min); | ||
} else { | ||
return (max - min) / (2 - max - min); | ||
} | ||
} | ||
|
||
function getBackground() { | ||
try { | ||
const logo = Deno.readFileSync("./static/icon.png"); | ||
const bytes = decode(logo); | ||
|
||
let brightest_color = "rgb(0,0,0)"; | ||
let max_brightness = 0; | ||
|
||
for (let i = 0; i < bytes.image.length; i += 4) { | ||
const [r, g, b, a] = [ | ||
bytes.image[i], | ||
bytes.image[i + 1], | ||
bytes.image[i + 2], | ||
bytes.image[i + 3], | ||
]; | ||
const brightness = saturation(r, g, b) * a; | ||
|
||
if (brightness > max_brightness) { | ||
max_brightness = brightness; | ||
brightest_color = `rgb(${r}, ${g}, ${b})`; | ||
} | ||
} | ||
|
||
console.log("Brightest color is", brightest_color); | ||
|
||
return brightest_color; | ||
} catch { | ||
return "white"; | ||
} | ||
} | ||
|
||
export function getMagic(): Magic { | ||
return { | ||
background: getBackground(), | ||
}; | ||
} |
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 |
---|---|---|
|
@@ -3,13 +3,13 @@ import { extract } from "std/encoding/front_matter/any.ts"; | |
import { renderToString } from "preact-render-to-string"; | ||
import { page } from "./page.tsx"; | ||
import { get_route_map, resolve_file } from "./route_map.ts"; | ||
import type { Config } from "./types.ts"; | ||
import type { Config, Magic } from "./types.ts"; | ||
|
||
import "https://esm.sh/[email protected]/components/prism-json?no-check"; | ||
import "https://esm.sh/[email protected]/components/prism-bash?no-check"; | ||
import "https://esm.sh/[email protected]/components/prism-yaml?no-check"; | ||
|
||
export function render(config: Config, path: string) { | ||
export function render(config: Config, magic: Magic, path: string) { | ||
const markdown = resolve_file(resolve("pages", path)); | ||
const frontmatter = extract(markdown); | ||
const route_map = get_route_map(resolve("pages"), true); | ||
|
@@ -25,6 +25,7 @@ export function render(config: Config, path: string) { | |
route_map, | ||
route: "/" + path, | ||
config, | ||
magic, | ||
}), | ||
); | ||
} |
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,4 +1,10 @@ | ||
export interface Config { | ||
title: string; | ||
github?: string; | ||
copyright?: string; | ||
footer?: Record<string, [string, string][]>; | ||
} | ||
|
||
export interface Magic { | ||
background: string; | ||
} |
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