A complete browser-based, what-you-see-is-what-you-get editor to streamline the process of editing TeachBooks hosted on GitHub pages.
The editor is made for everyone, not just programmers. So we made the installation process as easy as possible:
- Go to your TeachBooks repo root
- In
requirements.txtadd the following two lines at the bottom of the file:--extra-index-url https://test.pypi.org/simple/ teachbooks_software_project_extension_name==0.1.3
- After saving
requirements.txtopen thebookfolder and edit the_config.ymlfile - Find the
extra_extensions:area and add the following to the bottom of the list:- teachbooks_software_project_extension_name - Save the config file and the GitHub actions will automatically build your book with the editor installed
For building the editor from source you have to build the two different components and combine them into the full editor.
The first component is the Vite app. For developing the app, you need
- NodeJS, version 22 (LTS)
- The pnpm package manager
- Preferably, using corepack
- In the
appfolder, if not enabled, enable the single file plugin invite.config.tsby uncommentingviteSingleFile()underplugins. - In the project root run:
cd app pnpm install
- We need to build the app, so we can use it later on. So still in the app folder run:
pnpm build
- The output will be located in
app/dist.
For loading the editor into the book we use a custom Sphinx Extension. You need Python 3.12 with pip installed
- Copy the
distfolder from building the Vite app to the_staticfolder of the extension by running the following in the project root:- MacOS or Linux:
cp -r app/dist sphinx_extension/teachbooks_software_project_extension_name/_static
- Windows:
robocopy app/dist sphinx_extension/teachbooks_software_project_extension_name/_static /E
- Pip install the extension by running the following in the project root:
pip install -e ./sphinx_extension
- Or build for distribution by running the following from the project root:
This will create a
cd sphinx_extension && python -m build
distfolder in thesphinx_extensionfolder.
We assume you already have a working TeachBooks installed locally. If not you can get the template here.
- Open the
_configfile in thebookfolder of your TeachBooks project. - Find the
extra_extensions:area and add the following to the bottom of the list:- teachbooks_software_project_extension_name - Because this only works locally you have to build the book yourself. You can make a clean build by running:
jupyter-book clean book && jupyter-book build book - This creates a
buildfolder with the actualhtmlfolder. - For the editor to work you cannot just open the
index.htmlin a browser. You have to start an actual live server.- In VS Code you can right-click
index.htmland selectOpen with Live Server - In JetBrains editors you can right-click
index.htmland selectOpen Inand thenBrowser
- In VS Code you can right-click
If you want to contribute or maintain this open source project there are a few guidelines written down below.
To keep the code readable and maintainable we use different tools:
- Prettier for code formatting
pnpm prettier
- Linting for code style
pnpm lint
- If you want to let
prettierandlintingsolve the fixable issues in your code you can runpnpm format
- We try to make sure every function is well documented with either
Python DocstringsorJSDocs.
To make sure the editor actually works we have made a comprehensive test suite, but more tests are always welcome.
- Tests are defined in
app/tests/asTypeScriptfiles withtestorspecin the file name. - For an example test you can check out the index.test.tsx file.
- Run the tests by running the following in the
appfolderpnpm test- If you do not quit, any tests that are changed will automatically re-run.
- For a general overview of Vitest, please view the Vitest guide.
If you get an unauthorizedAccess error when running tests, run this in the terminal and try again:
`Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process`