make docs preprocessor more generic and update docs (#58)

This commit is contained in:
Josh Thomas 2025-01-03 08:38:36 -06:00 committed by GitHub
parent 6924fe7c74
commit d9d0f4ee87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 9 deletions

View file

@ -113,7 +113,7 @@ The server has only been tested with Neovim. Documentation for setting up the la
If you run into issues setting up the language server: If you run into issues setting up the language server:
1. Check the existing documentation in `docs/editors/` 1. Check the existing documentation in `docs/editors/`
2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/blob/main/../../issues/new) describing your setup and the problems you're encountering 2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/issues/new) describing your setup and the problems you're encountering
- Include your editor and any relevant configuration - Include your editor and any relevant configuration
- Share any error messages or unexpected behavior - Share any error messages or unexpected behavior
- The more details, the better! - The more details, the better!

View file

@ -270,25 +270,28 @@ def preview_changes(original: str, processed: str) -> None:
print_change_group(group) print_change_group(group)
def process_readme( def process_file(
input: str = "README.md", input: str = "README.md",
output: str = "docs/index.md", output: str = "docs/index.md",
processors: list[ProcessingFunc] | None = None, processors: list[ProcessingFunc] | None = None,
preview: bool = True, preview: bool = True,
description: str | None = None,
) -> bool: ) -> bool:
""" """
Process README.md with given processing functions. Process a file with given processing functions.
Args: Args:
input_path: Path to the input README.md file input: Path to the input file
output_path: Path where the processed file will be saved output: Path where the processed file will be saved
processors: List of processing functions to apply processors: List of processing functions to apply
preview: Whether to show a preview of changes preview: Whether to show a preview of changes
description: Optional description for status message
Returns: Returns:
bool: True if processing was successful, False otherwise bool: True if processing was successful, False otherwise
""" """
with console.status("[bold green]Processing README...") as status: status_msg = f"[bold green]Processing {description or input}..."
with console.status(status_msg) as status:
input_path = Path(input) input_path = Path(input)
output_path = Path(output) output_path = Path(output)
@ -442,10 +445,12 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
Input: Input:
See the [`LICENSE`](LICENSE) file for more information. See the [`LICENSE`](LICENSE) file for more information.
Check the [Neovim](/docs/editors/neovim.md) guide. Check the [Neovim](/docs/editors/neovim.md) guide.
Open an [issue](../../issues/new) to report bugs.
Output: Output:
See the [`LICENSE`](https://github.com/username/repo/blob/main/LICENSE) file for more information. See the [`LICENSE`](https://github.com/username/repo/blob/main/LICENSE) file for more information.
Check the [Neovim](editors/neovim.md) guide. Check the [Neovim](editors/neovim.md) guide.
Open an [issue](https://github.com/username/repo/issues/new) to report bugs.
""" """
def processor(content: str) -> str: def processor(content: str) -> str:
@ -467,6 +472,13 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
clean_path = path.removeprefix("/docs/").removeprefix("docs/") clean_path = path.removeprefix("/docs/").removeprefix("docs/")
return f"[{text}]({clean_path})" return f"[{text}]({clean_path})"
# Handle relative paths with ../ or ./
if "../" in path or "./" in path:
# Special handling for GitHub-specific paths
if "issues/" in path or "pulls/" in path:
clean_path = path.replace("../", "").replace("./", "")
return f"[{text}]({repo_url}/{clean_path})"
# Handle root-relative paths # Handle root-relative paths
if path.startswith("/"): if path.startswith("/"):
path = path.removeprefix("/") path = path.removeprefix("/")
@ -487,8 +499,7 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
def main(): def main():
"""Example usage of the readme processor.""" console.print("[bold blue]File Processor[/bold blue]")
console.print("[bold blue]README Processor[/bold blue]")
processors = [ processors = [
add_frontmatter({"title": "Home"}), add_frontmatter({"title": "Home"}),
@ -498,11 +509,12 @@ def main():
), ),
] ]
success = process_readme( success = process_file(
input="README.md", input="README.md",
output="docs/index.md", output="docs/index.md",
processors=processors, processors=processors,
preview=True, preview=True,
description="README.md → docs/index.md",
) )
if success: if success: