Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

website(docs): Fix some regressions #3694

Merged
merged 6 commits into from
Nov 12, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
version: 7
- name: Build WASM module for the web
run: wasm-pack build --out-dir ../../npm/wasm-web --target web --release --scope rometools crates/rome_wasm
run: wasm-pack build --out-dir ../../npm/wasm-web --target web --scope rometools crates/rome_wasm
- name: Install libraries
working-directory: website
run: pnpm i
Expand Down
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"rehype-slug": "^5.1.0",
"rehype-toc": "^3.0.2",
"remark-toc": "^8.0.1",
"rome": "^10.0.1",
"sass": "^1.56.1",
"typescript": "^4.8.4",
"vite": "3.1.8",
Expand Down
64 changes: 64 additions & 0 deletions website/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions website/src/frontend-scripts/docsearch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import docsearch from "@docsearch/js";
import { matchesDark, setCurrentTheme } from "./util";

const docsearchContainer = document.querySelector(
"#docsearch-target",
) as HTMLElement;

// We need to explicitly set data-theme as docsearch explicitly matches for it
if (matchesDark.matches) {
setCurrentTheme("dark");
}

docsearch({
appId: "ZKNROT3Q65",
apiKey: "6c573608bd6c44671bfc263fb83992e2",
Expand Down
8 changes: 4 additions & 4 deletions website/src/frontend-scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { matchesDark, getCurrentTheme } from "./util";
import { matchesDark, getCurrentTheme, setCurrentTheme } from "./util";
import "./mobile";
import "./toc";
import "./package-manager-commands";
Expand Down Expand Up @@ -44,7 +44,6 @@ for (const elem of collapsed) {
function toggleColorSchemeSwitch(evt: Event) {
const currentScheme = getCurrentTheme();
const newScheme = currentScheme === "dark" ? "light" : "dark";
window.localStorage.setItem("data-theme", newScheme);

if (evt.currentTarget instanceof Element) {
evt.currentTarget.setAttribute(
Expand All @@ -54,7 +53,8 @@ function toggleColorSchemeSwitch(evt: Event) {
}

document.documentElement.classList.add("transition");
document.documentElement.setAttribute("data-theme", newScheme);
window.localStorage.setItem("data-theme", newScheme);
setCurrentTheme(newScheme);
onColorSchemeChange();
}

Expand All @@ -68,7 +68,7 @@ if (colorSchemeSwitcher != null) {
colorSchemeSwitcher.addEventListener("click", toggleColorSchemeSwitch, false);
}

matchesDark().addEventListener("change", () => {
matchesDark.addEventListener("change", () => {
onColorSchemeChange();
});

Expand Down
11 changes: 6 additions & 5 deletions website/src/frontend-scripts/util.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export type ThemeName = "dark" | "light";

export function matchesDark() {
return window.matchMedia("(prefers-color-scheme: dark)");
}
export const matchesDark = window.matchMedia("(prefers-color-scheme: dark)");

export function getCurrentTheme(): ThemeName {
let currentScheme = window.localStorage.getItem("data-theme");
if (currentScheme == null) {
const prefersDarkMode = matchesDark().matches;
currentScheme = prefersDarkMode ? "dark" : "light";
currentScheme = matchesDark.matches ? "dark" : "light";
}
return currentScheme === "dark" ? "dark" : "light";
}

export function setCurrentTheme(theme: ThemeName) {
document.documentElement.setAttribute("data-theme", theme);
}
2 changes: 2 additions & 0 deletions website/src/styles/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ footer {
background-color: var(--container-color);
border-right: 1px solid var(--hard-border-color);
padding: 20px;
flex-shrink: 0;

@include mobile-only {
position: fixed;
Expand Down Expand Up @@ -318,6 +319,7 @@ footer {

.toc-sidebar {
right: 0;
white-space: nowrap;

h2 {
padding-left: 32px;
Expand Down
2 changes: 1 addition & 1 deletion website/src/svg/npm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.