GitHub Action commited on
Commit ·
1595318
1
Parent(s): 15e2717
Sync from GitHub with Git LFS
Browse files
scripts/publish_to_hashnode.py
CHANGED
|
@@ -56,17 +56,17 @@ def create_post(title, slug, markdown_content):
|
|
| 56 |
"slug": slug, "publicationId": HASHNODE_PUBLICATION_ID}}
|
| 57 |
return graphql_request(query, variables)["data"]["createDraft"]["draft"]
|
| 58 |
|
| 59 |
-
def update_post(
|
| 60 |
query = """
|
| 61 |
-
mutation UpdateDraft($
|
| 62 |
-
updateDraft(
|
| 63 |
-
draft { slug title
|
| 64 |
}
|
| 65 |
}
|
| 66 |
"""
|
| 67 |
variables = {
|
| 68 |
-
"slug": slug,
|
| 69 |
"input": {
|
|
|
|
| 70 |
"title": title,
|
| 71 |
"contentMarkdown": markdown_content
|
| 72 |
}
|
|
@@ -102,7 +102,7 @@ def main(force=False):
|
|
| 102 |
|
| 103 |
try:
|
| 104 |
if name in published and "id" in published[name]:
|
| 105 |
-
|
| 106 |
print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
|
| 107 |
else:
|
| 108 |
draft = create_post(title, slug, md_text)
|
|
|
|
| 56 |
"slug": slug, "publicationId": HASHNODE_PUBLICATION_ID}}
|
| 57 |
return graphql_request(query, variables)["data"]["createDraft"]["draft"]
|
| 58 |
|
| 59 |
+
def update_post(draft_id, title, markdown_content):
|
| 60 |
query = """
|
| 61 |
+
mutation UpdateDraft($input: UpdateDraftInput!) {
|
| 62 |
+
updateDraft(input: $input) {
|
| 63 |
+
draft { id slug title }
|
| 64 |
}
|
| 65 |
}
|
| 66 |
"""
|
| 67 |
variables = {
|
|
|
|
| 68 |
"input": {
|
| 69 |
+
"draftId": draft_id,
|
| 70 |
"title": title,
|
| 71 |
"contentMarkdown": markdown_content
|
| 72 |
}
|
|
|
|
| 102 |
|
| 103 |
try:
|
| 104 |
if name in published and "id" in published[name]:
|
| 105 |
+
update_post(published[name]["id"], title, md_text)
|
| 106 |
print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
|
| 107 |
else:
|
| 108 |
draft = create_post(title, slug, md_text)
|