Skip to content

Implement reusable themes with theme_url #179

Closed

Description

@micahhausler

I was thinking about how to reuse a custom MkDocs theme on multiple projects without copying files or using a git submodule, and it occurred to me that the jinja2.PackageLoader() could be used instead of the filesystem loader in build.py

This could be as simple as:

https://pypi.python.org/pypi/my-mkdocs-theme

setup.py
my_mkdocs_theme/
    __init__.py
    version.py
    templates/
        css/
        fonts/
        img/
        js/
        base.html
        content.html
        nav.html
        search.html
        toc.html

And in each of my projects that use my-mkdocs-theme,
mkdocs.yml

template_pkg: my_mkdocs_theme

requirements.txt

my-mkdocs-theme==0.0.1

Thoughts?

Activity

  1. d0ugal commented on Oct 28, 2014

    @d0ugal
    Contributor

    This sounds great. It is on my mental list of things to do. I think at some point we want to move the current themes out into their own package (exceot maybe one or two builtin themes).

    It would be great if packages could provide multiple themes. So, for example, you might have a light and dark version included in your my_mkdocs_theme package. then the bootswatch themes included in MkDocs could all come under one package. We could use some sort of path akin to Python like . - so then in the config you would have something like theme = my_mkdocs_theme.light but i'm not sure I like that.

    We probably need to also attach the version of MkDocs they work with. This is a bit of a complicated issue to figure out too.

    I think this is a great direction to take the idea - maybe we should start with the simplest way (as you describe) and build on it from there.

    Finally, I'm not sure I like the idea of adding another config option. Maybe there is a way we avoid that as we already have theme and custom_theme.

    It is probably also work getting @tomchristie's input on this, as I suspect he will have some thoughts on it.

  2. micahhausler commented on Oct 28, 2014

    @micahhausler
    Author

    One possible way could be to specify in the theme the mkdocs versions, something like how setuptools does it:

    my_mkdocs_theme/__init__.py

    mkdocs_allowed = 'mkdocs>=0.8'

    or a more picky case:

    my_mkdocs_theme/__init__.py

    mkdocs_allowed = 'mkdocs<1.6,>1.9,!=1.9.6,<2.0a0,==2.4c1'

    MkDocs itself could assess if it's own mkdocs.__version__ matches the mkdocs_allowed

    from pkg_resources import parse_requirements
    from my_mkdocs_theme import mkdocs_allowed
    
    req  = list(parse_requirements([mkdocs_allowed]))[0]
    is_theme_compatable = mkdocs.__version__ in req

    Just an idea that could probably use some refinement.

    As far as a config option, I only see the theme and theme_dir option. Perhaps depreciate theme_dir (still usable for a few versions) in favor of a custom_theme that is a path or package-dotted-path?

  3. d0ugal commented on Oct 28, 2014

    @d0ugal
    Contributor

    ah, I meant to write theme and theme_dir - the second is for custom themes typically under the same path as the mkdocs.yml.

  4. lovelydinosaur commented on Oct 28, 2014

    @lovelydinosaur
    Collaborator

    I'd generally prefer us to keep 'python'ness out of MkDocs where possible.
    Yes, it's written in python, but long-term it's unnecessarily limiting if we tie in the ecosystem to that.
    theme_dir may be simple, but that's also it's advantage - you don't need to understand a programming language's particular package repo, instead you just put your custom theme on the web somewhere and say 'hey folks, download this'.
    Anyways, don't take anything I say as gospel, I might not have thought any of this through properly, but it does seem to me that introducing PyPI into the equation makes things more complicated, not less.

  5. micahhausler commented on Oct 28, 2014

    @micahhausler
    Author

    @tomchristie After reading over the wiki, do you think re-usable, versioned templates are out of scope?

    Is git submodules a better approach? I was really hoping to avoid the gnarliness of submodules.

  6. d0ugal commented on Oct 28, 2014

    @d0ugal
    Contributor

    I'm conflicted, as I understand the motivation around avoiding python tooling but I don't want to invent our own packaging system. Ultimetly we would then need to teach a potential user this.

    Is there a way we can make PyPI easier for our specific use case? A mkdocs subcommand that turns a directory of files into a package? Just thinking out loud here.

    I'd suggest that custom, reusable themes will only be made by a smaller set of users that are perhaps more advanced but that might be naive.

  7. micahhausler commented on Oct 28, 2014

    @micahhausler
    Author

    Personally, I think adding a python package and still supporting the template_dir config option gets the best of both worlds: People can still simply copy a template directory, but advanced users can use a python package if they so choose.

  8. added this to the 0.11.0 milestone on Oct 29, 2014
  9. lovelydinosaur commented on Oct 29, 2014

    @lovelydinosaur
    Collaborator

    Maybe I'm misunderstanding something - talk me through what the intention is here.
    What problem does 'packaged' themes solve that downloadable themes don't?
    If it's about wanting to point to an external entity rather than keeping it local then shouldn't we instead thing about a theme_url that can point at a zip file or similar. That'd allow us to point at git repos and/or versioned URLs if needed.

  10. micahhausler commented on Oct 29, 2014

    @micahhausler
    Author

    @tomchristie A theme_url is a great solution to what I'm thinking of.

    The specific case I'm looking at is that I just wrote the documentation for docker-py, the Docker python client. docker/docker-py#375. Docker already has a custom mkdocs theme for their org, in the main Docker repo. I really just wanted to re-use that theme without having to copy the files.

    I really like the idea of a theme_url. It avoids having to use python-specific tooling, and allows re-usable themes.

  11. d0ugal commented on Oct 29, 2014

    @d0ugal
    Contributor

    Ideally we need a theme version and the version of MkDocs it corresponds with. Storing this information only in the URL feels wrong.

    I'm also not keen on themes being spread over a random asortment of hosts. I trust PyPI to be available and responsible.

    However, it certainly is simpler.

  12. lovelydinosaur commented on Oct 29, 2014

    @lovelydinosaur
    Collaborator

    and the version of MkDocs it corresponds with.

    Do we really need that ^?

    I'm also not keen on themes being spread over a random asortment of hosts.

    I've got no issue with us having URLs like https://github.com/tomchristie/mytheme/archive/master.zip plus S3, bitbucket, or whatever else folks want to use. I'd be a million times happier with that then with repurposing the esoteric, obscure stack that is PyPI.

    PyPI setup is a major pain in the ass usability wise. There's zero chance that I want our theme packaging go down that road. 😄

  13. d0ugal commented on Oct 29, 2014

    @d0ugal
    Contributor

    We would want a MkDocs version unless the available context in templates is never going to change.

  14. lovelydinosaur commented on Oct 29, 2014

    @lovelydinosaur
    Collaborator

    @d0ugal Either ways around we should try our utmost to ensure that we ain't gonna be making backwards incompatible changes to the context. Keep it simple and that should be something that we can make as a reasonable claim for the forseeable future.

    "Versioning an interface is just a polite way to kill deployed applications" - Roy Fielding

  15. 12 remaining items

  16. modified the milestones: 0.12.0, 0.11.0 on Nov 14, 2014
  17. modified the milestones: 1.0.0, 0.12.0 on Mar 30, 2015
  18. modified the milestones: 0.13.0, 1.0.0 on Apr 8, 2015
  19. modified the milestones: 0.12.0, 0.13.0, 1.0.0 on Apr 22, 2015
  20. d0ugal commented on Apr 24, 2015

    @d0ugal
    Contributor

    Closing in favor of #476

  21. removed this from the 1.0.0 milestone on Apr 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions