Skip to content

Commit

Permalink
feat: clean command and build --clean (#103)
Browse files Browse the repository at this point in the history
Adds a clean command to empty the build directory and adds a --clean
option to the build command
  • Loading branch information
johnfraney authored Dec 29, 2024
1 parent 0c6dd22 commit 0c73317
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
22 changes: 20 additions & 2 deletions blurry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,20 @@ def gather_file_data_by_directory() -> DirectoryFileData:
return sort_directory_file_data_by_date(file_data_by_directory)


@app.command(name="clean")
def clean_build_directory():
"""Removes the build directory for a clean build."""
update_settings()
build_directory = get_build_directory()

try:
shutil.rmtree(build_directory)
except FileNotFoundError:
pass


@app.async_command()
async def build(release=True):
async def build(release=True, clean: bool = False):
"""Generates HTML content from Markdown files."""
start = datetime.now()

Expand All @@ -234,8 +246,14 @@ async def build(release=True):
print_plugin_table()

update_settings()
content_directory = get_content_directory()
build_directory = get_build_directory()

if clean:
clean_build_directory()

build_directory.mkdir(parents=True, exist_ok=True)

content_directory = get_content_directory()
build_directory.mkdir(parents=True, exist_ok=True)
jinja_env = get_jinja_env()

Expand Down
10 changes: 10 additions & 0 deletions docs/content/commands/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,13 @@ dist

18 directories, 19 files
```

## Options

`clean`: cleans the build directory before building.

Usage:

```bash
blurry build --clean
```
12 changes: 12 additions & 0 deletions docs/content/commands/clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
+++
"@type" = "WebPage"
name = "Commands: clean"
abstract = "The clean command for Blurry, a Python static site generator focused on page speed and SEO"
datePublished = 2024-12-28
+++

# Commands: clean

`clean` removes the build folder and all of its contents.

The build folder is specified by the `build_directory_name` [setting](./../configuration/settings.md), and defaults to `./dist/`.
3 changes: 2 additions & 1 deletion docs/templates/base.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">

<head>
<title>{% block title %}{% endblock %} · {{ sourceOrganization.name }}</title>
<title>{% block title %}{% endblock %} | {{ sourceOrganization.name }}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{{ abstract|safe}}">
Expand Down Expand Up @@ -37,6 +37,7 @@
<ul>
<li><a href="/commands/build/" rel="noreferrer"><code>build</code></a></li>
<li><a href="/commands/runserver/" rel="noreferrer"><code>runserver</code></a></li>
<li><a href="/commands/clean/" rel="noreferrer"><code>clean</code></a></li>
</ul>
</li>
<li>Content
Expand Down

0 comments on commit 0c73317

Please sign in to comment.