Skip to content

Page title: filename vs top header #1008

Closed

Description

@memeplex

Yesterday we have been evaluating different themes to use for our documentation at work and we found some issues a bit confusing:

  1. mkdocs, bootswatch and material themes seem to assume that the top header is the page title. I say this because the mkdocs docs are structured this way and because the toc is unindented (no nested lists, although there is some highlighting of the top level).
  2. The cinder theme shows many levels of headers in its toc and seems to cope well with pages for which the top header is the title and also for pages which uses the level one headers as section titles. The example site for cinder is using h1 instead of # for the first header, I guess in order to exclude it from the toc.
  3. The readthedocs theme is problematic with both kind of pages:
    • If level one headers are section titles, then the structure is lost in the toc outline, since there is no differentitation between the two shown levels (not even highlighting).
    • If the top header is the title, the toc will repeat this name: first as part of the "filesystem hierarchy", then as part of the "header hierarchy". Say you have a P page with headers #P, ##Q, ##R, the toc will look like
P
  P
  Q
  R

Problems I see here:

  1. Violation of DRY principle: one has to ensure consistency between the filename and the top header.
  2. Changing the theme may imply changing the logical structure of the document.
  3. The readthedocs theme seems to make assumptions that are incompatible with any kind of realistic document.

Activity

  1. memeplex commented on Aug 3, 2016

    @memeplex
    ContributorAuthor

    I have been reading #316, #318, #308 and #770. I see the possible inconsistency regarding the "real title" was somehow resolved. Still, that themes are structure dependent disturbes me. Wouldn't it be better if mkdocs established some convention that themes would follow (say, # is the page title)? (the user will still be free to hack the theme to fit contents with other structure). And the rtd point above: why is the second toc level not differentiated from the first (I mean, the css class is different, but they're not nested lists and there is no css style set at the theme level); it's like it's assuming the user will set the style or will restrict himself to use just one level of headers.

  2. waylan commented on Aug 3, 2016

    @waylan
    Contributor

    The problem is that different users have different needs and expectations. Some want the title taken from the first heading on the page (h1), and some want the title taken from elsewhere (config, front matter, filename, etc.). The former do not want or need the title to also be displayed by the template (as it would display twice), while others absolutely need the title to be displayed by the template. So how do we cleanly alter the template behavior only for files in which the title did not come from the first heading in the document? Remember, a single project could have different files which have the title defined in different ways, so a global setting won't be sufficient.

    Of course, the Page refactor of the nav (discussed in #316) has happened (partially, anyway), so we could store an attribute on each Page object and in the template wrap the display of the title in an if statement. Personally, I'm not crazy about that fix, but its the best solution I can think of.

  3. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    I understand different users have different expectations, but doesn't it make things worse that different themes have different expectations? If there was some convention then at least people wanting to obey it will have the chance of switching themes without touching contents. Another possibility is to develop some conventional setting to put under extras, so that themes were able to provide a couple of common options: h1 is the page title, h1 is the first level section, etc. This is global but it's still good for people wanting to rip the benefits of obedience. For users with less conventional requirements there is always the possibility of modifying parts of the theme, at the file or at the block level.

    Then regarding rtd, is it a flaw of the theme that there is no sort of nesting or visual clue whatsoever to differentiate the first and second level in the page outline? I can't see what is the theme expectation: h1 is the title implies h1 is shown twice, h1 is a section implies h1 and h2 are shown the same.

  4. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    Just thinking: what about an extension point at the template level where the user may attempt some jinja assignment before the template gets rendered. This will even work at the page level since the user may decide what kind of tweak to apply to the model depending on the current page title or whatever info exposed by model he considers relevant. It's an easy change to provide such kind of hook. Maybe to add a (by default empty) __init__.html template that is called only for its side-effects. This will offer a restricted environment to manipulate the model. This may be a plain python module also, but I don't want to get wild in other people's home :)

  5. waylan commented on Aug 4, 2016

    @waylan
    Contributor

    I understand your frustration that the RTD theme does not align with the other themes. However, as I understand it (it happened before my time), that theme was create and provided by RTD when they added support for MkDocs to their service. Actually, if you host your MkDocs project on RTD service, they override your config and force their theme, and by their theme, I mean they use their own code/templates, not the RTD theme packaged with MkDocs. We simply provide our own copy of that same theme so users have a copy of the theme for local testing purposes prior to deploying to the RTD service.

    I would like to see some significant improvements to the RTD theme myself, but unless those improvements get pushed upstream to RTD, most users of that theme will not be able to benefit from them. That being the case, we have two options:

    1. Ignore RTD and move forward with MkDocs leaving that behind
    2. Limit all forward movement to fit within the constraints imposed by RTD

    Truth be told, we have already made some significant movement toward option 1 in version 0.16 (the upcoming release). I expect that the RTD service will not be able to adopt 0.16 without making some changes to their templates. So, if we are going to make any such changes, now is the time to do it.

  6. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    Thanks for the explanation, @waylan. Regarding my suggestion of fine tuning the title and toc stuff manipulating the model inside the template, I think that could be achieved using the machinery introduced by #947, by just assigning before extending (I have not tested it, though). Supposing that works, there is still the problem of legacy themes but, hey, they should be updated.

  7. waylan commented on Aug 4, 2016

    @waylan
    Contributor

    Yes, the machinery introduced by #947 is exactly how end users should be altering the default behavior in themes. Not sure how that assists us in offering a built-in solution though.

  8. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    What I'm proposing is not to offer a built-in solution but to use the template mechanism to customize the theme not only at the markup level but also at the model level. For this blocks are useless, what is needed is a way to do some jinja assignments to the model (override the page title, restructure the page toc, etc) before rendering happens. I think this could be done before calling the extends directive. In a sense this would be complementary to js dom customization, but working on the application (pre-rendering) model, not the document model. Of course the same could be achieved rewriting blocks, but that would be a lot of copy paste for things like removing h1 from the toc.

  9. waylan commented on Aug 4, 2016

    @waylan
    Contributor

    I'm not sure I follow, but that seems unnecessarily complicated. Why not just assign a boolean attribute to the Page instance (perhaps, Page.show_title). Depending on how the title is obtained, set it to true or false. Then in the template do (simplified for demonstration purposes):

    {% if page.show_title%}
      <h1>{{ page.title }}</h1>
    {% endif %}

    Actually, when the Plugin API (#206) lands, that could be extremely powerful for plugins as well.

  10. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    Maybe it's me that is not following you. Let me explain my point: there are a number of open or half-closed issues regarding using the top level header for the title or not, including the top level header in the toc or not, etc. Since different users have different expectations, it's not possible to automatically adapt themes to the different use cases => some configuration option or extension point is needed. Given I sense some resistance to add new configuration options, I'm going the extension point / hook way. This may well be the plugin api, but since it's not available for the time being I suggested to make it easy for the user not just to override templates but to modify the model a bit. Then I realised this is already possible since #947: override main.html, tweak the model a bit, then extend base.html, then tweak blocks as usual if necessary (all this inside main.html using jinja). Obviously, you can't put a title on the template by just changing the model, but you can remove the title from the toc or override the title using a meta attribute or the top level header.

  11. waylan commented on Aug 4, 2016

    @waylan
    Contributor

    Perhaps my suggestion would make more sense in the context of the changes made in f8a0ac6. Note that each "page" is contained in a page object which holds all the info about that page as attributes on the page object. Any page-specific-behavior would appropriately be stored in an attribute on that page. No need for global (per project) behavior. You are proposing a solution which would require all pages in a project to follow the same pattern. My solution allows different pages in the same project to obtain their title in a different manner. Then, in the template, using an if statement, have the template behave differently based on that attribute (include or don't include an element as appropriate). No need for users to customize the template (that parts already built in). And Plugins (once #206 is finished) can alter the title or any other attributes of the page object to control how things get displayed by the template.

  12. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    You are proposing a solution which would require all pages in a project to follow the same pattern.

    No, because you may test the page name using a jinja conditional.

    No need for users to customize the template

    I agree writing a plugin is the best solution. I was just suggesting a trick to workaround some of the issues discussed in #316, #318, #308 and #770 without having to introduce html in the md (<h1></h1>) or hiding toc levels using css or js (with the consequence of losing one level).

  13. waylan commented on Aug 4, 2016

    @waylan
    Contributor

    you may test the page name using a jinja conditional.

    Hard coding page titles into your templates seem like a really bad idea to me. Every time a page title is changed (or a new page it added), then the template needs to be edited as well. I suppose a list of page titles in extra would work, but that is a temporary hack until a real solution is available. I'm not interested in the temporary hacks and don't want to waste my time on them. I'd rather work on the real solution, which involves the plugin API and any potential template updates to support those plugins.

  14. memeplex commented on Aug 4, 2016

    @memeplex
    ContributorAuthor

    You don't need to hardcode pages names, just check for some path pattern, some page meta attribute or whatever you see fit. I mean, it's just python in disguise and a data structure. Anyway, I'm not requesting to introduce a temporary hack into mkdocs at all, just sharing a way to workaround issues that I find a bit cleaner than the alternatives discussed in the aforementioned issues. Thank you for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions