GitHub Action commited on
Commit
2f8f693
·
1 Parent(s): 6892c13

Sync from GitHub with Git LFS

Browse files
Files changed (1) hide show
  1. scripts/publish_to_hashnode.py +12 -10
scripts/publish_to_hashnode.py CHANGED
@@ -146,20 +146,22 @@ def main(force=False):
146
  slug = re.sub(r'-+', '-', slug).strip('-')
147
  slug = slug[:250]
148
 
149
- h = file_hash(md_file)
150
-
151
- if not force and name in published and published[name]["hash"] == h:
152
- print(f"✅ Пост '{name}' без изменений — пропускаем.")
153
- continue
154
-
155
  md_text = md_file.read_text(encoding="utf-8")
156
  source_link = f"Источник: [ {md_file.name} ](https://github.com/kagvi13/HMP/blob/main/docs/{md_file.name})\n\n"
157
  md_text = source_link + md_text
158
  md_text = convert_md_links(md_text)
159
 
 
 
 
 
 
 
 
 
160
  try:
161
- if name in published and "id" in published[name]:
162
- post_id = published[name]["id"]
163
  post = update_post(post_id, title, slug, md_text)
164
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
165
  else:
@@ -167,14 +169,14 @@ def main(force=False):
167
  post = publish_draft(post["id"])
168
  print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
169
 
170
- published[name] = {"id": post["id"], "slug": post["slug"], "hash": h}
171
  save_published(published)
172
 
173
  print("⏱ Пауза 30 секунд перед следующим постом...")
174
  time.sleep(30)
175
 
176
  except Exception as e:
177
- print(f"❌ Ошибка при публикации {name}: {e}")
178
  save_published(published)
179
  break
180
 
 
146
  slug = re.sub(r'-+', '-', slug).strip('-')
147
  slug = slug[:250]
148
 
 
 
 
 
 
 
149
  md_text = md_file.read_text(encoding="utf-8")
150
  source_link = f"Источник: [ {md_file.name} ](https://github.com/kagvi13/HMP/blob/main/docs/{md_file.name})\n\n"
151
  md_text = source_link + md_text
152
  md_text = convert_md_links(md_text)
153
 
154
+ # Хэш после добавления источника
155
+ h = hashlib.md5(md_text.encode("utf-8")).hexdigest()
156
+
157
+ # Проверка публикации по title
158
+ if not force and title in published and published[title]["hash"] == h:
159
+ print(f"✅ Пост '{title}' без изменений — пропускаем.")
160
+ continue
161
+
162
  try:
163
+ if title in published and "id" in published[title]:
164
+ post_id = published[title]["id"]
165
  post = update_post(post_id, title, slug, md_text)
166
  print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
167
  else:
 
169
  post = publish_draft(post["id"])
170
  print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
171
 
172
+ published[title] = {"id": post["id"], "slug": post["slug"], "hash": h}
173
  save_published(published)
174
 
175
  print("⏱ Пауза 30 секунд перед следующим постом...")
176
  time.sleep(30)
177
 
178
  except Exception as e:
179
+ print(f"❌ Ошибка при публикации {title}: {e}")
180
  save_published(published)
181
  break
182