Skip to content

Commit

Permalink
fix scroll to location hash (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri authored Mar 12, 2024
1 parent 84dceeb commit 59d9211
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { readFileSync } from "fs";
import { join } from "path";
import { defineConfig } from "vitepress";

const toggleSyntaxScript = readFileSync(join(__dirname, './toggleSyntax.js'), 'utf8');

// From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/reason.json
const reasonGrammar = JSON.parse(
readFileSync(join(__dirname, "./reasonml.tmLanguage.json"), "utf8")
Expand All @@ -12,6 +14,13 @@ const base = process.env.BASE || "unstable";
// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Melange Documentation Site",
head:[
[
'script',
{},
toggleSyntaxScript
]
],
description:
"The official documentation site for Melange, a compiler from OCaml to JavaScript. Explore the features and resources for functional programming with Melange, including the standard libraries APIs, the playground, and extensive documentation about bindings, build system, and the opam package manager.",
base: `/${base}/`,
Expand Down
19 changes: 19 additions & 0 deletions docs/.vitepress/toggleSyntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Keep in sync with Switch.vue
// Just needed so that Vitepress finds the content already in the right
// position when it scrolls to location hash
document.addEventListener("DOMContentLoaded", () => {
const SYNTAXES = ["reasonml", "ocaml"];
const CLASS_PREFIX = "syntax__";
let currentSyntax;
let setCurrentSyntax = (syntax = SYNTAXES[0]) => {
document.body.classList.remove(`${CLASS_PREFIX}${currentSyntax}`);
document.body.classList.add(`${CLASS_PREFIX}${syntax}`);

currentSyntax = syntax;
localStorage.setItem("syntax", currentSyntax);
};

setCurrentSyntax(
localStorage.getItem("syntax", currentSyntax) || SYNTAXES[0]
);
});

0 comments on commit 59d9211

Please sign in to comment.