This commit is contained in:
Eduardo Garcia 2026-11-16 17:40:50 +08:00 • committed by GitHub
commit 64d385dacd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 160 additions and 1 deletions

View file

@ -96,6 +96,14 @@ This command starts LibreSpeed in standalone mode, with persisted telemetry, ID
docker run -e MODE=standalone -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -e WEBPORT=86 -p 86:86 -v $PWD/db-dir/:/database -it ghcr.io/librespeed/speedtest
```
## Branding the modern design
To give your instance its own colors, background and logo, put your own `theme.css` (and `logo.svg`) in
`/speedtest/frontend/styling/` and `/speedtest/frontend/images/` of the container, either with a bind mount or with a
`COPY` in your own image. Mount at `/speedtest/frontend`, not at `/var/www/html/frontend`: the entrypoint empties
`/var/www/html` and copies the frontend into it at every start. `USE_NEW_DESIGN=true` makes the modern design the default; `index-modern.html` and `?design=new` work without it. The
variables and examples are in [frontend/README.md](frontend/README.md#theming).
## Multiple Points of Test
For multiple servers, you need to set up 1+ LibreSpeed backends, and 1 LibreSpeed frontend.

View file

@ -18,6 +18,64 @@ page fetches them relative to itself:
- `../settings.json` overrides selected `speedtest_worker.js` settings.
- `index.html` and `../index-modern.html` show how the frontend is wired up.
## Theming
The look of the modern design is driven by the CSS variables in `styling/colors.css`. To brand an instance, put your own
values in `styling/theme.css`. That file ships empty and is loaded after `index.css`, so it wins. There is no switch for
the visitors: the host decides.
```css
:root {
--theme-green: #ff8a00; /* accents, links, the tagline */
--theme-pink: #7a2cff; /* the second color of the button and the hover of the links */
--background-backup-color: #101820; /* the page behind the background image */
}
html {
background-image: url("../images/my-background.jpg"); /* relative to theme.css, so to this folder */
}
```
The variables that change the look are the ones in `styling/colors.css`: the accent colors (`--theme-green`,
`--theme-pink`), the texts (`--primary-text-color`, `--secondary-text-color`, `--tagline-text-color`, and the disabled
ones), the background (`--background-backup-color`, `--background-overlay-color`), the start button
(`--button-*`), the server selector (`--server-selector-*`, which includes the text of the options), the gauges (`--gauge-background-color`,
`--gauge-pointer-green`, `--gauge-pointer-pink`), ping and jitter (`--ping-and-jitter-*`) and the popups
(`--popup-background-color`). `--gauge-progress-color` and `--popup-shadow-color` are declared but not used by the
page, so changing them has no effect.
The logo is `images/logo.svg`; put your own file at that path. The favicon is `images/favicon.svg`.
What the theme cannot reach: the colors written inside the SVG files (the logo and the favicon gradient, the chevron and
the close button), the `theme-color` of the page and of `manifest.webmanifest`, and the image that is made for sharing
a result (`results/index.php`). Change those files themselves if you need them to match.
This applies to the modern design only. The classic design and the stability page have their own styles.
### Docker
The container copies `/speedtest/frontend` to the web root every time it starts, so a theme has to be put in
`/speedtest/frontend`, not in `/var/www/html/frontend`. Mounting a file over a path in `/var/www/html` makes the start
fail, because the entrypoint empties that folder first.
```sh
docker run -d -p 80:8080 -e MODE=standalone -e USE_NEW_DESIGN=true \
-v $PWD/theme.css:/speedtest/frontend/styling/theme.css:ro \
-v $PWD/logo.svg:/speedtest/frontend/images/logo.svg:ro \
ghcr.io/librespeed/speedtest
```
To bake the theme into your own image instead of mounting it:
```dockerfile
FROM ghcr.io/librespeed/speedtest
COPY theme.css /speedtest/frontend/styling/theme.css
COPY logo.svg /speedtest/frontend/images/logo.svg
```
`USE_NEW_DESIGN=true` makes the modern design the default; `index-modern.html` and `?design=new` work without it. A change to a mounted file needs a restart of the
container, because the files are copied at start.
## Notes
- The modern frontend expects modern browser features and does not support old

View file

@ -14,6 +14,7 @@
<script type="text/javascript" src="speedtest.js"></script>
<script type="text/javascript" src="javascript/index.js"></script>
<link rel="stylesheet" type="text/css" href="styling/index.css" />
<link rel="stylesheet" type="text/css" href="styling/theme.css" />
<title>LibreSpeed - Free and Open Source Speedtest</title>
</head>

View file

@ -18,6 +18,7 @@
--button-shadow-color: #5cf9fd47;
--button-disabled-background-color: #a2a2a2;
--server-selector-text-color: var(--primary-text-color);
--server-selector-border-color: #625b6b;
--server-selector-hover-border-color: var(--theme-green);
--server-selector-background-color: #251b32;

View file

@ -142,7 +142,7 @@
font-size: 2.4rem;
font-weight: 700;
letter-spacing: -0.2rem;
color: var(--sprint-text-color);
color: var(--server-selector-text-color);
text-transform: uppercase;
text-decoration: none;
text-align: left;

View file

@ -0,0 +1,7 @@
/*
* Branding of the modern design, for people who host LibreSpeed.
*
* This file is empty on purpose and loaded after index.css, so what you write here wins. Replace it, or mount your own
* file over it, to give your instance its own look. See "Theming" in frontend/README.md for the variables, the logo and
* the background image.
*/

View file

@ -17,6 +17,7 @@
</script>
<script type="text/javascript" src="frontend/javascript/index.js"></script>
<link rel="stylesheet" type="text/css" href="frontend/styling/index.css" />
<link rel="stylesheet" type="text/css" href="frontend/styling/theme.css" />
<title>LibreSpeed - Free and Open Source Speedtest</title>
</head>

View file

@ -51,6 +51,9 @@ services:
- WEBPORT=8080
- USE_NEW_DESIGN=true
- "TAGLINE=It'd rather be fast!"
volumes:
# A host theme, mounted where the entrypoint copies the frontend from
- ./e2e/fixtures/theme-host.css:/speedtest/frontend/styling/theme.css:ro
ports:
- "18186:8080"

View file

@ -0,0 +1,8 @@
:root {
--theme-green: rgb(255, 138, 0);
--background-backup-color: rgb(16, 24, 32);
}
html {
background-image: none;
}

View file

@ -68,6 +68,7 @@ module.exports = async () => {
const timeoutMs = 180_000;
await waitForReady('standalone', 'http://127.0.0.1:18180/index.html', timeoutMs);
await waitForReady('standalone-new', 'http://127.0.0.1:18185/index.html', timeoutMs);
await waitForReady('standalone-apostrophe', 'http://127.0.0.1:18186/index.html', timeoutMs);
await waitForReady('standalone-alpine', 'http://127.0.0.1:18187/index.html', timeoutMs);
await waitForReady('backend', 'http://127.0.0.1:18181/empty.php', timeoutMs);
await waitForReady('frontend', 'http://127.0.0.1:18182/index-modern.html', timeoutMs);

View file

@ -7,6 +7,7 @@ const expectedAssets = [
"/settings.json",
"/server-list.json",
"/frontend/styling/index.css",
"/frontend/styling/theme.css",
"/frontend/javascript/index.js",
"/frontend/images/logo.svg",
"/frontend/images/favicon.svg",

70
tests/e2e/theme.spec.js Normal file
View file

@ -0,0 +1,70 @@
const fs = require("node:fs");
const path = require("node:path");
const { test, expect } = require("@playwright/test");
const { baseUrls } = require("./helpers/env");
const staticRepositoryUrl = "http://127.0.0.1:18184";
const root = path.resolve(__dirname, "../..");
const hostTheme = fs.readFileSync(path.join(__dirname, "fixtures/theme-host.css"), "utf8");
const tagline = page => page.locator("main > p.tagline");
const color = locator => locator.evaluate(element => getComputedStyle(element).color);
const rootStyle = page =>
page.evaluate(() => {
const style = getComputedStyle(document.documentElement);
return { image: style.backgroundImage, color: style.backgroundColor };
});
test.describe("Host theme of the modern design", () => {
test("ships an empty theme.css that leaves the default look alone", async ({ page, request }) => {
const response = await request.get(`${staticRepositoryUrl}/frontend/styling/theme.css`);
expect(response.ok()).toBeTruthy();
expect(await response.text()).not.toContain("{");
await page.goto(`${staticRepositoryUrl}/index-modern.html`);
expect(await color(tagline(page))).toBe("rgb(92, 249, 253)");
expect((await rootStyle(page)).image).toContain("background.jpeg");
});
test("a theme.css of the host changes the colors and the background", async ({ page }) => {
await page.route("**/frontend/styling/theme.css", route =>
route.fulfill({ body: hostTheme, contentType: "text/css" })
);
await page.goto(`${staticRepositoryUrl}/index-modern.html`);
expect(await color(tagline(page))).toBe("rgb(255, 138, 0)");
expect(await rootStyle(page)).toEqual({ image: "none", color: "rgb(16, 24, 32)" });
});
test("a relative url in theme.css is relative to the theme.css", async ({ page }) => {
await page.route("**/frontend/styling/theme.css", route =>
route.fulfill({
body: 'html { background-image: url("../images/background-original.jpeg"); }',
contentType: "text/css"
})
);
const requested = page.waitForRequest("**/frontend/images/background-original.jpeg");
await page.goto(`${staticRepositoryUrl}/index-modern.html`);
await requested;
});
test("both modern pages load theme.css after index.css", () => {
const link = (file, folder) => {
const html = fs.readFileSync(path.join(root, file), "utf8");
return [html.indexOf(`${folder}index.css`), html.indexOf(`${folder}theme.css`)];
};
for (const [file, folder] of [
["index-modern.html", "frontend/styling/"],
["frontend/index.html", "styling/"]
]) {
const [index, theme] = link(file, folder);
expect(index, file).toBeGreaterThan(-1);
expect(theme, file).toBeGreaterThan(index);
}
});
test("a theme.css mounted in the Docker image is the one that is served", async ({ page }) => {
await page.goto(`${baseUrls.standaloneApostrophe}/index-modern.html`);
expect(await color(tagline(page))).toBe("rgb(255, 138, 0)");
expect(await rootStyle(page)).toEqual({ image: "none", color: "rgb(16, 24, 32)" });
});
});