serve and publish commands now take a --metadata option

If provided, the --metadata option is the path to a JSON file containing
metadata that should be displayed alongside the dataset.

    datasette /tmp/fivethirtyeight.db --metadata /tmp/metadata.json

Currently that metadata format looks like this:

    {
        "title": "Five Thirty Eight",
        "license": "CC Attribution 4.0 License",
        "license_url": "http://creativecommons.org/licenses/by/4.0/",
        "source": "fivethirtyeight/data on GitHub",
        "source_url": "https://github.com/fivethirtyeight/data"
    }

If provided, this will be used by the index template and to populate the
common footer.

The publish command also accepts this argument, and will package any provided
metadata up and include it with the resulting Docker container.

    datasette publish --metadata /tmp/metadata.json /tmp/fivethirtyeight.db

Closes #68
This commit is contained in:
Simon Willison 2017-11-13 07:20:02 -08:00
commit 3ef35ca8b4
6 changed files with 113 additions and 62 deletions

View file

@ -133,15 +133,16 @@ def escape_sqlite_table_name(s):
return '[{}]'.format(s)
def make_dockerfile(files):
def make_dockerfile(files, metadata_file):
return '''
FROM python:3
COPY . /app
WORKDIR /app
RUN pip install https://static.simonwillison.net/static/2017/datasette-0.5-py3-none-any.whl
RUN datasette build_metadata {} --metadata metadata.json
RUN pip install https://static.simonwillison.net/static/2017/datasette-0.6-py3-none-any.whl
RUN datasette build {} --inspect-file inspect-data.json
EXPOSE 8006
CMD ["datasette", "serve", {}, "--port", "8006", "--metadata", "metadata.json"]'''.format(
CMD ["datasette", "serve", {}, "--port", "8006", "--inspect-file", "inspect-data.json"{}]'''.format(
' '.join(files),
'"' + '", "'.join(files) + '"',
metadata_file and ', "--metadata", "{}"'.format(metadata_file) or '',
).strip()