|
| 1 | +# Bazel Website Builder - Testing and Generator Agnostic Design |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The website builder in `bazel/website/` provides Bazel rules for building static websites. The design intends to be generator-agnostic, allowing different static site generators (not just Pelican) to be used. |
| 6 | + |
| 7 | +## Current State of Generator-Agnostic Design |
| 8 | + |
| 9 | +### What Works Well (Already Generator-Agnostic) |
| 10 | + |
| 11 | +1. **Generator Parameter**: The `static_website()` macro accepts a `generator` parameter that can point to any Bazel target that acts as a site generator. |
| 12 | + ```starlark |
| 13 | + generator = "@envoy_toolshed//website/tools/pelican" # Default, but customizable |
| 14 | + ``` |
| 15 | + |
| 16 | +2. **Simple Generator Interface**: The generator is invoked with just the content path as an argument: |
| 17 | + ```bash |
| 18 | + $GENERATOR "$CONTENT" |
| 19 | + ``` |
| 20 | + This simple interface makes it easy for different generators to work. |
| 21 | + |
| 22 | +3. **Customizable Parameters**: Key parameters can be customized per-site: |
| 23 | + - `exclude`: List of patterns to exclude from final tarball |
| 24 | + - `mappings`: Dictionary of source to destination path mappings |
| 25 | + - `output_path`: Where the generator outputs files |
| 26 | + - `content_path`: Where content files are located |
| 27 | + |
| 28 | +### Areas That Need Improvement for Full Generator Agnostic Support |
| 29 | + |
| 30 | +1. **Default Exclude Patterns**: The default `exclude` list contains Pelican-specific patterns: |
| 31 | + ```starlark |
| 32 | + exclude = [ |
| 33 | + "archives.html", # Pelican-specific |
| 34 | + "authors.html", # Pelican-specific |
| 35 | + "categories.html", # Pelican-specific |
| 36 | + "external", |
| 37 | + "tags.html", # Pelican-specific |
| 38 | + "pages", # Pelican-specific |
| 39 | + "theme/.webassets-cache", |
| 40 | + "theme/css/_sass", |
| 41 | + "theme/css/main.scss", |
| 42 | + ] |
| 43 | + ``` |
| 44 | + **Recommendation**: These should either be: |
| 45 | + - Moved to a Pelican-specific wrapper function |
| 46 | + - Made conditional based on the generator |
| 47 | + - Or just documented that users should override them when using other generators |
| 48 | + |
| 49 | +2. **Default Mappings**: The default `mappings` assume Pelican's theme structure: |
| 50 | + ```starlark |
| 51 | + mappings = { |
| 52 | + "theme/css": "theme/static/css", |
| 53 | + "theme/js": "theme/static/js", |
| 54 | + "theme/images": "theme/static/images", |
| 55 | + "theme/templates/extra": "theme/templates", |
| 56 | + } |
| 57 | + ``` |
| 58 | + **Recommendation**: Same as above - either make generator-specific wrappers or document override expectations. |
| 59 | + |
| 60 | +## Testing |
| 61 | + |
| 62 | +Tests are located in `bazel/website/tests/` and verify: |
| 63 | + |
| 64 | +1. **Basic Website Generation**: Tests that the macro can build a complete website tarball |
| 65 | +2. **Custom Exclude Patterns**: Tests that custom exclude patterns work |
| 66 | +3. **Custom Mappings**: Tests that custom (or empty) mappings work |
| 67 | +4. **Generator Flexibility**: Tests verify the macro compiles with different parameter combinations |
| 68 | + |
| 69 | +### Running Tests |
| 70 | + |
| 71 | +```bash |
| 72 | +cd bazel |
| 73 | +bazel test //website/tests/... |
| 74 | +``` |
| 75 | + |
| 76 | +### Test Structure |
| 77 | + |
| 78 | +- `tests/test_content/`: Minimal markdown content for test websites |
| 79 | +- `tests/test_theme/`: Minimal Pelican theme templates |
| 80 | +- `tests/test_config.py`: Minimal Pelican configuration |
| 81 | +- `tests/BUILD`: Test targets using the website macros |
| 82 | +- `tests/run_website_tests.sh`: Basic functionality tests |
| 83 | +- `tests/run_parameterized_tests.sh`: Parameter flexibility tests |
| 84 | + |
| 85 | +## Recommendations for Future Iterations |
| 86 | + |
| 87 | +1. **Create Generator-Specific Wrappers**: |
| 88 | + ```starlark |
| 89 | + def pelican_website(**kwargs): |
| 90 | + # Set Pelican-specific defaults |
| 91 | + static_website( |
| 92 | + exclude = ["archives.html", "authors.html", ...], |
| 93 | + mappings = {"theme/css": "theme/static/css", ...}, |
| 94 | + **kwargs |
| 95 | + ) |
| 96 | + ``` |
| 97 | + |
| 98 | +2. **Document Generator Requirements**: Create clear documentation about what a generator must do: |
| 99 | + - Accept content path as first argument |
| 100 | + - Output to the specified output path |
| 101 | + - Handle config files passed via the sources tarball |
| 102 | + |
| 103 | +3. **Add More Generator Examples**: Once the interface is stable, add examples with other generators (Hugo, Jekyll, etc.) to verify true generator-agnostic design. |
| 104 | + |
| 105 | +4. **Consider Environment Variables**: Some generators may need environment variables (like SITEURL in Pelican). The current design handles this, but it could be more explicit in documentation. |
0 commit comments