Skip to content

Commit 4c79d83

Browse files
Include multiple files in examples
1 parent 74bf151 commit 4c79d83

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

website.nix

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ let
2424
builtins.filter (name: if name == "docs" then isLinux else true) exampleDirs
2525
);
2626

27+
exampleMeta = {
28+
docs = { files = [ "build.nix" "components.nix" "options.nix" ]; };
29+
};
30+
2731
showcaseStyles = ''
2832
* { box-sizing: border-box; margin: 0; padding: 0; }
2933
body { display: flex; flex-direction: column; height: 100vh; font-family: system-ui, sans-serif; background: #1a1a2e; color: #ccc; }
@@ -33,8 +37,11 @@ let
3337
.topbar .current { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
3438
.content { display: flex; flex: 1; min-height: 0; }
3539
.source { flex: 1; overflow: auto; padding: 1rem; border-right: 1px solid #333; }
36-
.source pre { margin: 0; font-size: 0.8rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
37-
.source code { font-family: ui-monospace, monospace; }
40+
.file { margin-top: 1rem; }
41+
.file:first-child { margin-top: 0; }
42+
.file h3 { display: inline-block; font-size: 0.7rem; font-weight: 600; color: #aaa; background: #252540; padding: 0.3rem 0.6rem; border-radius: 4px 4px 0 0; margin: 0; }
43+
.file pre { margin: 0; padding: 0.8rem; font-size: 0.8rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; background: #12121f; border-radius: 0 4px 4px 4px; }
44+
.file code { font-family: ui-monospace, monospace; }
3845
.preview { flex: 1; }
3946
.preview iframe { width: 100%; height: 100%; border: none; }
4047
'';
@@ -50,9 +57,15 @@ let
5057
(builtins.tail (pkgs.lib.concatMap (name: [ " - " (exampleLink current name) ]) exampleNames))
5158
];
5259

60+
renderFile = name: file: [ "div.file"
61+
[ "h3" file ]
62+
[ "pre" [ "code" (builtins.readFile ./examples/${name}/${file}) ] ]
63+
];
64+
5365
wrapExample = name: drv:
5466
let
55-
source = builtins.readFile ./examples/${name}/build.nix;
67+
meta = exampleMeta.${name} or {};
68+
files = meta.files or [ "build.nix" ];
5669
page = h.render [ "html" { lang = "en"; }
5770
[ "head"
5871
[ "meta" { charset = "utf-8"; } ]
@@ -62,7 +75,7 @@ let
6275
[ "body"
6376
(navBar name)
6477
[ "div.content"
65-
[ "div.source" [ "pre" [ "code" source ] ] ]
78+
[ "div.source" (map (renderFile name) files) ]
6679
[ "div.preview" [ "iframe" { src = "demo/"; } ] ]
6780
]
6881
]

0 commit comments

Comments
 (0)