lukasgeiter / mkdocs-awesome-pages-plugin

An MkDocs plugin that simplifies configuring page titles and their order
MIT License
452 stars 35 forks source link

Regex for excluding files #63

Closed lin-ycv closed 2 years ago

lin-ycv commented 2 years ago

I'm trying to exclude all pages that starts with 'h' from showing in the nav, but i'm not successful in my attempts

my docs dir structure looks like this

docs/
├─.pages
├─index.md
├─Folder1/
| └─(bunch of image files)
└─Folder2/
  ├─File1.md
  └─Folder2.1/
    ├─File1.md
    ├─File2.md
    └─h_File3.md

in .pages i configured it according to https://github.com/lukasgeiter/mkdocs-awesome-pages-plugin/issues/34#issuecomment-788704657

nav:
    - ... | regex=^(?!h).*$

which didn't work.

I tried to change it so that only files starting with lowercase alphabets will show (just for testing)

nav:
    - ... | regex=[a-z]+.md

but this gave me none for the nav bar instead
All my file and folder names start with capitals, expect index and the file I want to exclude

I also tried to use the code in the comment as is

nav:
    - ... | regex=[^(?!template)].*$

and renamed h_File3.md to template.md, but the file still shows up on the nav


I'm using Material for MkDocs on GH pages, here's my settings:

mkdocs.yml ``` theme: name: material custom_dir: overrides # 404 page static_templates: - 404.html # Necessary for search to work properly include_search_page: false search_index_only: true # Default values, taken from mkdocs_theme.yml language: en font: text: Noto Sans code: Source Code Pro favicon: assets/images/favicon.png icon: logo: icon/signature palette: # Light mode - media: "(prefers-color-scheme: light)" scheme: default primary: white accent: pink toggle: icon: material/weather-sunny name: Switch to dark mode # Dark mode - media: "(prefers-color-scheme: dark)" scheme: slate primary: black accent: light green toggle: icon: material/weather-night name: Switch to light mode features: - navigation.indexes - navigation.tabs - navigation.tracking - content.code.annotate - navigation.top - search.suggest - search.highlight - search.share markdown_extensions: - attr_list - md_in_html - admonition - def_list - pymdownx.tasklist: custom_checkbox: true - pymdownx.details - pymdownx.highlight: anchor_linenums: true - pymdownx.inlinehilite - pymdownx.snippets - pymdownx.superfences - pymdownx.emoji: emoji_index: !!python/name:materialx.emoji.twemoji emoji_generator: !!python/name:materialx.emoji.to_svg options: custom_icons: - overrides/.icons - toc: permalink: true - tables - meta plugins: - search - awesome-pages extra: generator: false extra_css: - assets/css/util.css ```
deploy action ``` name: action on: push: branches: - master - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v2 with: python-version: 3.x - run: pip install mkdocs-material - run: pip install mkdocs-awesome-pages-plugin - run: mkdocs gh-deploy --force ```

The contents of the file I want to exclude looks like this (if it matters)

---
title: h
description: Some description
tags: ['tag1, 'tag2']
---

# ![](../../assets/images/icon.png) Header

content for the file....

Anyone has any ideas on what I'm doing wrong?

lukasgeiter commented 2 years ago

I can't see any mistakes in your code, could you share a repo that reproduces the issue?


Be aware that the filtering inside a .pages file only works with all items on that "level" (in that folder essentially). I'm working on a new version that would remove this limitation, but until then you have 3 options:

lin-ycv commented 2 years ago

@lukasgeiter this would be a reppo that reproduces the issue: https://github.com/lin-ycv/awesome-pages-test as you can see, this page is in the nav bar https://lin-ycv.github.io/awesome-pages-test/Rh/Gr/h_Un%20Cl/ even tho it starts with h and I've configured .pages to exclude it here: https://github.com/lin-ycv/awesome-pages-test/blob/main/docs/.pages

lin-ycv commented 2 years ago
  • (once you get it working) add the .pages file in every relevant folder
  • Use the nav attribute in mkdocs.yml instead (same syntax, but it filters the whole tree)

Tried these 2 options, they didn't work either, can't test the 3rd option since I'd prefer the pages to be built

lukasgeiter commented 2 years ago

Thanks for the repo. This regex should work:

nav:
    - ... | regex=^[^h]

Side note: The None in the navigation is because your index.md has an empty title annotation.

lin-ycv commented 2 years ago

Thanks, that regex does work.