I'm boarding a plane in a few minutes, but I'd like to still have access to hex.docs.
How hard could it be to get docs running locally so I don't need a connection to use them?
...
It turns out to be very, very easy. The Elixir guys thought of everything!
Step 1: Fetch the docs you want
# From any mix directory
mix hex.docs fetch elixir
mix hex.docs fetch kino
mix hex.docs fetch nx
mix hex.docs fetch scholar
mix hex.docs fetch livebook
...
You may need to check the versions and fetch a specific one you're interested in...
mix hex.docs fetch nx 0.5.2
Step 2: Run a local web server from the doc root
On a Mac, the default location for docs is:
/Users/<user>/.hex/docs/hexpm
I use Caddy so with that it's as easy to run a local instance as a single command from the directory:
cd /Users/<user>/.hex/docs/hexpm
caddy file-server --browse --listen :5051
Go to http://localhost:5051 to test.
Bonus step: Create a script for the future
Let's go ahead and automate this. You could create an alias but I prefer to create small scripts that I keep on my PATH to run again whenever needed. In my case, I have a directory at ~/projects/utils
touch ~/projects/utils/local_docs.sh
echo "cd /Users/$(whoami)/.hex/docs/hexpm" > ~/projects/utils/local_docs.sh
echo "caddy file-server --browse --listen :5051" >> ~/projects/utils/local_docs.sh
echo "cd -" >> ~/projects/utils/local_docs.sh
chmod u+x ~/projects/utils/local_docs.sh
Now whenever I want to start my local docs I can just run:
local_docs.sh
Top comments (1)
Here's a command to start a Python web server so you don't have to download Caddy:
cd /Users/<user>/.hex/docs/hexpm && python3 -m http.server 5051