Comments (4)
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.
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.
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.
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)
- [BUG] HOT 1
- Is it possible to hide a single file from nav? HOT 8
- issue with material for mkdocs when using navigation.prune HOT 3
- folder level .pages nav not working when top level .pages nav has sub-sections? HOT 2
- Installation was successful, but MKDOCS server spits out the error "plugin is not installed" HOT 11
- Version 2.9.2 regression in `.pages` handling HOT 3
- support for imported repositories (multirepo plugin) HOT 5
- Can nav be sorted by date? HOT 3
- Ordering breaks when rest pattern is used in mkdocs > nav HOT 7
- conda-forge distribution
- Full custom nav for pages in a directory HOT 1
- Deep `.pages.` files not respected HOT 3
- does not work in combination with monorepo HOT 6
- Possible to build full nav in directory? HOT 4
- An absolute path to '/...' is included in the 'nav' configuration, which presumably points to an external HOT 6
- Hide pages but still show left navigation? HOT 2
- Order does not take effect for subdirectory files HOT 2
- Possible regression in 2.9.2: `hide: true` not working in `.pages` HOT 3
- Custom styling on nav items HOT 2
- [FEATURE] `flat n` - How to include nested folders correctly? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mkdocs-awesome-pages-plugin.