CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mkdocs-awesome-pages-plugin

An MkDocs plugin that simplifies configuring page titles and their order through .pages configuration files

56

0.94x

Evaluation56%

0.94x

Agent success when using this tile

Overview
Eval results
Files

rest-patterns.mddocs/

Rest Entry Patterns

Pattern matching system for "..." rest entries in navigation configurations. Rest entries provide powerful filtering and inclusion capabilities, supporting glob patterns, regular expressions, and structural flattening options for flexible navigation control.

Capabilities

Rest Item Classes

Core classes that handle rest entry parsing, pattern matching, and filtering logic.

class MetaNavRestItem(MetaNavItem):
    """
    Handles "..." rest entries with patterns and filters.
    
    Rest entries allow including remaining files/directories with optional
    filtering using glob patterns or regular expressions.
    
    Attributes:
        type (RestType): Type of pattern matching (GLOB, REGEX, ALL)
        pattern (str): Pattern string for filtering
        flat (bool): Whether to flatten nested structure
    
    Args:
        value (str): Rest entry string with optional pattern/flags
    """
    
    def __init__(self, value: str): ...
    
    def matches(self, path: str) -> bool:
        """
        Check if a file path matches this rest item's pattern.
        
        Args:
            path (str, optional): File path to test against pattern
            
        Returns:
            bool: True if path matches the pattern criteria
        """
    
    @staticmethod
    def is_rest(item: Any) -> bool:
        """
        Check if an item represents a rest entry.
        
        Args:
            item (Any): Item to test
            
        Returns:
            bool: True if item is a rest entry string
        """

class RestType(Enum):
    """
    Types of rest pattern matching.
    
    Values:
        GLOB: Glob pattern matching with wildcards
        REGEX: Regular expression pattern matching
        ALL: Include all remaining items (no filtering)
    """
    GLOB = "glob"
    REGEX = "regex"
    ALL = "all"

Rest Item Collection

Container class for managing multiple rest entries with different pattern types and processing order.

class RestItemList:
    """
    Container for rest items with pattern and all categories.
    
    Separates pattern-based rest items from catch-all rest items
    and provides ordered iteration for processing.
    """
    
    def __init__(self): ...
    
    def append(self, item: MetaNavRestItem):
        """
        Add a rest item to the collection.
        
        Args:
            item (MetaNavRestItem): Rest item to add
        """
    
    def __iter__(self) -> Iterator[MetaNavRestItem]:
        """
        Iterate over rest items in processing order.
        
        Pattern items are processed first, then catch-all items.
        
        Returns:
            Iterator[MetaNavRestItem]: Rest items in processing order
        """
    
    def __len__(self) -> int:
        """
        Get total number of rest items.
        
        Returns:
            int: Total count of pattern and all rest items
        """

Usage Examples

Basic rest entry usage:

# .pages
nav:
  - introduction.md
  - ...  # Include all remaining files here
  - conclusion.md

Advanced rest entries with patterns:

# .pages
nav:
  - overview.md
  
  # Glob pattern matching
  - ... | glob=tutorial-*.md  # Files like tutorial-01.md, tutorial-basic.md
  - ... | glob=api/**/*.md    # All markdown files in api/ subdirectories
  
  # Regular expression matching  
  - ... | regex=test.*\.md    # Files matching regex pattern
  - ... | regex=^guide-      # Files starting with "guide-"
  
  # Flattening nested structure
  - ... | flat               # Flatten all remaining items
  - ... | flat | glob=*.md   # Flatten and filter by pattern
  
  # Multiple rest entries
  - ... | glob=beginner-*.md # Beginner tutorials first
  - ... | glob=advanced-*.md # Advanced tutorials second
  - ...                      # Everything else last
  
  - summary.md

Pattern matching examples:

# Glob patterns (using wcmatch.glob)
"..." | glob=*.md          # All .md files in current directory
"..." | glob=**/*.py       # All .py files recursively
"..." | glob=test-*.md     # Files starting with "test-"
"..." | glob=**/index.md   # All index.md files anywhere

# Regular expressions (using re.search)
"..." | regex=test.*\.md   # Files matching regex
"..." | regex=^api-        # Files starting with "api-" 
"..." | regex=v\d+\.md$    # Files like v1.md, v2.md, etc.

# Flattening behavior
"..." | flat               # Remove directory structure, include files directly
"..." | flat | glob=*.md   # Flatten structure and filter by glob pattern

Rest entry syntax patterns:

# All rest entry variations
nav:
  - ...                           # Include all remaining (RestType.ALL)
  - ... | flat                   # Include all, flatten structure  
  - ... | glob=pattern           # Filter with glob pattern (RestType.GLOB)
  - ... | regex=pattern          # Filter with regex (RestType.REGEX)
  - ... | flat | glob=pattern    # Flatten and filter with glob
  - ... | flat | regex=pattern   # Flatten and filter with regex

Pattern Matching Details

Glob Pattern Support

Uses the wcmatch library with GLOBSTAR flag support:

  • * matches any characters except path separators
  • ** matches any characters including path separators (recursive)
  • ? matches any single character except path separators
  • [...] matches any character in brackets
  • {a,b} matches either a or b (brace expansion)

Regular Expression Support

Uses Python's re.search() with PurePath.as_posix() normalized paths:

  • Full regex syntax support
  • Path separators normalized to forward slashes
  • Case-sensitive matching (use (?i) flag for case-insensitive)
  • Matches anywhere in the path (not anchored by default)

Flattening Behavior

The flat flag affects how nested directory structures are handled:

  • Without flat: Maintains directory hierarchy in navigation
  • With flat: Extracts files from subdirectories and includes them directly
  • Flat + patterns: Apply pattern matching to flattened file list

Processing Order

Rest entries are processed in a specific order to ensure predictable results:

  1. Pattern-based rest entries (GLOB and REGEX types) are processed first
  2. Catch-all rest entries (ALL type) are processed last
  3. Within each type, rest entries are processed in the order they appear
  4. Files can only match one rest entry - first match wins
  5. Remaining unmatched files are handled by catch-all entries

This ordering allows for sophisticated filtering pipelines where specific patterns capture targeted files before general catch-all entries process the remainder.

Install with Tessl CLI

npx tessl i tessl/pypi-mkdocs-awesome-pages-plugin

docs

index.md

navigation-processing.md

pages-configuration.md

plugin-configuration.md

rest-patterns.md

tile.json