Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to theme Datasette with CSS #1149

Open
simonw opened this issue Dec 17, 2020 · 3 comments
Open

Make it easier to theme Datasette with CSS #1149

simonw opened this issue Dec 17, 2020 · 3 comments
Labels
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Dec 17, 2020

I want to theme https://datasette.io/ so that when you visit https://datasette.io/content (the Datasette UI part of it) the navigation from the parent site is used.

I tried dropping in a base.html template like this:

{% extends "page_base.html" %}

{% block base_extra_head %}

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
{% for url in extra_css_urls %}
    <link rel="stylesheet" href="{{ url.url }}"{% if url.sri %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}>
{% endfor %}
{% for url in extra_js_urls %}
    <script src="{{ url.url }}"{% if url.sri %} integrity="{{ url.sri }}" crossorigin="anonymous"{% endif %}></script>
{% endfor %}
{% block extra_head %}{% endblock %}
{% endblock %}

{% block extra_body_end %}
{% include "_close_open_menus.html" %}

{% for body_script in body_scripts %}
    <script>{{ body_script }}</script>
{% endfor %}
{% endblock %}

But this resulted in pages looking like this:

content__categories__3_rows

Note that the cog menu is broken and the filter UI is unstyled. To get these working correctly I would need to copy over a whole lot of Datasette's default CSS - and that means that when Datasette changes in the future those pages could break in subtle ways.

@simonw simonw added the css label Dec 17, 2020
@simonw
Copy link
Owner Author

simonw commented Dec 17, 2020

I think what I want is for it to be easy to reuse portions of Datasette's CSS - the bit that styles the cog menu for example - without pulling in the whole thing.

I tried linking in the <link rel="stylesheet" href="/-/static/app.css"> stylesheet and the page broke, wildly:

content__categories__3_rows_and_Datasette_search__pytest

That's because Datasette's built-in CSS applies styles directly to a whole bunch of different tags - body, header, footer etc - which means that if you import that stylesheet it can play havoc with the site you have already built.

@simonw
Copy link
Owner Author

simonw commented Dec 17, 2020

So, an idea: what if Datasette's default CSS applied only to elements with classes - or maybe to childen of a body class="datasette" element? In such a way that you could write your own custom HTML that reused elements of Datasette's CSS - the cog menu styling for example - but only on an opt-in basis?

@simonw simonw added this to the Datasette 1.0 milestone Dec 17, 2020
@mroswell
Copy link
Sponsor Contributor

Sounds like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants