Skip to content

Commit e54d38e

Browse files
committed
Use ContentManager for creating an entry in a Collection.
1 parent 662ba2d commit e54d38e

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/render_engine_cli/cli.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import datetime
22
import json
3-
import re
4-
import subprocess
53
from pathlib import Path
64

75
import click
@@ -299,6 +297,7 @@ def new_entry(
299297
)
300298
):
301299
raise click.exceptions.BadParameter(f"Unknown collection: {collection}")
300+
# pdb.set_trace()
302301
filepath = Path(_collection.content_path).joinpath(filename)
303302
if filepath.exists():
304303
if not click.confirm(
@@ -310,16 +309,19 @@ def new_entry(
310309
raise TypeError("Both content and content_file provided. At most one may be provided.")
311310
if content_file:
312311
content = content_file
313-
entry = create_collection_entry(content=content or "", collection=_collection, **parsed_args)
314312
if title:
315-
# If we had a title earlier this is where we replace the default that is added by the template handler with
316-
# the one supplied by the user.
317-
entry = re.sub(r"title: Untitled Entry", f"title: {title}", entry)
318-
filepath.write_text(entry)
319-
Console().print(f'New {collection} entry created at "{filepath}"')
320-
321-
if editor:
322-
subprocess.run([editor, filepath])
313+
parsed_args["title"] = title
314+
try:
315+
entry = create_collection_entry(
316+
editor=editor,
317+
filepath=filepath,
318+
content=content or "",
319+
collection=_collection,
320+
**parsed_args,
321+
)
322+
except ValueError as e:
323+
raise click.BadParameter from e
324+
click.echo(entry)
323325

324326

325327
@app.command

src/render_engine_cli/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ def get_available_themes(console: Console, site: Site, theme_name: str) -> list[
130130
return []
131131

132132

133-
def create_collection_entry(content: str | None, collection: Collection, **context):
133+
def create_collection_entry(
134+
filepath: Path, editor: str | None, content: str | None, collection: Collection, **context
135+
) -> str:
134136
"""Creates a new entry for a collection"""
135-
return collection.Parser.create_entry(content=content, **collection._metadata_attrs(), **context)
137+
return collection.content_manager.create_entry(filepath, editor, content, context)
136138

137139

138140
def split_args(args: list[str] | None) -> dict[str, str]:

0 commit comments

Comments
 (0)