diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..a3180aa --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,44 @@ +## Description + + +This PR enhances the project documentation by adding comprehensive API reference, user guide, and contributing guidelines. + +### Changes Made +- Add comprehensive API documentation with examples +- Include detailed user guide with practical examples +- Add best practices section covering performance, SEO, security, and monitoring +- Create CONTRIBUTING.md with detailed contribution guidelines +- Update README.md with quick-start contributing section + +## Type of Change + + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [x] Documentation update +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + +## Testing + + +- [x] Verified all documentation links are working +- [x] Checked code examples for accuracy +- [x] Validated markdown formatting +- [x] Ensured consistency with existing documentation + +## Checklist + + +- [x] My code follows the style guidelines of this project +- [x] I have performed a self-review of my own changes +- [x] I have commented my code, particularly in hard-to-understand areas +- [x] I have made corresponding changes to the documentation +- [x] My changes generate no new warnings +- [x] I have added tests that prove my fix is effective or that my feature works +- [x] New and existing unit tests pass locally with my changes +- [x] Any dependent changes have been merged and published in downstream modules + +## Additional Notes + + +The documentation improvements aim to make the project more accessible to new contributors and provide clearer guidance for users implementing SEO optimization in their Django projects. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1aa6eff --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,167 @@ +# Contributing to Django SEO Optimizer + +First off, thank you for considering contributing to Django SEO Optimizer! It's people like you that make Django SEO Optimizer such a great tool. + +## Code of Conduct + +This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code. + +## How Can I Contribute? + +### Reporting Bugs + +Before creating bug reports, please check the issue list as you might find out that you don't need to create one. When you are creating a bug report, please include as many details as possible: + +* Use a clear and descriptive title +* Describe the exact steps which reproduce the problem +* Provide specific examples to demonstrate the steps +* Describe the behavior you observed after following the steps +* Explain which behavior you expected to see instead and why +* Include details about your configuration and environment + +### Suggesting Enhancements + +Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, please include: + +* Use a clear and descriptive title +* Provide a step-by-step description of the suggested enhancement +* Provide specific examples to demonstrate the steps +* Describe the current behavior and explain which behavior you expected to see instead +* Explain why this enhancement would be useful + +### Pull Requests + +* Fill in the required template +* Do not include issue numbers in the PR title +* Follow the Python style guide +* Include thoughtfully-worded, well-structured tests +* Document new code +* End all files with a newline + +## Development Process + +1. Fork the repo and create your branch from `develop` +2. Install development dependencies: + ```bash + pip install -e ".[dev]" + ``` +3. Run tests to ensure everything is working: + ```bash + pytest + ``` +4. Make your changes and add tests +5. Run the test suite again +6. Push to your fork and submit a pull request + +## Testing + +We use pytest for our test suite. To run tests: + +```bash +# Run all tests +pytest + +# Run specific test file +pytest tests/test_fields.py + +# Run with coverage report +pytest --cov=seo_optimizer +``` + +### Writing Tests + +* Write test docstrings +* Each test should have a single assertion +* Use descriptive test names +* Follow the Arrange-Act-Assert pattern + +Example: +```python +def test_metadata_field_validates_max_length(): + """Test that MetadataField correctly validates max_length.""" + # Arrange + field = MetadataField(max_length=10) + + # Act & Assert + with pytest.raises(ValidationError): + field.clean("This is too long") +``` + +## Style Guide + +We follow PEP 8 with some modifications: + +* Line length limit is 100 characters +* Use double quotes for strings +* Use trailing commas in multi-line structures +* Sort imports using isort + +Use black for code formatting: +```bash +black seo_optimizer +``` + +## Documentation + +* Use Google-style docstrings +* Update the README.md if needed +* Add docstrings to all public methods +* Include code examples in docstrings +* Update type hints + +Example: +```python +def get_metadata( + self, + path: str, + language: Optional[str] = None +) -> Dict[str, Any]: + """Get metadata for the given path and language. + + Args: + path: The URL path to get metadata for + language: Optional language code (e.g., 'en', 'es') + + Returns: + Dictionary containing metadata fields + + Example: + >>> meta = MetadataManager().get_metadata('/products/') + >>> print(meta['title']) + 'Our Products' + """ +``` + +## Commit Messages + +* Use the present tense ("Add feature" not "Added feature") +* Use the imperative mood ("Move cursor to..." not "Moves cursor to...") +* Limit the first line to 72 characters or less +* Reference issues and pull requests liberally after the first line + +Example: +``` +Add async support for metadata retrieval + +- Implement AsyncMetadataManager +- Add async_get_metadata method +- Update documentation with async examples + +Fixes #123 +``` + +## Release Process + +1. Update version in `seo_optimizer/version.py` +2. Update CHANGELOG.md +3. Create release notes +4. Tag the release +5. Push to PyPI + +## Questions? + +Feel free to contact the project maintainers if you have any questions or need help with the contribution process. + +## License + +By contributing, you agree that your contributions will be licensed under the MIT License. diff --git a/README.md b/README.md index 29a9d22..a815c2c 100644 --- a/README.md +++ b/README.md @@ -107,13 +107,312 @@ report = analytics.generate_report() print(report.suggestions) ``` -## Documentation +## API Documentation -For detailed documentation, visit [avixiii.com/django-seo-optimizer](https://avixiii.com/django-seo-optimizer) +### Core Components + +#### MetadataField + +The base field type for SEO metadata: + +```python +from seo_optimizer import MetadataField + +title = MetadataField( + max_length=70, + required=True, + template_support=True +) +``` + +**Parameters:** +- `max_length`: Maximum length of the field value +- `required`: Whether the field is required +- `template_support`: Enable Django template syntax in field values +- `validators`: List of validation functions + +#### Specialized Fields + +```python +from seo_optimizer import KeywordsField, RobotsField, OpenGraphField + +# Keywords with automatic comma separation +keywords = KeywordsField(max_keywords=10) + +# Robots directives with validation +robots = RobotsField(default="index,follow") + +# Open Graph metadata +og = OpenGraphField( + title_max_length=95, + description_max_length=200 +) +``` + +#### AsyncMetadataManager + +For high-performance async metadata operations: + +```python +from seo_optimizer import AsyncMetadataManager + +async def get_meta(path): + manager = AsyncMetadataManager() + return await manager.get_metadata(path) +``` + +### Configuration Options + +Available settings in `settings.py`: + +```python +SEO_OPTIMIZER = { + 'CACHE_TIMEOUT': 3600, # 1 hour + 'ASYNC_ENABLED': True, + 'MAX_ASYNC_WORKERS': 10, + 'USE_SITES_FRAMEWORK': True, + 'DEFAULT_LANGUAGE': 'en', +} +``` + +## User Guide + +### Basic Setup + +1. Install the package: +```bash +pip install django-seo-optimizer +``` + +2. Add to INSTALLED_APPS: +```python +INSTALLED_APPS = [ + ... + 'seo_optimizer', +] +``` + +3. Run migrations: +```bash +python manage.py migrate seo_optimizer +``` + +### Metadata Configuration + +Create a metadata configuration file (e.g., `seo.py`): + +```python +from seo_optimizer import register_metadata, MetadataField + +@register_metadata +class BlogMetadata: + title = MetadataField(max_length=70) + description = MetadataField(max_length=160) + keywords = KeywordsField() + + class Meta: + use_cache = True + use_sites = True + use_i18n = True +``` + +### Template Integration + +```html +{% load seo_tags %} + +{% get_metadata as meta %} +
+