GitHub Action commited on
Commit ·
7cabfe5
1
Parent(s): f8e26e4
Sync from GitHub with Git LFS
Browse files
scripts/publish_to_hashnode.py
CHANGED
|
@@ -91,11 +91,12 @@ def create_post(title, slug, markdown_content):
|
|
| 91 |
return graphql_request(query, variables)["data"]["createDraft"]["draft"]
|
| 92 |
|
| 93 |
|
| 94 |
-
def update_post(
|
| 95 |
query = """
|
| 96 |
-
mutation UpdateDraft($
|
| 97 |
-
updateDraft(
|
| 98 |
draft {
|
|
|
|
| 99 |
slug
|
| 100 |
title
|
| 101 |
}
|
|
@@ -103,7 +104,7 @@ def update_post(slug, title, markdown_content):
|
|
| 103 |
}
|
| 104 |
"""
|
| 105 |
variables = {
|
| 106 |
-
"
|
| 107 |
"input": {
|
| 108 |
"title": title,
|
| 109 |
"contentMarkdown": markdown_content,
|
|
@@ -161,15 +162,16 @@ def main(force=False):
|
|
| 161 |
continue
|
| 162 |
|
| 163 |
try:
|
| 164 |
-
if title in published and "
|
| 165 |
-
|
| 166 |
-
post = update_post(
|
| 167 |
print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
|
| 168 |
else:
|
| 169 |
post = create_post(title, slug, md_text)
|
| 170 |
post = publish_draft(post["id"])
|
| 171 |
print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
|
| 172 |
|
|
|
|
| 173 |
published[title] = {"id": post["id"], "slug": post["slug"], "hash": h}
|
| 174 |
save_published(published)
|
| 175 |
|
|
|
|
| 91 |
return graphql_request(query, variables)["data"]["createDraft"]["draft"]
|
| 92 |
|
| 93 |
|
| 94 |
+
def update_post(draft_id, title, markdown_content):
|
| 95 |
query = """
|
| 96 |
+
mutation UpdateDraft($id: ID!, $input: UpdateDraftInput!) {
|
| 97 |
+
updateDraft(id: $id, input: $input) {
|
| 98 |
draft {
|
| 99 |
+
id
|
| 100 |
slug
|
| 101 |
title
|
| 102 |
}
|
|
|
|
| 104 |
}
|
| 105 |
"""
|
| 106 |
variables = {
|
| 107 |
+
"id": draft_id,
|
| 108 |
"input": {
|
| 109 |
"title": title,
|
| 110 |
"contentMarkdown": markdown_content,
|
|
|
|
| 162 |
continue
|
| 163 |
|
| 164 |
try:
|
| 165 |
+
if title in published and "id" in published[title]:
|
| 166 |
+
draft_id = published[title]["id"]
|
| 167 |
+
post = update_post(draft_id, title, md_text)
|
| 168 |
print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
|
| 169 |
else:
|
| 170 |
post = create_post(title, slug, md_text)
|
| 171 |
post = publish_draft(post["id"])
|
| 172 |
print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
|
| 173 |
|
| 174 |
+
|
| 175 |
published[title] = {"id": post["id"], "slug": post["slug"], "hash": h}
|
| 176 |
save_published(published)
|
| 177 |
|