Skip to content

Commit bd6392b

Browse files
committed
Favicon and hjs cleanup
1 parent c609675 commit bd6392b

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

docs/favicon.ico

264 KB
Binary file not shown.

docs/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
from pathlib import Path
77

88
# Setup the app
9-
app,rt = fast_app(pico=False, hdrs=(*Theme.blue.headers(),*hjs))
9+
10+
11+
12+
app,rt = fast_app(pico=False, hdrs=(*Theme.blue.headers(),*hjs, Link(rel="icon", type="image/x-icon", href="/favicon.ico")))
1013

1114
def is_htmx(request=None):
1215
"Check if the request is an HTMX request"

docs/utils.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ def get_last_statement(code): return ast.unparse(ast.parse(code).body[-1])
1414
from pathlib import Path
1515

1616

17-
hjs = (Style('html.dark .hljs-copy-button {background-color: #e0e0e0; color: #2d2b57;}'),
17+
hjs = (Style(''' .hljs-copy-button {background-color: #2d2b57;}
18+
html.dark .hljs-copy-button {background-color: #e0e0e0; color: #2d2b57;}'''),
1819
Link(rel='stylesheet', href='https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/atom-one-dark.css', disabled=True),
1920
Link(rel='stylesheet', href='https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/atom-one-light.css', disabled=True),
2021
Script(src='https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/highlight.min.js'),
2122
Script(src='https://cdn.jsdelivr.net/gh/arronhunt/highlightjs-copy/dist/highlightjs-copy.min.js'),
2223
Link(rel='stylesheet', href='https://cdn.jsdelivr.net/gh/arronhunt/highlightjs-copy/dist/highlightjs-copy.min.css'),
23-
Style('.hljs-copy-button {background-color: #2d2b57;}'),
2424
Script(src='https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/languages/python.min.js'),
25-
Script("hljs.addPlugin(new CopyButtonPlugin());\r\nhljs.configure({'cssSelector': 'pre code'});\r\nhtmx.onLoad(hljs.highlightAll);", type='module'),
26-
Script('''htmx.on("htmx:beforeHistorySave", () => {document.querySelectorAll("uk-icon").forEach((elt) => {elt.innerHTML = '';});});'''),
27-
28-
Script('''hljs.configure({
29-
ignoreUnescapedHTML: true
30-
});'''),
31-
Script('''const observer = new MutationObserver(mutations => {
32-
mutations.forEach(mutation => {
33-
if (mutation.target.tagName === 'HTML' && mutation.attributeName === 'class') {
34-
const isDark = mutation.target.classList.contains('dark');
35-
document.querySelector('link[href*="atom-one-dark.css"]').disabled = !isDark;
36-
document.querySelector('link[href*="atom-one-light.css"]').disabled = isDark;
37-
}
38-
});
25+
Script('''
26+
hljs.addPlugin(new CopyButtonPlugin());
27+
hljs.configure({
28+
cssSelector: 'pre code',
29+
ignoreUnescapedHTML: true
30+
});
31+
htmx.onLoad(hljs.highlightAll);
32+
33+
const observer = new MutationObserver(mutations => {
34+
mutations.forEach(mutation => {
35+
if (mutation.target.tagName === 'HTML' && mutation.attributeName === 'class') {
36+
const isDark = mutation.target.classList.contains('dark');
37+
document.querySelector('link[href*="atom-one-dark.css"]').disabled = !isDark;
38+
document.querySelector('link[href*="atom-one-light.css"]').disabled = isDark;
39+
}
40+
});
3941
});
4042
4143
observer.observe(document.documentElement, { attributes: true });
@@ -44,7 +46,7 @@ def get_last_statement(code): return ast.unparse(ast.parse(code).body[-1])
4446
const isDark = document.documentElement.classList.contains('dark');
4547
document.querySelector('link[href*="atom-one-dark.css"]').disabled = !isDark;
4648
document.querySelector('link[href*="atom-one-light.css"]').disabled = isDark;
47-
'''))
49+
''', type='module'))
4850

4951
def create_flippable_card(content, source_code, extra_cls=None):
5052
"Creates a card that flips between content and source code"
@@ -57,7 +59,7 @@ def create_flippable_card(content, source_code, extra_cls=None):
5759
DivFullySpaced(UkIcon('corner-down-right', 20, 20, 3),"See Output"),
5860
uk_toggle=f"target: #{_id}", id=_id, cls=ButtonT.primary, hidden=True),
5961
Div(content, id=_id),
60-
Div(Pre(Code(source_code, cls="hljs language-python")), id=_id, hidden=True, cls="mockup-code"),
62+
Div(Pre(Code(source_code, cls="hljs language-python")), id=_id, hidden=True),#, cls="mockup-code"
6163
cls='my-8')
6264
return Div(_card, cls=extra_cls) if extra_cls else _card
6365

0 commit comments

Comments
 (0)