Update README.md

This commit is contained in:
pacnpal
2024-12-09 21:13:25 -05:00
committed by GitHub
parent 40b57348a2
commit 48e7235ba7

173
README.md
View File

@@ -1,45 +1,39 @@
# README.md # Astro Documentation PDF Generator
# Astro Documentation to PDF Converter
A Python script that automatically generates a well-formatted PDF from Astro's documentation repository. The script clones the documentation, processes all markdown files, and creates a PDF with a table of contents, proper formatting, and consistent styling. A Python script to generate a PDF from Astro's documentation. Forked from [Docs-Exporter](https://github.com/Riyooo/Docs-Exporter) and modified to work with Astro's documentation format.
## Features ## Overview
- Automatic repository cloning and updating This script:
- Comprehensive documentation processing - Clones the Astro documentation repository
- Table of contents generation - Processes Markdown/MDX files
- Code block syntax highlighting - Generates a PDF with:
- Image path handling - Cover page
- Proper page breaks - Table of contents
- Custom header and footer - Formatted content
- Error handling and recovery - Headers and footers
- Progress reporting - Code syntax highlighting
- Clean temporary file management - Proper page breaks
## Requirements ## Requirements
### System Requirements ### System Requirements
- Python 3.7 or higher - Python 3.7+
- Git installed and accessible from command line - Git installed and accessible from command line
- Internet connection for repository access - Internet connection for cloning repositories
### Python Dependencies ### Python Dependencies
Install all required packages:
```bash
pip install -r requirements.txt
```
Install Playwright's browser:
```bash ```bash
pip install gitpython markdown packaging playwright pyyaml tqdm
playwright install chromium playwright install chromium
``` ```
## Installation ## Usage
1. Clone this repository or download the script files: 1. Clone this repository:
```bash ```bash
git clone git clone <your-repo-url>
cd cd <repo-directory>
``` ```
2. Install dependencies: 2. Install dependencies:
@@ -48,116 +42,55 @@ pip install -r requirements.txt
playwright install chromium playwright install chromium
``` ```
3. Ensure you have the following files in your directory: 3. Run the script:
- `astro_docs_to_pdf.py` (main script)
- `requirements.txt`
- `styles.css` (will be created automatically if missing)
## Usage
Run the script:
```bash ```bash
python astro_docs_to_pdf.py python astro_docs_to_pdf.py
``` ```
The script will: The script will:
1. Clone/update the Astro documentation repository - Create a default styles.css if none exists
2. Process all documentation files - Clone the Astro documentation
3. Generate a PDF with proper formatting - Process all documentation files
4. Create a table of contents - Generate a PDF with table of contents
5. Output the final PDF as `Astro_Documentation_YYYY-MM-DD.pdf`
## Output ## Output
The generated PDF includes: The script generates:
- Cover page with title and date - A PDF file named `Astro_Documentation_YYYY-MM-DD.pdf`
- Table of contents with page numbers - Default styling for documentation content
- Formatted documentation content - Hierarchical table of contents
- Code syntax highlighting - Page numbers and generation date
- Properly sized images
- Headers and footers with page numbers
- Consistent styling throughout
## Customization ## Features
### CSS Styling - Automatic table of contents generation
The script creates a default `styles.css` file if none exists. You can modify this file to customize the PDF's appearance. - Code block syntax highlighting
- Image processing
- Proper handling of Astro's MDX format
- Frontmatter parsing
- Clean page breaks
- Responsive design
- Error handling and reporting
### Output Options ## Modifications from Original
You can modify these variables in the script:
```python
repo_dir = "astro-docs" # Local directory for cloned repo
output_pdf = f"Astro_Documentation_{datetime.now().strftime('%Y-%m-%d')}.pdf" # Output filename
```
### PDF Format This fork includes several modifications from the original Docs-Exporter:
Adjust the PDF format options in the `generate_pdf` function: - Updated to use Playwright instead of wkhtmltopdf
```python - Added support for Astro's specific MDX format
format_options = { - Enhanced frontmatter parsing
'format': 'A4', - Improved error handling
'margin': { - Automatic CSS generation
'top': '50px', - Better image handling
'right': '50px',
'bottom': '50px',
'left': '50px'
},
'print_background': True,
# ... other options
}
```
## Troubleshooting ## Credits
### Common Issues - Original project: [Docs-Exporter](https://github.com/Riyooo/Docs-Exporter) by Riyooo
- Modified for Astro documentation format
1. **Git Clone Failures**
- Ensure you have git installed
- Check your internet connection
- Verify repository access permissions
2. **PDF Generation Errors**
- Check if output PDF is already open
- Ensure enough disk space
- Verify Playwright browser installation
3. **Image Loading Issues**
- Check internet connection
- Verify image paths in documentation
- Ensure Playwright timeouts are sufficient
4. **Styling Problems**
- Verify styles.css exists and is readable
- Check CSS syntax
- Ensure no conflicting styles
### Error Messages
The script provides detailed error messages for common issues:
- Repository cloning failures
- File processing errors
- PDF generation problems
- Resource cleanup issues
## Limitations
- Requires active internet connection
- May take several minutes for large documentation sets
- Memory usage scales with documentation size
- Some complex MDX components may not render perfectly
## Contributing
Contributions are welcome! Please feel free to:
1. Report bugs
2. Suggest improvements
3. Submit pull requests
## License ## License
This project is open source and available under the MIT License. [Include the original project's license information here]
## Acknowledgments ## Contributing
- Built using Playwright for PDF generation Contributions are welcome! Please feel free to submit a Pull Request.
- Processes documentation from the official Astro docs repository
- Uses Python's markdown library for processing