diff --git a/overview/default.nix b/overview/default.nix index 174c744ad..594263b3c 100644 --- a/overview/default.nix +++ b/overview/default.nix @@ -101,6 +101,32 @@ let markdownToHtml = markdown: "{{ markdown_to_html(${toJSON markdown}) }}"; render = { + # A code snippet that is copyable and optionally downloadable + codeSnippet.one = + { + filename, + language ? "nix", + relative ? false, + downloadable ? false, + }: + '' +
+ {{ include_code("${language}", "${filename}" ${optionalString relative ", relative_path=True"}) }} +
+ ${optionalString downloadable '' + Download + ''} + +
+
+ ''; options = rec { one = prefixLength: option: @@ -148,7 +174,7 @@ let one = example: ''
${example.description} - {{ include_code("nix", "${example.module}")}} + ${render.codeSnippet.one { filename = example.module; }}
''; @@ -274,7 +300,11 @@ let Download this Nix file to your computer. It obtains the NGIpkgs source code and declares a basic service configuration to be run in a virtual machine. - {{ include_code("nix", "default.nix", relative_path=True) }} + ${render.codeSnippet.one { + filename = "default.nix"; + relative = true; + downloadable = true; + }}
  • Build the virtual machine defined in default.nix and run it: @@ -377,7 +407,26 @@ let - ${args.content} + ${args.content} + ''; diff --git a/overview/style.css b/overview/style.css index 4e50943db..d645bbae0 100644 --- a/overview/style.css +++ b/overview/style.css @@ -286,6 +286,50 @@ code, pre { overflow-x: auto; } +.code-block { + position: relative; +} + +.code-buttons { + position: absolute; + top: 0.5em; + right: 1em; +} + +.button { + display: inline-block; + padding: 0.1em 0.4em; + background-color: transparent; + color: white; + text-align: center; + text-decoration: none; + border-radius: 5px; + border: solid 1px gray; + background-color: gray; + margin: 0; + font-size: 0.8rem; +} + +.button.copy:before { + content: "⿻"; +} + +.button.download:before { + content: "⭳"; +} + +.button.download { + background-color: green; +} + +.button.copy:hover { + background-color: darkgrey; +} + +.button.download:hover { + background-color: darkgreen; +} + details > summary > h2, details > summary > h3 { display: inline; }