mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Compare commits
1 commit
main
...
plugin-loa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d11fd2cbaa |
5 changed files with 20 additions and 8 deletions
|
|
@ -265,8 +265,8 @@ def package(
|
||||||
@click.option(
|
@click.option(
|
||||||
"-m",
|
"-m",
|
||||||
"--metadata",
|
"--metadata",
|
||||||
type=click.File(mode="r"),
|
type=str,
|
||||||
help="Path to JSON file containing license/source metadata",
|
help="Path to JSON file containing license/source metadata, or input to a metadata plugin",
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--template-dir",
|
"--template-dir",
|
||||||
|
|
@ -329,16 +329,12 @@ def serve(
|
||||||
|
|
||||||
reloader = hupper.start_reloader("datasette.cli.serve")
|
reloader = hupper.start_reloader("datasette.cli.serve")
|
||||||
reloader.watch_files(files)
|
reloader.watch_files(files)
|
||||||
if metadata:
|
|
||||||
reloader.watch_files([metadata.name])
|
|
||||||
|
|
||||||
inspect_data = None
|
inspect_data = None
|
||||||
if inspect_file:
|
if inspect_file:
|
||||||
inspect_data = json.load(open(inspect_file))
|
inspect_data = json.load(open(inspect_file))
|
||||||
|
|
||||||
metadata_data = None
|
metadata_data = pm.hook.load_metadata(metadata_value=metadata)
|
||||||
if metadata:
|
|
||||||
metadata_data = json.loads(metadata.read())
|
|
||||||
|
|
||||||
click.echo(
|
click.echo(
|
||||||
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
"Serve! files={} (immutables={}) on port {}".format(files, immutable, port)
|
||||||
|
|
|
||||||
|
|
@ -58,3 +58,8 @@ def register_output_renderer(datasette):
|
||||||
@hookspec
|
@hookspec
|
||||||
def register_facet_classes():
|
def register_facet_classes():
|
||||||
"Register Facet subclasses"
|
"Register Facet subclasses"
|
||||||
|
|
||||||
|
|
||||||
|
@hookspec(firstresult=True)
|
||||||
|
def load_metadata(metadata_value): # , datasette):
|
||||||
|
"Return metadata dictionary loaded from metadata_value"
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ DEFAULT_PLUGINS = (
|
||||||
"datasette.publish.now",
|
"datasette.publish.now",
|
||||||
"datasette.publish.cloudrun",
|
"datasette.publish.cloudrun",
|
||||||
"datasette.facets",
|
"datasette.facets",
|
||||||
|
"datasette.default_metadata",
|
||||||
)
|
)
|
||||||
|
|
||||||
pm = pluggy.PluginManager("datasette")
|
pm = pluggy.PluginManager("datasette")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ Options:
|
||||||
--cors Enable CORS by serving Access-Control-Allow-Origin: *
|
--cors Enable CORS by serving Access-Control-Allow-Origin: *
|
||||||
--load-extension PATH Path to a SQLite extension to load
|
--load-extension PATH Path to a SQLite extension to load
|
||||||
--inspect-file TEXT Path to JSON file created using "datasette inspect"
|
--inspect-file TEXT Path to JSON file created using "datasette inspect"
|
||||||
-m, --metadata FILENAME Path to JSON file containing license/source metadata
|
-m, --metadata TEXT Path to JSON file containing license/source metadata, or
|
||||||
|
input to a metadata plugin
|
||||||
--template-dir DIRECTORY Path to directory containing custom templates
|
--template-dir DIRECTORY Path to directory containing custom templates
|
||||||
--plugins-dir DIRECTORY Path to directory containing custom plugins
|
--plugins-dir DIRECTORY Path to directory containing custom plugins
|
||||||
--static MOUNT:DIRECTORY Serve static files from this directory at /MOUNT/...
|
--static MOUNT:DIRECTORY Serve static files from this directory at /MOUNT/...
|
||||||
|
|
|
||||||
|
|
@ -813,3 +813,12 @@ This example plugin adds a ``x-databases`` HTTP header listing the currently att
|
||||||
await app(scope, recieve, wrapped_send)
|
await app(scope, recieve, wrapped_send)
|
||||||
return add_x_databases_header
|
return add_x_databases_header
|
||||||
return wrap_with_databases_header
|
return wrap_with_databases_header
|
||||||
|
|
||||||
|
.. _plugin_load_metadata:
|
||||||
|
|
||||||
|
load_metadata(metadata_value)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Return a Python dictionary of metadata configuration values. The ``metadata_value`` argument will be the value passed to the ``-m`` or ``--metadata`` argument to ``datasette serve``.
|
||||||
|
|
||||||
|
Only one plugin can implement this at a time. The first registered plugin will get to provide the metadata dictionary, while all other plugins will be ignored.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue