GitHub Action commited on
Commit
e2c8dd5
·
1 Parent(s): 53a88a8

Sync from GitHub with Git LFS

Browse files
Files changed (1) hide show
  1. scripts/publish_to_hashnode.py +17 -0
scripts/publish_to_hashnode.py CHANGED
@@ -112,6 +112,22 @@ def update_post(post_id, title, slug, markdown_content):
112
  return graphql_request(query, variables)["data"]["updateDraft"]["draft"]
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  def main(force=False):
116
  published = load_published()
117
  md_files = list(Path("docs").rglob("*.md"))
@@ -139,6 +155,7 @@ def main(force=False):
139
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
140
  else:
141
  post = create_post(name, slug, md_text)
 
142
  print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
143
 
144
  published[name] = {"id": post["id"], "slug": post["slug"], "hash": h}
 
112
  return graphql_request(query, variables)["data"]["updateDraft"]["draft"]
113
 
114
 
115
+ def publish_draft(draft_id):
116
+ query = """
117
+ mutation PublishDraft($id: ID!) {
118
+ publishDraft(id: $id) {
119
+ post {
120
+ id
121
+ slug
122
+ url
123
+ }
124
+ }
125
+ }
126
+ """
127
+ variables = {"id": draft_id}
128
+ return graphql_request(query, variables)["data"]["publishDraft"]["post"]
129
+
130
+
131
  def main(force=False):
132
  published = load_published()
133
  md_files = list(Path("docs").rglob("*.md"))
 
155
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
156
  else:
157
  post = create_post(name, slug, md_text)
158
+ post = publish_draft(post["id"])
159
  print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
160
 
161
  published[name] = {"id": post["id"], "slug": post["slug"], "hash": h}