Skip to content

Commit

Permalink
Migrate from mkdocs to vitepress (#161)
Browse files Browse the repository at this point in the history
* add vitepress

* vitepress: fix docs:build

* vitepress: add syntax toggle

* vitepress: add missing sidebar items

* vitepress: add reason syntax highlight

* vitepress: add sitemap and search

* vitepress: handle api docs

* vitepress: deploy to unstable

* vitepress: fix playground link

* vitepress: attempt to fix deploy

* vitepress: debug + more attempts

* vitepress: try to fix playground

* vitepress: fix mobile layout

* vitepress: test _self with api links

* vitepress: change outline level

* vitepress: add target self for api links

* vitepress: add edit on github

* vitepress: fix reason snippets top margin

* vitepress: cleanup python + fix publish version
  • Loading branch information
jchavarri authored Feb 9, 2024
1 parent 451d6b2 commit 711779c
Show file tree
Hide file tree
Showing 28 changed files with 3,600 additions and 508 deletions.
31 changes: 21 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Setup Node
uses: actions/setup-node@v4
with:
python-version: 3.x
- run: python3 -m pip install -r ./pip-requirements.txt
node-version: 20
cache: yarn
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 5.1.1
Expand All @@ -25,24 +26,34 @@ jobs:
- name: Generate melange docs in ml syntax
run: opam reinstall -y melange --with-doc
- name: Copy melange docs in ml syntax
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/api/ml
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/public/api/ml
- name: Generate melange docs in re syntax
run: ODOC_SYNTAX="re" opam reinstall -y melange --with-doc
- name: Copy melange docs in re syntax
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/api/re
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/public/api/re
- name: Run canonical script
run: opam exec -- dune exec add_canonical docs/api
run: opam exec -- dune exec add_canonical docs/public/api
- name: Check Reason syntax
run: make check-reason
- name: Check extracted code blocks
run: make check-extracted-code-blocks
- name: Run tests
run: make test
- name: Build playground
run: make build-playground
- name: Build site (and playground)
run: make build-site
- name: Configure Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- run: git fetch origin gh-pages --depth=1
- run: mike deploy --push unstable
- name: Fetch and checkout gh-pages
run: |
git fetch origin gh-pages --depth=1
git checkout gh-pages
- name: Copy published site into folder
run: cp -TRv docs/.vitepress/dist/ unstable/
- name: Add unstable files to git index
run: git add unstable
- name: Committing
run: git commit -m 'Deployed ${{ github.sha }} to unstable'
- name: Push
run: git push
32 changes: 21 additions & 11 deletions .github/workflows/publish-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Setup Node
uses: actions/setup-node@v4
with:
python-version: 3.x
- run: python3 -m pip install -r ./pip-requirements.txt
node-version: 20
cache: yarn
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 5.1.1
Expand All @@ -23,26 +24,35 @@ jobs:
- name: Generate melange docs
run: opam reinstall -y melange --with-doc
- name: Copy melange docs in ml syntax
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/api/ml
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/public/api/ml
- name: Generate melange docs in re syntax
run: ODOC_SYNTAX="re" opam reinstall -y melange --with-doc
- name: Copy melange docs in re syntax
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/api/re
run: cp -r _opam/.opam-switch/build/melange.dev/_build/default/_doc/_html docs/public/api/re
# only uncomment after a new version is released, from inside a `x.x.x-patches` branch
# - name: Run canonical script
# run: opam exec -- dune exec add_canonical docs/api
# run: opam exec -- dune exec add_canonical docs/public/api
- name: Check Reason syntax
run: make check-reason
- name: Check extracted code blocks
run: make check-extracted-code-blocks
- name: Run tests
run: make test
- name: Build playground
run: make build-playground
- name: Build site (and playground)
run: BASE=${{ github.ref_name }} make build-site
- name: Configure Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- run: git fetch origin gh-pages --depth=1
- run: mike deploy ${{ github.ref_name }}
- run: mike set-default --push ${{ github.ref_name }}
- name: Fetch and checkout gh-pages
run: |
git fetch origin gh-pages --depth=1
git checkout gh-pages
- name: Copy published site into folder
run: cp -TRv docs/.vitepress/dist/ ${{ github.ref_name }}/
- name: Add ${{ github.ref_name }} files to git index
run: git add ${{ github.ref_name }}
- name: Committing
run: git commit -m 'Deployed ${{ github.sha }} to ${{ github.ref_name }}'
- name: Push
run: git push
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ _build
_opam
.vscode
.DS_Store
node_modules

docs/playground
docs/.vitepress/cache
docs/.vitepress/dist
docs/public/playground
docs/public/api/ml
docs/public/api/re
docs/api/ml
docs/api/re
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ format-check: ## Checks if format is correct
build-playground: ## Builds the playground
$(DUNE) build @playground-assets
cd playground && yarn && yarn build

.PHONY: build-site
build-site: build-playground ## Builds the whole site (including playground)
yarn && yarn docs:build
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ https://github.com/melange-re/melange.
## Working locally

After cloning the repository, install the necessary Python packages:
After cloning the repository, install the necessary JavaScript packages:

```
python3 -m pip install -r ./pip-requirements.txt
yarn
```

Then run `mkdocs serve .` from the folder where the repository lives.
Then run `yarn docs:dev` from the folder where the repository lives.

### (Optional) Tooling for docs generation

Expand Down Expand Up @@ -53,8 +53,7 @@ dune build @re --auto-promote

Publishing is done automatically from GitHub actions:
- Every commit to `master` will publish in the `unstable` folder
- Every tag pushed with the `v*` format will publish on its corresponding
folder, and set it as default
- Every tag pushed with the `v*` format will publish on its corresponding folder

### Tracking new versions of `melange` in opam

Expand Down Expand Up @@ -94,15 +93,5 @@ move-vx.x.x-tag: ## Moves the vx.x.x tag to the latest commit, useful to publish
- update the version in `add_canonical.ml`
- run `dune test --auto-promote`
- uncomment the relevant code in `publish-version.yml`
- Finally, we need to disable the publication of previous version `y.y.y` as the
default version:
- In `y.y.y-patches`: update `publish-version.yml` so that `mike deploy -push`
is used and `set-default` is removed. The diff should look like:
```diff
+ - run: mike deploy --push ${{ github.ref_name }}
- - run: mike deploy ${{ github.ref_name }}
- - run: mike set-default --push ${{ github.ref_name }}
```

- Commit and run `make move-vy.y.y-tag` to deploy.

- In the `gh-pages` branch, replace the default version with the new one [in
index.html](https://github.com/melange-re/melange-re.github.io/blob/gh-pages/index.html#L10)
111 changes: 111 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { readFileSync } from "fs";
import { join } from "path";
import { defineConfig } from "vitepress";

// From https://github.com/ocamllabs/vscode-ocaml-platform/blob/master/syntaxes/reason.json
const reasonGrammar = JSON.parse(
readFileSync(join(__dirname, "./reasonml.tmLanguage.json"), "utf8")
);

const base = process.env.BASE || "unstable";

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "Melange Documentation Site",
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}/`,
sitemap: {
hostname: "https://melange.re/unstable/",
},
markdown: {
languages: [reasonGrammar],
},
themeConfig: {
outline: {level: [2, 3]},
search: {
provider: "local",
},
editLink: {
pattern: 'https://github.com/melange-re/melange-re.github.io/edit/master/docs/:path'
},
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: "Learn", link: "/what-is-melange" },
{ text: "API", link: "/api" },
{ text: "Playground", link: "/playground/", target: '_self' },
{
text: "unstable",
items: [
{
text: "v3.0.0",
link: "https://melange.re/v3.0.0/",
},
{
text: "v2.2.0",
link: "https://melange.re/v2.2.0/",
},
{
text: "v2.1.0",
link: "https://melange.re/v2.1.0/",
},
{
text: "v2.0.0",
link: "https://melange.re/v2.0.0/",
},
{
text: "v1.0.0",
link: "https://melange.re/v1.0.0/",
},
],
},
],

sidebar: [
{
text: "Intro",
items: [
{ text: "What is Melange", link: "/what-is-melange" },
{ text: "Rationale", link: "/rationale" },
{ text: "Getting Started", link: "/getting-started" },
],
},
{
text: "Learn",
items: [
{ text: "New to OCaml?", link: "/new-to-ocaml" },
{ text: "Package Management", link: "/package-management" },
{ text: "Build System", link: "/build-system" },
{
text: "Communicate with JavaScript",
link: "/communicate-with-javascript",
},
{ text: "How-to Guides", link: "/how-to-guides" },
{
text: "Melange for X Developers",
link: "/melange-for-x-developers",
},
],
},
{
text: "Reference",
items: [{ text: "API", link: "/api" }],
},
{
text: "Try",
items: [{ text: "Playground", link: "/playground/", target: '_self' }],
},
{
text: "About",
items: [
{ text: "Community", link: "/community" },
{ text: "Roadmap", link: "/roadmap" },
],
},
],

socialLinks: [
{ icon: "github", link: "https://github.com/melange-re/melange" },
],
},
});
Loading

0 comments on commit 711779c

Please sign in to comment.