mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
/-/static-plugins/PLUGIN_NAME/ now serves static/ from plugins
Refs #214
This commit is contained in:
parent
a5792a8c61
commit
0bb483ca5b
2 changed files with 18 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ import json
|
||||||
import jinja2
|
import jinja2
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
|
import pkg_resources
|
||||||
import pint
|
import pint
|
||||||
import pluggy
|
import pluggy
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -1294,6 +1295,12 @@ class Datasette:
|
||||||
app.static('/-/static/', str(app_root / 'datasette' / 'static'))
|
app.static('/-/static/', str(app_root / 'datasette' / 'static'))
|
||||||
for path, dirname in self.static_mounts:
|
for path, dirname in self.static_mounts:
|
||||||
app.static(path, dirname)
|
app.static(path, dirname)
|
||||||
|
# Mount any plugin static/ directories
|
||||||
|
for plugin_module in pm.get_plugins():
|
||||||
|
if pkg_resources.resource_isdir(plugin_module.__name__, 'static'):
|
||||||
|
modpath = '/-/static-plugins/{}/'.format(plugin_module.__name__)
|
||||||
|
dirpath = pkg_resources.resource_filename(plugin_module.__name__, 'static')
|
||||||
|
app.static(modpath, dirpath)
|
||||||
app.add_route(
|
app.add_route(
|
||||||
DatabaseView.as_view(self),
|
DatabaseView.as_view(self),
|
||||||
'/<db_name:[^/\.]+?><as_json:(\.jsono?)?$>'
|
'/<db_name:[^/\.]+?><as_json:(\.jsono?)?$>'
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,17 @@ To learn how to upload your plugin to `PyPI <https://pypi.org/>`_ for use by
|
||||||
other people, read the PyPA guide to `Packaging and distributing projects
|
other people, read the PyPA guide to `Packaging and distributing projects
|
||||||
<https://packaging.python.org/tutorials/distributing-packages/>`_.
|
<https://packaging.python.org/tutorials/distributing-packages/>`_.
|
||||||
|
|
||||||
|
Static assets
|
||||||
|
-------------
|
||||||
|
|
||||||
|
If your plugin has a `static/` directory, Datasette will automatically configure
|
||||||
|
itself to serve those static assets from the following path::
|
||||||
|
|
||||||
|
/-/static-plugins/NAME_OF_PLUGIN_PACKAGE/yourfile.js
|
||||||
|
|
||||||
|
See `the datasette-plugin-demos repository <https://github.com/simonw/datasette-plugin-demos/tree/0ccf9e6189e923046047acd7878d1d19a2cccbb1>`_
|
||||||
|
for an example of how to create a package that includes a static folder.
|
||||||
|
|
||||||
Plugin hooks
|
Plugin hooks
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue