Skip to content

Commit

Permalink
Use default author
Browse files Browse the repository at this point in the history
  • Loading branch information
Siecje committed Jun 24, 2024
1 parent 491c62c commit 3bca158
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions htmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ def verify() -> None:
# reload is needed for testing when the directory changes
# FlatPages has already been loaded so the pages do not reload
importlib.reload(site)
app = site.app

correct = True
required_fields = ('author', 'title')
required_fields = ['title']
# Only check author if there is no default
if not app.config.get('DEFAULT_AUTHOR'):
required_fields.append('author')
for post in site.posts:
for field in required_fields:
if field not in post.meta:
Expand All @@ -87,7 +91,6 @@ def verify() -> None:
click.echo(click.style(msg, fg='green'))

# Check if SITE_NAME exists
app = site.app
site_name = app.config.get('SITE_NAME')
if not site_name:
# SITE_NAME is not required
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ beautifulsoup4==4.12.3
click==8.1.7
csscompressor==0.9.5
feedwerk==1.2.0
Flask==3.0.1
Flask==3.0.3
Flask-FlatPages==0.8.2
Frozen-Flask==1.0.2
htmlmin==0.1.12
jsmin==3.0.1
Pygments==2.17.2
Pygments==2.18.0
requests==2.31.0
19 changes: 19 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,22 @@ def test_build_vcs_repo(run_start: CliRunner) -> None:
run_start.invoke(build)
for path in path_list:
assert path.is_dir()


def test_build_with_default_author(run_start: CliRunner) -> None:
config_path = Path('config.toml')
with config_path.open('r') as config_file:
lines = config_file.readlines()

with config_path.open('w') as config_file:
for line in lines:
if 'default_name' in line:
config_file.write('default_name = "Taylor"\n')
else:
config_file.write(line)

remove_fields_from_post('example', ('draft',))

result = run_start.invoke(build)
assert result.exit_code == 0
assert re.search(SUCCESS_REGEX, result.output)

0 comments on commit 3bca158

Please sign in to comment.