GitHub Action commited on
Commit
f8e26e4
·
1 Parent(s): a6585a8

Sync from GitHub with Git LFS

Browse files
Files changed (1) hide show
  1. scripts/publish_to_hashnode.py +8 -10
scripts/publish_to_hashnode.py CHANGED
@@ -91,12 +91,11 @@ def create_post(title, slug, markdown_content):
91
  return graphql_request(query, variables)["data"]["createDraft"]["draft"]
92
 
93
 
94
- def update_post(post_id, title, slug, 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,12 +103,11 @@ def update_post(post_id, title, slug, markdown_content):
104
  }
105
  """
106
  variables = {
107
- "id": post_id,
108
  "input": {
109
  "title": title,
110
  "contentMarkdown": markdown_content,
111
- "slug": slug,
112
- "tags": [{"name": tag} for tag in HMP_TAGS] # <-- теги при обновлении
113
  }
114
  }
115
  return graphql_request(query, variables)["data"]["updateDraft"]["draft"]
@@ -163,9 +161,9 @@ def main(force=False):
163
  continue
164
 
165
  try:
166
- if title in published and "id" in published[title]:
167
- post_id = published[title]["id"]
168
- post = update_post(post_id, title, slug, md_text)
169
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
170
  else:
171
  post = create_post(title, slug, md_text)
 
91
  return graphql_request(query, variables)["data"]["createDraft"]["draft"]
92
 
93
 
94
+ def update_post(slug, title, markdown_content):
95
  query = """
96
+ mutation UpdateDraft($slug: String!, $input: UpdateDraftInput!) {
97
+ updateDraft(slug: $slug, input: $input) {
98
  draft {
 
99
  slug
100
  title
101
  }
 
103
  }
104
  """
105
  variables = {
106
+ "slug": slug,
107
  "input": {
108
  "title": title,
109
  "contentMarkdown": markdown_content,
110
+ "tags": [{"name": tag} for tag in HMP_TAGS]
 
111
  }
112
  }
113
  return graphql_request(query, variables)["data"]["updateDraft"]["draft"]
 
161
  continue
162
 
163
  try:
164
+ if title in published and "slug" in published[title]:
165
+ post_id = published[title]["slug"]
166
+ post = update_post(slug, title, md_text)
167
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
168
  else:
169
  post = create_post(title, slug, md_text)