Skip to content

Instantly share code, notes, and snippets.

@brigand
Last active June 25, 2021 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/80cf6f223de4fbae8228660c1b229d46 to your computer and use it in GitHub Desktop.
Save brigand/80cf6f223de4fbae8228660c1b229d46 to your computer and use it in GitHub Desktop.
ErrorMime::JavaScript => format!(
"{pre}{json};\nlet css = {css_json};\n{code}\n{close}",
json = get_json(),
pre = "{ let error_json = ",
close = "}",
code = indoc::indoc!(r#"
const h = (tag, {style, ...props}, ...children) => {
const element = Object.assign(document.createElement(tag), props);
Object.assign(element.style, style);
for (const child of children) {
if (!child || child === true) continue;
if (child instanceof Node) {
element.appendChild(child);
} else {
const text = document.createTextNode(String(child));
element.appendChild(text);
}
}
return element;
};
document.head.appendChild(
h('style', {}, css),
);
document.body.appendChild(
h('aside', {},
h('h1', { style: { color: 'var(--red)' } }, error_json.title),
h('h3', {},
'Code: ',
h('span', { style: { color: 'var(--purple)' } }, error_json.code),
),
h('p', { style: { color: 'var(--yellow)', whiteSpace: 'pre-wrap' } }, error_json.message),
),
);
"#),
css_json = serde_json::to_string(colors).unwrap(),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment