|
| 1 | +--- |
| 2 | +title: "Render Engine CLI" |
| 3 | +description: "Guide to using Render Engine CLI for creating, building, and serving your site." |
| 4 | +date: August 22, 2024 |
| 5 | +tags: ["render-engine", "cli", "site-setup", "build", "serve"] |
| 6 | +--- |
| 7 | + |
| 8 | +Render Engine comes with a CLI that can be used to create, build, and serve your site. |
| 9 | + |
| 10 | +> !!! Note |
| 11 | + The CLI is no longer a part of the Render Engine package and must be installed |
| 12 | + separately. To install run `pip install render-engine-cli`. Render Engine can be |
| 13 | + installed together with the CLI as well using |
| 14 | + `pip install render-engine[cli]`. |
| 15 | + |
| 16 | +## pyproject.toml Configuration |
| 17 | + |
| 18 | +The Render Engine CLI can be configured through your `pyproject.toml` file to set default values and avoid |
| 19 | +repetitive command-line arguments. |
| 20 | + |
| 21 | +### Configuration Options |
| 22 | + |
| 23 | +- **module**: The Python module containing your Site class |
| 24 | +- **site**: The name of your Site class within the module |
| 25 | +- **collection**: Default collection name for the `new-entry` command |
| 26 | + |
| 27 | +### Example Configuration |
| 28 | + |
| 29 | +```toml |
| 30 | +[tool.render-engine.cli] |
| 31 | +module = "my_site" |
| 32 | +site = "MySite" |
| 33 | +collection = "posts" |
| 34 | +``` |
| 35 | + |
| 36 | +With this configuration, commands that normally require `module:site` can be run without arguments: |
| 37 | + |
| 38 | +- `render-engine build` instead of `render-engine build my_site:MySite` |
| 39 | +- `render-engine serve` instead of `render-engine serve my_site:MySite` |
| 40 | + |
| 41 | +## CLI Commands |
| 42 | + |
| 43 | +### init |
| 44 | + |
| 45 | +Create a new Render Engine site from a template. |
| 46 | + |
| 47 | +```bash |
| 48 | +render-engine init [TEMPLATE] [OPTIONS] |
| 49 | +``` |
| 50 | + |
| 51 | +**Arguments:** |
| 52 | + |
| 53 | +- `TEMPLATE`: Template URL or path (default: <https://github.com/render-engine/cookiecutter-render-engine-site>) |
| 54 | + |
| 55 | +**Options:** |
| 56 | + |
| 57 | +- `--extra-context, -e`: Extra context as JSON string |
| 58 | +- `--no-input`: Skip all prompts |
| 59 | +- `--output-dir`: Output directory (default: ./) |
| 60 | +- `--config-file, -c`: Path to cookiecutter config file |
| 61 | + |
| 62 | +**Examples:** |
| 63 | + |
| 64 | +```bash |
| 65 | +# Use default template |
| 66 | +render-engine init |
| 67 | + |
| 68 | +# Use custom template with no prompts |
| 69 | +render-engine init https://github.com/myuser/mytemplate --no-input |
| 70 | + |
| 71 | +# Provide extra context |
| 72 | +render-engine init --extra-context '{"project_name": "My Blog"}' |
| 73 | +``` |
| 74 | + |
| 75 | +### build |
| 76 | + |
| 77 | +Build your static site. |
| 78 | + |
| 79 | +```bash |
| 80 | +render-engine build [MODULE:SITE] [OPTIONS] |
| 81 | +``` |
| 82 | + |
| 83 | +**Arguments:** |
| 84 | + |
| 85 | +- `MODULE:SITE`: Module path and site class (e.g., `my_site:MySite`) |
| 86 | + |
| 87 | +**Options:** |
| 88 | + |
| 89 | +- `--clean, -c`: Remove output folder before building |
| 90 | + |
| 91 | +**Examples:** |
| 92 | + |
| 93 | +```bash |
| 94 | +# Basic build |
| 95 | +render-engine build my_site:MySite |
| 96 | + |
| 97 | +# Build with clean |
| 98 | +render-engine build my_site:MySite --clean |
| 99 | + |
| 100 | +# Using config defaults |
| 101 | +render-engine build |
| 102 | +``` |
| 103 | + |
| 104 | +### serve |
| 105 | + |
| 106 | +Serve your site locally with auto-reload capability. |
| 107 | + |
| 108 | +```bash |
| 109 | +render-engine serve [MODULE:SITE] [OPTIONS] |
| 110 | +``` |
| 111 | + |
| 112 | +**Arguments:** |
| 113 | + |
| 114 | +- `MODULE:SITE`: Module path and site class |
| 115 | + |
| 116 | +**Options:** |
| 117 | + |
| 118 | +- `--clean, -c`: Clean output folder before building |
| 119 | +- `--reload, -r`: Auto-reload on file changes |
| 120 | +- `--directory, -d`: Directory to serve (default: output) |
| 121 | +- `--port, -p`: Port number (default: 8000) |
| 122 | + |
| 123 | +**Examples:** |
| 124 | + |
| 125 | +```bash |
| 126 | +# Basic serve |
| 127 | +render-engine serve my_site:MySite |
| 128 | + |
| 129 | +# Serve with auto-reload on port 3000 |
| 130 | +render-engine serve my_site:MySite --reload --port 3000 |
| 131 | + |
| 132 | +# Clean build and serve |
| 133 | +render-engine serve my_site:MySite --clean --reload |
| 134 | +``` |
| 135 | + |
| 136 | +### templates |
| 137 | + |
| 138 | +List available templates from installed themes. |
| 139 | + |
| 140 | +```bash |
| 141 | +render-engine templates [MODULE:SITE] [OPTIONS] |
| 142 | +``` |
| 143 | + |
| 144 | +**Arguments:** |
| 145 | + |
| 146 | +- `MODULE:SITE`: Module path and site class |
| 147 | + |
| 148 | +**Options:** |
| 149 | + |
| 150 | +- `--theme-name`: Specific theme to list templates from |
| 151 | +- `--filter-value`: Filter templates by name |
| 152 | + |
| 153 | +**Examples:** |
| 154 | + |
| 155 | +```bash |
| 156 | +# List all templates |
| 157 | +render-engine templates my_site:MySite |
| 158 | + |
| 159 | +# List templates from specific theme |
| 160 | +render-engine templates my_site:MySite --theme-name bootstrap |
| 161 | + |
| 162 | +# Filter templates containing "post" |
| 163 | +render-engine templates my_site:MySite --filter-value post |
| 164 | +``` |
| 165 | + |
| 166 | +### new-entry |
| 167 | + |
| 168 | +Create a new collection entry (blog post, page, etc.). |
| 169 | + |
| 170 | +```bash |
| 171 | +render-engine new-entry [MODULE:SITE] [COLLECTION] [FILENAME] [OPTIONS] |
| 172 | +``` |
| 173 | + |
| 174 | +**Arguments:** |
| 175 | + |
| 176 | +- `MODULE:SITE`: Module path and site class |
| 177 | +- `COLLECTION`: Collection name (e.g., "blog", "pages") |
| 178 | +- `FILENAME`: Output filename for the new entry |
| 179 | + |
| 180 | +**Options:** |
| 181 | + |
| 182 | +- `--content`: Content string for the entry |
| 183 | +- `--content-file`: Path to file containing content |
| 184 | +- `--title`: Entry title |
| 185 | +- `--slug`: URL slug for the entry |
| 186 | +- `--args`: Additional metadata as key=value or key:value pairs |
| 187 | +- `--include-date`: Add today's date to the entry. NOTE: If this is set and a |
| 188 | +date is included in the `--args` the one from the `--args` will be used. |
| 189 | + |
| 190 | +**Examples:** |
| 191 | + |
| 192 | +```bash |
| 193 | +# Create a basic blog post |
| 194 | +render-engine new-entry my_site:MySite blog my-first-post.md --title "My First Post" |
| 195 | + |
| 196 | +# Create post with content |
| 197 | +render-engine new-entry my_site:MySite blog hello.md --content "Hello, world!" --title "Hello" |
| 198 | + |
| 199 | +# Create post from file with metadata |
| 200 | +render-engine new-entry my_site:MySite blog review.md \ |
| 201 | + --content-file draft.txt \ |
| 202 | + --title "Product Review" \ |
| 203 | + --args author="John Doe" \ |
| 204 | + --args category=reviews \ |
| 205 | + --args tags="product,tech" |
| 206 | + |
| 207 | +# Using slug |
| 208 | +render-engine new-entry my_site:MySite pages about.md \ |
| 209 | + --title "About Us" \ |
| 210 | + --slug "about-us" |
| 211 | + |
| 212 | +# With --include-date |
| 213 | +render-engine new-entry my_site:MySite pages about.md \ |
| 214 | + --include-date |
| 215 | +``` |
| 216 | + |
| 217 | +**Notes:** |
| 218 | + |
| 219 | +- The `--args` option can be used multiple times |
| 220 | +- Arguments can use either `=` or `:` as separator |
| 221 | +- If `EDITOR` environment variable is set, the file opens automatically after creation |
| 222 | +- Cannot use both `--content` and `--content-file` options |
| 223 | + |
| 224 | +## Usage Tips |
| 225 | + |
| 226 | +1. **Configuration First**: Set up your `pyproject.toml` to avoid typing module:site repeatedly |
| 227 | +2. **Development Workflow**: Use `serve --reload` during development for instant feedback |
| 228 | +3. **Clean Builds**: Use `--clean` flag when switching between major changes |
| 229 | +4. **Template Discovery**: Use `templates --filter-value` to find specific template types |
| 230 | +5. **Batch Entry Creation**: Combine `new-entry` with shell scripts for bulk content creation |
0 commit comments