Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replaced overly complicated redirection rules with a simple hack #196

Merged
merged 1 commit into from
May 17, 2020
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: 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 big hack to force a trailing slash in case the URL does not
// point directly to an html document.
//
// Netlify doesn't allow changing trailing slashes with redirects 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/" }