jimporter / mike

Manage multiple versions of your MkDocs-powered documentation via Git
BSD 3-Clause "New" or "Revised" License
534 stars 47 forks source link

Is there any way to deploy to a directory? #88

Closed AshleighAdams closed 2 years ago

AshleighAdams commented 2 years ago

Instead of deploying to GitHub Pages, I want to rsync it to a remote server, any idea on the path of least resistance for me?

AshleighAdams commented 2 years ago

Nevermind, found this: https://github.com/squidfunk/mkdocs-material/discussions/3128#discussioncomment-1531268

AshleighAdams commented 2 years ago

Incase anyone finds this in future, here's the script I came up with based on the above comment:

#!/bin/bash
set -eufx -o pipefail

version="$1"
tmp=$(mktemp -d)

mkdocs build --site-dir "site/${version}"

# setup versions.json
if [[ ! -f site/versions.json ]]; then
  echo "creating versions.json"
  echo '[]' > site/versions.json
fi

# insert version if not present
if jq -re '.[] | select(.version == "'$version'")?' site/versions.json; then
    echo "version already present"
else
    echo "adding version"

    echo '[{ "version": "'$version'", "title": "'$version'", "aliases": [] }]' > "$tmp/new-version.json"
    jq -rs add "$tmp/new-version.json" site/versions.json > "$tmp/versions.json"

    cp "$tmp/versions.json" site/versions.json
fi

# setup index.html redirect
cat <<EOF > site/index.html
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Redirecting</title>
  <noscript>
    <meta http-equiv="refresh" content="1; url=master/" />
  </noscript>
  <script>
    window.location.replace("master/" + window.location.hash);
  </script>
</head>

<body>
  Redirecting to <a href="master/">master/</a>...
</body>

</html>
EOF

echo "done"