Skip to content

Commit 7415444

Browse files
committed
Ensure post id is included if updating
1 parent f79a8dc commit 7415444

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

entrypoint.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def _get_publish_date(self, published_at: str = None) -> str:
112112
return published_at
113113
return datetime.now(ZoneInfo("UTC")).strftime("%Y-%m-%dT%H:%M:%SZ")
114114

115-
def build_post_data(self) -> Dict[str, Any]:
115+
def build_post_data(self, post_id: str = None) -> Dict[str, Any]:
116116
"""Build the post data for the Hashnode API."""
117117
self._update_image_urls()
118118

119-
return {
119+
post_data = {
120120
"title": self.metadata["title"],
121121
"subtitle": self.metadata.get("subtitle"),
122122
"publicationId": self.publication_id,
@@ -135,6 +135,11 @@ def build_post_data(self) -> Dict[str, Any]:
135135
},
136136
}
137137

138+
if post_id:
139+
post_data["id"] = post_id
140+
141+
return post_data
142+
138143
def _update_image_urls(self) -> None:
139144
"""Update relative image URLs in the content to absolute URLs."""
140145
relative_image_regex = re.compile(r"!\[(.*?)\]\((?!http)(.*?)\)")
@@ -167,7 +172,6 @@ def handle_post(file_path: Path, api: HashnodeAPI) -> None:
167172
debug_data.append([datetime.now(ZoneInfo("UTC")).strftime("%Y-%m-%d %H:%M:%S:%f"), f"Handling file: {file_path}"])
168173

169174
markdown_file_handler = MarkdownFileHandler(file_path, api.publication_id)
170-
post_data = markdown_file_handler.build_post_data()
171175

172176
post_id = api.get_post_id(markdown_file_handler.metadata["slug"])
173177
debug_data.append(
@@ -177,6 +181,8 @@ def handle_post(file_path: Path, api: HashnodeAPI) -> None:
177181
]
178182
)
179183

184+
post_data = markdown_file_handler.build_post_data(post_id)
185+
180186
post_action = "update_post" if post_id else "create_post"
181187

182188
post = getattr(api, post_action)(post_data)

0 commit comments

Comments
 (0)