Skip to content

Commit

Permalink
fix: replaced overly complicated redirection rules with a simple hack
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed May 17, 2020
1 parent 8c20b47 commit 31e0bdd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 2 additions & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 6 additions & 20 deletions book/ci/build
Original file line number Diff line number Diff line change
@@ -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 "<base href=\"$BASE_URL\" />" > 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

Expand Down
18 changes: 18 additions & 0 deletions book/theme/trailing_slash_hack.js
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 0 additions & 3 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/" }

0 comments on commit 31e0bdd

Please sign in to comment.