Giter VIP home page Giter VIP logo

Comments (4)

lukasgeiter avatar lukasgeiter commented on June 6, 2024 2

Of course I don't know any details about your setup, but it might also have some advantages to do it this way. If you generate the other site components as part of the MkDocs build you can ensure that both navigations will always be in sync.

If you want you could also abort the build process in your plugin's on_nav method (e.g. by raising SystemExit). Then you would have access to the navigation without the overhead of generating the actual documentation.

from mkdocs-awesome-pages-plugin.

lukasgeiter avatar lukasgeiter commented on June 6, 2024

I'd suggest you create your own plugin that implements the on_nav event hook. As first argument, the method will receive a Navigation object. You'll mostly be using the items property which gives you a nested list of all sections, pages and links.

Make sure to register your plugin after awesome-pages in mkdocs.yml. That way your plugin is called after awesome-pages has made its changes to the navigation.

from mkdocs-awesome-pages-plugin.

ms-lolo avatar ms-lolo commented on June 6, 2024

that's only less ideal because it would require me to run the full mkdocs build before being able to generate the other site components but I get how this is probably the most reliable way for me to get the exact navigation generated without poking into this plugin's internal classes. looking at the mkdocs plugin docs, this doesn't seem too daunting so I'll give that a shot. thanks for the help!

from mkdocs-awesome-pages-plugin.

ms-lolo avatar ms-lolo commented on June 6, 2024

forgot to come back and mention that creating a little plugin worked just fine! it looked a little like this:

class MkdocsPlugin(BasePlugin):  # type: ignore
    def on_nav(self, nav: Navigation, config: Config, files: Files) -> Navigation:  # type: ignore
        result = []
        # The mkdocs.yml file in the project .tmp directory
        config_path = Path(config["config_file_path"])
        # The directory containing the mkdocs.yml file
        config_dir_path = (config_path / "..").resolve()
        # We will be creating a top-nav.yml file for us here to use in sphinx builds
        output_path = config_dir_path / "top-nav.yml"

        def find_first_path(i: Union[Section, Page]) -> str:  # type: ignore
            if isinstance(i, Page):
                return f"/{i.url}"

            return find_first_path(i.children[0])

        for item in nav.items:
            result.append({
                "name": item.title,
                "path": find_first_path(item),
            })

        output_path.write_text(yaml.dump(result, indent=2))

        return nav

We're mostly writing out the top navigation items so I can generate the same thing in the various sphinx docs steps.

Thanks again for the suggestion :)

from mkdocs-awesome-pages-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.