Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions src/components/CodeSnippet.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import { Code } from "astro:components";
import lightPlus from "@shikijs/themes/light-plus";
import darkPlus from "@shikijs/themes/dark-plus";
interface Props {
code: string;
}
Expand All @@ -9,25 +10,46 @@ const { code } = Astro.props;

import flixGrammar from "../grammars/flix.tmLanguage.json";

// Light+ colors `keyword`/`storage` blue but `keyword.control` magenta;
// unify them so all Flix keywords share the magenta. `storage.modifier` is
// named explicitly because the most specific selector wins rather than the last
// one, so a bare `storage` here loses to Light+'s own `storage.modifier` rule.
const theme = {
...lightPlus,
name: "light-plus-flix",
// Both Plus themes color `keyword`/`storage` blue but `keyword.control`
// magenta; unify them so all Flix keywords share the magenta. `storage.modifier`
// is named explicitly because the most specific selector wins rather than the
// last one, so a bare `storage` here loses to the theme's own
// `storage.modifier` rule. The two magentas are each theme's own, not one value
// used twice: #AF00DB is legible on white and would be far too dark on #1a1d20.
// The name is derived rather than passed so it cannot drift from the theme it
// describes; it reaches the markup as a class, so it wants to stay truthful.
// Typed off lightPlus because `shiki` itself is not a dependency here -- it
// resolves only through astro -- and @shikijs/themes already declares its
// exports as ThemeRegistration.
const unifyKeywords = (base: typeof lightPlus, foreground: string) => ({
...base,
name: `${base.name}-flix`,
tokenColors: [
...(lightPlus.tokenColors ?? []),
...(base.tokenColors ?? []),
{
scope: ["keyword", "storage", "storage.modifier"],
settings: { foreground: "#AF00DB" },
settings: { foreground },
},
],
});

// Shiki emits both themes at once: the light colors land in `color` and the
// dark ones in a --shiki-dark custom property beside them, which global.css
// switches between. Keeping light as the default means the markup renders
// correctly for the light theme with no CSS applied at all.
const themes = {
light: unifyKeywords(lightPlus, "#AF00DB"),
dark: unifyKeywords(darkPlus, "#C586C0"),
};
---

<div class="code-snippet-frame">
<div class="code-snippet-code">
<Code code={code} theme={theme} lang={flixGrammar} />
<Code
code={code}
themes={themes}
defaultColor="light"
lang={flixGrammar}
/>
</div>
</div>
80 changes: 78 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,44 @@ const footerGroups = [
];

import FlixMark from '../components/FlixMark.astro';
import { Icon } from 'astro-icon/components';
import '../styles/global.css';
---
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

{/* First thing in the head, and is:inline so it stays here rather than
being bundled into a deferred module: it has to have set the attribute
before the first paint, and a deferred script runs after it, which is
the flash of the wrong theme this exists to prevent.

Bootstrap 5.3 keys its whole dark palette off data-bs-theme and ships no
prefers-color-scheme rules of its own, so the media query cannot be left
to CSS and is read here. localStorage is wrapped because it throws
outright, rather than returning null, when site data is blocked. */}
<script is:inline>
(() => {
let stored = null;
try {
stored = localStorage.getItem("theme");
} catch {}
const theme =
stored === "light" || stored === "dark"
? stored
: matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
document.documentElement.setAttribute("data-bs-theme", theme);
})();
</script>

{/* Covers the gap before the stylesheet applies, and tells the browser to
draw the scrollbar and any form controls to match. */}
<meta name="color-scheme" content="light dark" />

<title>{title}</title>
<meta name="description" content={description} />
{
Expand Down Expand Up @@ -145,13 +176,28 @@ import '../styles/global.css';
alt="Fork me on GitHub">
</a>
{/* data-bs-theme has to sit on the .navbar itself: Bootstrap keys the
light-on-dark link and toggler colours off .navbar[data-bs-theme="dark"]. */}
<nav class="navbar bg-dark navbar-expand-lg menu shadow-sm mb-4" data-bs-theme="dark" aria-label="Main">
light-on-dark link and toggler colours off .navbar[data-bs-theme="dark"].
It says nothing about the background, which .menu paints. */}
<nav class="navbar navbar-expand-lg menu shadow-sm mb-4" data-bs-theme="dark" aria-label="Main">
<div class="container-fluid">
<a class="navbar-brand d-flex align-items-center gap-2" href="/">
<FlixMark size={24} />
Flix
</a>
{/* Deliberately outside the collapse: the theme is worth changing
on a phone too, and inside it the button would only be reachable
by first opening the menu. order-lg-last sends it to the far end
once the nav expands, since in source order it has to precede
the collapse to sit left of the hamburger below that. */}
<button
class="btn btn-sm theme-toggle ms-auto ms-lg-0 me-2 me-lg-0 order-lg-last d-flex align-items-center"
type="button"
aria-label="Switch between the light and dark theme"
title="Switch between the light and dark theme"
>
<Icon name="mdi:weather-night" class="theme-toggle-to-dark" size={18} />
<Icon name="mdi:weather-sunny" class="theme-toggle-to-light" size={18} />
</button>
<button
class="navbar-toggler"
type="button"
Expand Down Expand Up @@ -252,6 +298,36 @@ import '../styles/global.css';
// frontmatter alongside the stylesheet import.
import "bootstrap/js/dist/collapse";
import "bootstrap/js/dist/carousel";

// The head script already picked the theme; this only handles changing it
// afterwards, so it can wait for the bundle. Writing to localStorage is
// what turns a choice into a preference: from then on the branch above
// reads it and stops consulting the OS.
const root = document.documentElement;

document.querySelector(".theme-toggle")?.addEventListener("click", () => {
const next =
root.getAttribute("data-bs-theme") === "dark" ? "light" : "dark";
root.setAttribute("data-bs-theme", next);
try {
localStorage.setItem("theme", next);
} catch {}
});

// Follow the OS live, but only for visitors who have never used the
// toggle -- once they have, their choice outranks it.
matchMedia("(prefers-color-scheme: dark)").addEventListener(
"change",
(event) => {
let stored = null;
try {
stored = localStorage.getItem("theme");
} catch {}
if (stored !== "light" && stored !== "dark") {
root.setAttribute("data-bs-theme", event.matches ? "dark" : "light");
}
},
);
</script>
</body>
</html>
6 changes: 3 additions & 3 deletions src/pages/documentation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const smallLinks = [
Programming Flix (doc.flix.dev)
</a>
</div>
<p class="card-text text-dark text-center">
<p class="card-text text-body text-center">
A detailed introduction to the Flix Programming Language.
</p>
</div>
Expand All @@ -80,7 +80,7 @@ const smallLinks = [
Standard Library (api.flix.dev)
</a>
</div>
<p class="card-text text-dark text-center">
<p class="card-text text-body text-center">
A Javadoc-style description of the Flix Standard Library.
</p>
</div>
Expand All @@ -99,7 +99,7 @@ const smallLinks = [
<div class="col-lg-2">
<a href={link}>
<div class="card h-100 card-body">
<div class="text-center m-4 text-black-50 card-subtitle">
<div class="text-center m-4 text-body-secondary card-subtitle">
<Icon name={icon} size={SMALL_ICON_SIZE} />
</div>
<div class="text-center link-primary card-title">{text}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/get-started.astro
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const installs = [
<div class="col">
<div class="card ms-5 me-5">
<img
class="card-img-top"
class="card-img-top plate"
src="/gif/install.png"
alt="Installing the Flix extension from the Visual Studio Code Extensions view"
/>
Expand Down
20 changes: 10 additions & 10 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ const vscodeSlides = [
<div class="card">
<img
src="/images/standardLibrary.png"
class="card-img"
class="card-img plate"
alt="Standard Library"
loading="lazy"
/>
Expand Down Expand Up @@ -757,7 +757,7 @@ const vscodeSlides = [
<div class="col-md-6">
<img
src="/images/speedupWithPar.png"
class="img-fluid"
class="img-fluid plate p-3"
alt="Parallel Speedup"
loading="lazy"
/>
Expand Down Expand Up @@ -1133,7 +1133,7 @@ const vscodeSlides = [

<div class="row mb-4">
<div class="col-md">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/dff.png"
class="card-img"
Expand All @@ -1143,7 +1143,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/dara-academy.png"
class="card-img"
Expand All @@ -1153,7 +1153,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/direc.png"
class="card-img"
Expand All @@ -1163,7 +1163,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/amazon-science.png"
class="card-img"
Expand All @@ -1173,7 +1173,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img src="/logo/stibo.png" class="card-img" alt="StiboFonden" loading="lazy" />
</div>
</div>
Expand All @@ -1189,7 +1189,7 @@ const vscodeSlides = [

<div class="row mb-4">
<div class="col-md-3">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/aarhusu.png"
class="card-img"
Expand All @@ -1199,7 +1199,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md-4">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/uwaterloo.png"
class="card-img"
Expand All @@ -1209,7 +1209,7 @@ const vscodeSlides = [
</div>
</div>
<div class="col-md-3">
<div class="card border-0 p-3">
<div class="card border-0 p-3 plate">
<img
src="/logo/tubingen.png"
class="card-img"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/vscode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const features = [
<h4 class="card-title">{f.title}</h4>
<p class="card-text mb-0" set:html={f.desc}></p>
</div>
<img class="card-img-bottom" src={f.img} alt={f.alt} loading={i < 2 ? "eager" : "lazy"} />
<img class="card-img-bottom plate" src={f.img} alt={f.alt} loading={i < 2 ? "eager" : "lazy"} />
</div>
</div>
))}
Expand Down
Loading