From 31e0bddb80bfb580f2bb6e1bff2d92cf11d26594 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Sun, 17 May 2020 13:05:21 +0200 Subject: [PATCH] fix: replaced overly complicated redirection rules with a simple hack --- book/book.toml | 2 ++ book/ci/build | 26 ++++++-------------------- book/theme/trailing_slash_hack.js | 18 ++++++++++++++++++ netlify.toml | 3 --- 4 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 book/theme/trailing_slash_hack.js diff --git a/book/book.toml b/book/book.toml index 7528e53b1..d743ef95f 100644 --- a/book/book.toml +++ b/book/book.toml @@ -7,3 +7,5 @@ title = "The Mun Programming Language" [output.html] additional-css = ["theme/mun.css"] +additional-js = ["theme/trailing_slash_hack.js"] +git-repository-url = "https://github.com/mun-lang/mun/tree/master/book" diff --git a/book/ci/build b/book/ci/build index eb1f7c03c..818892031 100755 --- a/book/ci/build +++ b/book/ci/build @@ -1,34 +1,20 @@ #!/bin/bash -set -eo pipefail +set -euo pipefail pushd ./book - # If there is a BASE_URL defined insert that into the head section of the - # book - if [[ ! -z "$BASE_URL" ]]; then - echo "Inserting BASE_URL: $BASE_URL" - echo "" > theme/head.hbs - else - echo "not using BASE_URL" - fi - # Check if mdbook is installed, otherwise download the binaries mdbook="mdbook" if ! [ -x "$(command -v $mdbook)" ]; then - # Ensure cargo is installed - if ! [ -x "$(command -v cargo)" ]; then - # Install rust & cargo - curl https://sh.rustup.rs -sSf | sh -s -- -y - # We have to source the installation - source $HOME/.cargo/env - fi - - # Install mdBook from source echo "Installing mdbook.." - cargo install --git https://github.com/rust-lang/mdBook.git mdbook + curl -sL https://github.com/rust-lang-nursery/mdBook/releases/download/v0.3.7/mdbook-v0.3.7-x86_64-unknown-linux-gnu.tar.gz | tar zxv + mdbook="./mdbook" fi + # Echo mdbook version + $mdbook --version + # First build our custom highlight.js ./ci/build-highlight-js diff --git a/book/theme/trailing_slash_hack.js b/book/theme/trailing_slash_hack.js new file mode 100644 index 000000000..e9b2c3bd1 --- /dev/null +++ b/book/theme/trailing_slash_hack.js @@ -0,0 +1,18 @@ +// This is a very hack to force a trailing slash in case the URL does not point +// directly to an html document. +// +// Netlify doesnt allow changing trailing slashes manually so we have to do +// it this way. +if (!window.location.pathname.endsWith(".html") && + !window.location.pathname.endsWith("/")) { + var url = window.location.protocol + '//' + + window.location.host + + window.location.pathname + '/' + + window.location.search; + + if(window.history && window.history.replaceState) { + window.history.replaceState(null, document.title, url); + } else { + window.location = url + } +} diff --git a/netlify.toml b/netlify.toml index 39ea2144d..b24426341 100644 --- a/netlify.toml +++ b/netlify.toml @@ -5,6 +5,3 @@ from = "/v0.2/*" to = "https://release-v0-2.docs.mun-lang.org/:splat" status = 200 - -[context."release/v0.2"] - environment = { BASE_URL = "/v0.2/" }