Skip to content

Make meta available on demand at global level (nav) #1476

Closed

Description

@memeplex

I've been trying to build an index file that sorts my pages by a date specified as metadata, just to find out that meta is always empty for a nav item. I understand this may be so because of performance reasons, but what about providing a way of getting it on demand for some specific templates that request so?

I'm currently resorting to this ugly hack:

{{ nav_item.read_source(config) or nav_item.meta }}

But if only read_source returned self this would look less hackish.

Activity

  1. memeplex commented on Apr 30, 2018

    @memeplex
    ContributorAuthor

    Alternatively, meta could also be a property. One concern with this solution is that it could trigger meta loading everywhere, since the ubiquitous title property depends on meta. So maybe it's better to keep meta loading more explicit (nav_item.read_source(config).meta) so as to prevent surprises.

    Is there another solution now that a plugin api is offered?

  2. memeplex commented on Apr 30, 2018

    @memeplex
    ContributorAuthor

    Also, see the reference above for a suggestion about loading source, quickly extracting meta and top header, then discarding source, so that a page is consistent across different contexts (except for its source being loaded and rendered or not).

  3. waylan commented on Apr 30, 2018

    @waylan
    Contributor

    I suspect the Pages Refactor will address any concerns you have here. All pages will have their Markdown "rendered" before any page is passed to a template.

  4. waylan commented on Apr 30, 2018

    @waylan
    Contributor

    It occurs to me that there is no single place with a complete summary of how things will work with the pages refactor So here you go:

    1. MkDocs will walk the docs_dir and create a list of all files in a files object. All documentation pages (Markdown documents) will also be added to a list of pages. Each file object will contain five attributes: four paths (relative and absolute source and destination paths) and a url relative to the site root. Additionally, a file.url_relative_to() method will be available to return a url relative to any other file for that specific file.
    2. MkDocs will iterate over all pages, reading the contents of the source file and building up each page instance with meta, markdown, html (rendered Markdown), title, toc, etc. Nothing will be passed to any templates at this point (which addresses the issues raised in this issue).
    3. MkDocs will build the nav with proper nesting. If a nav is defined in the config, it is iterated over and each item is associated with the correct page instance. If no matching page exists, then the nav item is assumed to be an external link. page instances are required to have a matching nav item. If no nav is defined in the config, then one is auto-generated from pages.
    4. Finally, all files will be iterated over again with any non-page files being copied to the site_dir and each page being passed to the template before being written to the site_dir.

    So we have three collections: (1) files which contains every file (including images, JS, CSS, etc) from the docs_dir, (2) pages which is a subset of files (all markdown files only) and (3) nav which is subset of pages (only those that should appear in site navigation). I expect both pages and nav will be passed to the template (paged being a flat list and nav being a nested structure), but not files. The actual names of objects mentioned above are subject to change as things develop. although there will be an attempt to maintain the currently documented template variables where possible.

    As a reminder, the current (pre-1.0) behavior is as follows:

    1. The (nested) nav is generated either from the config or from the site_dir.
    2. The docs_dir is walked and all non-page files are copied to the site_dir.
    3. nav is iterated over and each page is read, rendered, passed to the template and written to the site_dir in a single step. In other words, the final rendering of the first page is written to disc before we even read the contents of the second page.

    The current behavior includes only a single collection called pages which is actually navigation in practice.

  5. memeplex commented on Apr 30, 2018

    @memeplex
    ContributorAuthor

    Thanks for such a detailed explanation! Just one question: aren't you concerned about having the entire set of rendered pages in memory anymore? What about extracting everything but the content itself and let the rendering happen only on demand, one page at a time as needed? Or maybe I'm not quite following you in this regard.

  6. memeplex commented on Apr 30, 2018

    @memeplex
    ContributorAuthor

    Ah, and related to the above (or perhaps to my misunderstanding of the above), why keep using the metadata parser instead of just the meta extension given that you will be rendering the pages anyway?

  7. waylan commented on Apr 30, 2018

    @waylan
    Contributor

    aren't you concerned about having the entire set of rendered pages in memory anymore?

    That's a good question. In practice, it seems that most competing projects seems to not have a problem with this. The actual approach used is subject to testing.

    why keep using the metadata parser instead of just the meta extension given that you will be rendering the pages anyway?

    Three reasons:

    1. The current Plugin API requires it. One of the events allows for the raw Markdown of a page to be altered by a plugin. However, it is clearly documented that the meta-data has already been removed at that point. We can't do that is we use the Markdown extension.
    2. I think its a better approach (I may or may not drop the Markdown extension in a future release of Python-Markdown)
    3. We may switch to using YAML rather than MultiMarkdown meta-data, in which case the markdown extension would not work anyway.
  8. added this to the 1.0.0 milestone on Jun 20, 2018
  9. waylan commented on Jun 28, 2018

    @waylan
    Contributor

    Fixed in #1504

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions