Skip to content

Commit 74bf151

Browse files
Better topbar for examples
1 parent b98d910 commit 74bf151

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

examples/blog/build.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let
1919
[ "head"
2020
[ "meta" { charset = "utf-8"; } ]
2121
[ "title" title ]
22+
[ "style" (h.raw "body { color: #eee; } a { color: #6ab0ff; }") ]
2223
]
2324
[ "body"
2425
header

website.nix

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,36 @@ let
2020
);
2121

2222
# Wrap example in showcase page (source left, rendered right)
23+
exampleNames = builtins.sort builtins.lessThan (
24+
builtins.filter (name: if name == "docs" then isLinux else true) exampleDirs
25+
);
26+
2327
showcaseStyles = ''
2428
* { box-sizing: border-box; margin: 0; padding: 0; }
25-
body { display: flex; height: 100vh; font-family: system-ui, sans-serif; background: #1a1a2e; color: #eee; }
29+
body { display: flex; flex-direction: column; height: 100vh; font-family: system-ui, sans-serif; background: #1a1a2e; color: #ccc; }
30+
.topbar { padding: 0.6rem 1rem; background: #151525; border-bottom: 1px solid #333; font-size: 0.85rem; letter-spacing: 0.01em; }
31+
.topbar a { color: #6ab0ff; text-decoration: none; }
32+
.topbar a:hover { text-decoration: underline; }
33+
.topbar .current { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
34+
.content { display: flex; flex: 1; min-height: 0; }
2635
.source { flex: 1; overflow: auto; padding: 1rem; border-right: 1px solid #333; }
27-
.source h1 { font-size: 1rem; margin-bottom: 0.5rem; color: #999; }
28-
.source h1 a { color: #6ab0ff; text-decoration: none; }
2936
.source pre { margin: 0; font-size: 0.8rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
3037
.source code { font-family: ui-monospace, monospace; }
3138
.preview { flex: 1; }
3239
.preview iframe { width: 100%; height: 100%; border: none; }
3340
'';
3441

42+
exampleLink = current: name:
43+
if name == current
44+
then [ "span.current" name ]
45+
else [ "a" { href = "../${name}/"; } name ];
46+
47+
navBar = current: [ "nav.topbar"
48+
[ "a" { href = "../../"; } "niccup docs" ]
49+
" | Examples: "
50+
(builtins.tail (pkgs.lib.concatMap (name: [ " - " (exampleLink current name) ]) exampleNames))
51+
];
52+
3553
wrapExample = name: drv:
3654
let
3755
source = builtins.readFile ./examples/${name}/build.nix;
@@ -42,12 +60,10 @@ let
4260
[ "style" (h.raw showcaseStyles) ]
4361
]
4462
[ "body"
45-
[ "div.source"
46-
[ "h1" [ "a" { href = "../../"; } "← niccup" ] " / ${name}" ]
47-
[ "pre" [ "code" source ] ]
48-
]
49-
[ "div.preview"
50-
[ "iframe" { src = "demo/"; } ]
63+
(navBar name)
64+
[ "div.content"
65+
[ "div.source" [ "pre" [ "code" source ] ] ]
66+
[ "div.preview" [ "iframe" { src = "demo/"; } ] ]
5167
]
5268
]
5369
];

0 commit comments

Comments
 (0)