diff --git a/README.md b/README.md new file mode 100644 index 0000000..f83c2f7 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +Zundler +======= + +Bundle assets of distributed HTML docs into one self-contained HTML file. + +Naively building one HTML file out of a directory of HTML files that total +dozens of megabytes quickly overwhelm modern browsers. Zundler solves this +by taking the following approach: + +* Embed all assets that are referenced in CSS files, such as imports and + fonts +* Endow all HTML files with extra scripts that embed these resources at run time: + * Convert `script` tags with a `src` attribute referencing a JavaScript + file to inline scripts + * Convert `link` tags with an `href` attribute referencing a CSS file to inline styles + * Make all `img` tags with a `src` attribute referencing local images use a data URI + * Monkey patch the JavaScript function `fetch` and the class `URLSearchParams` +* Create a JSON structure (the "global context") out of all files in the directory (the "virtual file tree") and other data +* Gzip this scructure and base64-encode it +* Bundle it all into a scuffolding file with this structure: + ```html + + + + {body} + + + + + ``` + The global context is then unzipped, an `iframe` is created and the + document is bootstrapped from the virtual file tree. + + +Installation +------------ + +Zundler is a Python package and can be installed like any other Python +package. + +The recommended way is to clone this repository and type `pip install .`. +If you prefer an alternative like `pipx`, `poetry` or manually handled +`venv`s, you probably know what to do. + +An entry point called `zundler` will appear in `~/.local/bin`. + + +Bundling Sphinx docs +-------------------- + +Providing a Sphinx extension does not make sense, because it would need to +add a new builder. Similar to the `latexpdf` + +Suggested Makefile addition: + +```make +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b zundler $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo "Bundle asset into one self-contained HTML file..." + $(MAKE) -C $(BUILDDIR)/html + @echo "Zundler finished; the HTML file is in $(BUILDDIR)/zundler." +``` + +Demos +----- + +... + + +Limitations +----------- + +This approach is quite hacky, but it might work well enough for your +purposes. + + +Copyright +--------- + +Adrian Vollmer, 2022. MIT licensed; see `LICENSE` for details. diff --git a/README.rst b/README.rst deleted file mode 100644 index 10cbaa3..0000000 --- a/README.rst +++ /dev/null @@ -1,19 +0,0 @@ -======================================== -sphinxcontrib-sphinx-self-contained-html -======================================== - -.. image:: https://travis-ci.org/AdrianVollmer/sphinxcontrib-sphinx-self-contained-html.svg?branch=master - :target: https://travis-ci.org/AdrianVollmer/sphinxcontrib-sphinx-self-contained-html - -A Sphinx extension that allows generating completely self-contained HTML documents - -Overview --------- - -Add a longer description here. - -Links ------ - -- Source: https://github.com/AdrianVollmer/sphinxcontrib-sphinx-self-contained-html -- Bugs: https://github.com/AdrianVollmer/sphinxcontrib-sphinx-self-contained-html/issues diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1d45dc6..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pbr diff --git a/setup.cfg b/setup.cfg index 90dee15..636b60c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] -name = self-contained-html -summary = Convert distributed HTML docs to completely self-contained HTML docs -description_file = README.rst +name = Zundler +summary = Bundle assets of distributed HTML docs into one self-contained HTML file +description_file = README.md author = Adrian Vollmer author_email = computerfluesterer@protonmail.com home_page = https://github.com/AdrianVollmer/self-contained-html @@ -23,9 +23,18 @@ classifier = Topic :: Documentation :: Sphinx Topic :: Utilities +[options] +zip_safe = False +include_package_data = True +packages = find: +install_requires = + sphinx + bs4 + importlib-metadata; python_version<"3.8" + [options.entry_points] console_scripts = - bundle-html = src.__main__:main + zundler = src.__main__:main [files] packages = src diff --git a/src/__main__.py b/src/__main__.py index 218de6e..0cb0615 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -10,4 +10,4 @@ def main(): if __name__ == "__main__": - pass + main() diff --git a/src/args.py b/src/args.py index 2b61deb..7da2e55 100644 --- a/src/args.py +++ b/src/args.py @@ -10,7 +10,7 @@ except ImportError: try: __version__ = importlib_metadata.version(__package__ or __name__) # __summary__ = importlib_metadata.metadata(__package__ or __name__)['summary'] - __summary__ = "Convert distributed HTML docs to completely self-contained HTML docs" + __summary__ = "Bundle assets of distributed HTML docs into one self-contained HTML file" except importlib_metadata.PackageNotFoundError: __version__ = "??" __summary__ = "??" diff --git a/test-requirements.txt b/test-requirements.txt deleted file mode 100644 index 55ff9de..0000000 --- a/test-requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pytest -sphinx diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index c1009dd..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,9 +0,0 @@ -""" - pytest config for sphinxcontrib/sphinx-self-contained-html/tests - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :copyright: Copyright 2017 by Adrian Vollmer - :license: BSD, see LICENSE for details. -""" - -pytest_plugins = 'sphinx.testing.fixtures' diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 5acb1a6..0000000 --- a/tox.ini +++ /dev/null @@ -1,32 +0,0 @@ -[tox] -minversion = 2.0 -envlist = py{34,35,36,py},style - -[testenv] -deps = -r{toxinidir}/test-requirements.txt -commands= - pytest - -[testenv:mypy] -description = - Run type checks. -deps = - mypy -commands= - mypy sphinxcontrib - -[testenv:style] -description = - Run style checks. -deps = - flake8 - isort - yapf -commands = - isort -rc -c -df sphinxcontrib tests - yapf -rd sphinxcontrib tests - flake8 sphinxcontrib tests setup.py - -[travis] -python = - 3.6: py36, mypy, style