Skip to content

Add support or user error when using with mkdocs-material's instant loading #2

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

Closed
timvink opened this issue Sep 3, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@timvink
Copy link
Owner

timvink commented Sep 3, 2020

mkdocs-material theme offers an experimental feature called instant loading.

When enabled, navigating to the print site page does not work properly.

Todo, investigate and either:

  • raise a user error to explain the incompability (and suggest to either disable this plugin, or turn off instant loading)
  • Somehow fix the issue :)
@timvink timvink added the enhancement New feature or request label Sep 3, 2020
@timvink
Copy link
Owner Author

timvink commented Sep 13, 2020

From squidfunk/mkdocs-material#1918 I learned you can to support instant loading by subscribing to the app:

if (
  typeof app !== "undefined" && 
  typeof app.document$ !== "undefined"
) {
  app.document$.subscribe(function() {
    // custom logic
  })
}

In this plugin however, I only inject javascript into one specific page, the print site page. It should not run anywhere else.

What I could do, is detect the page and only execute the JS there.

window.location.pathname Returns:

  • "/print_page.html" (without directory urls, mkdocs serve)
  • "/print_page" (with directory urls, mkdocs serve)
  • (mkdocs build)

That won't work. Instead, I could add a classname to the print site page, and only execute the JS if it's in the body, as suggested here: https://stackoverflow.com/a/9578898/5525118.

I would then need to add the javascript files (with the functions only) to all mkdocs pages, and add to all pages a bit of js that only on the print page calls the appropriate functions (depending on plugin config settings).

Because I'll be calling js functions now, I should simplify and just make a single print-site.js file with all functions.

@timvink timvink reopened this Sep 13, 2020
@timvink
Copy link
Owner Author

timvink commented Sep 14, 2020

Fixed in 2260505

@timvink timvink closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant