A dead simple Node Express app that serves static Material Themed docs generated by Mkdocs from behind basic authentication.
- Clone this repo
- Install Node dependencies:
npm i
(seepackage.json
) - Run
npm start
to see the current state of the ebook. - Start with
ebook-folder/mkdocs.yml
this is the configuration file for this book
To be able to edit the ebook you will need to follow these steps first:
- Install Python 3.7+ on to your computer
- pip3 should be installed with Python but if not: install pip or
pip3 install pip3
cd ebook-folder
to move into the Python package- run
git clone https://github.com/squidfunk/mkdocs-material.git
- Install the Python Packages
pip3 install -r requirements.txt
(Seerequirements.txt
) orpip3 install -r requirements.txt
- Run
mkdocs build
to build the markdown files into static HTML files into thesite/
directory.
NOTE1: if you are running Python 2.7 this will not work. You'll need to update to Python 3.7 or higher.
NOTE2: if you are still running into the error your machine may have Python 2.7 set as a default. Change it to an alias so you always use 3.7+ or change to alternative versions.
NOTE3: potential updates needed to Python packages, see
requirements.txt
. Upgradedpymdown_extensions-8.1.1
topymdown_extensions-9.4
&mkdocs-1.1.2
tomkdocs-1.3.0
on May 10, 2022. Runpip3 install <package> --upgrade
to fix.
To serve the files in site/
to port 8000 withOUT username:password
authentication simply run mkdocs serve
to see the documentation at http://127.0.0.1:8000/
To serve with basic username:password
authentication you'll need to add a .env
file with environment variables to the root directory:
cd ..
echo "STUDENT_USERNAME=a-username STUDENT_PASSWORD=a-password INSTRUCTOR_USERNAME=a-username INSTRUCTOR_PASSWORD=a-password PORT=5500" >> .env
STUDENT_USERNAME=a-username
STUDENT_PASSWORD=a-password
INSTRUCTOR_USERNAME=a-username
INSTRUCTOR_PASSWORD=a-password
PORT=5500
- From
ebook-folder
runmkdocs serve
- From root directory run
npm start
- to serve files fromsite/
to port 5500 with username:password authentication
Go to
ebook-folder/mkdocs.yml
for further instructions + seeebook-folder/workspace
for templates and notes.
While working in
ebook-folder/
you can simply usemkdocs build
andmkdocs serve
to by-pass the Node server.
- Finish your changes and check them with
mkdocs serve
. - Before you
git add
anything to staging runmkdocs build
. This will ensure you've built the newest intended version of the ebook before you push it to GitHub. git status, add, commit, push ...
to repo- Create pull request & merge
Heroku will need some environment variables to perform authentication checks. Add them as you would the variables in .env
file using he CLI tools or the dashboard.
ENVIRONMENT
:PRODUCTION
STUDENT_USERNAME
:<a-username>
STUDENT_PASSWORD
:<a-password>
INSTRUCTOR_USERNAME
:<a-username>
INSTRUCTOR_PASSWORD
:<a-password>
How to install Python and pip instructions here:
Mkdocs is a Python package that generates statics web files (HTML, CSS, JS), seen in the site/
directory, from plain Markdown files, seen in the docs/
directory.
Material-Mkdocs is another Python package that builds on top of Mkdocs to provide design from the Material-UI Theme. The two receive their configuration from the mkdocs.yaml
file. You'll see the navigation is provided by the nav:
property in that file and the Material Theme is the value of theme:
.
The Express server is just an app used to serve the static files from site/
behind basic authentication thus the Node app is deployed and not the Python code.