GitHub Action
commited on
Commit
·
38cf376
1
Parent(s):
b4eee0c
Sync from GitHub with Git LFS
Browse files
scripts/publish_to_hashnode.py
CHANGED
|
@@ -134,14 +134,18 @@ def main(force=False):
|
|
| 134 |
|
| 135 |
for md_file in md_files:
|
| 136 |
name = md_file.stem
|
|
|
|
|
|
|
| 137 |
if len(name) < 6:
|
| 138 |
title = name + "-HMP"
|
| 139 |
else:
|
| 140 |
title = name
|
| 141 |
|
| 142 |
-
slug
|
|
|
|
| 143 |
slug = re.sub(r'-+', '-', slug).strip('-')
|
| 144 |
slug = slug[:250]
|
|
|
|
| 145 |
h = file_hash(md_file)
|
| 146 |
|
| 147 |
if not force and name in published and published[name]["hash"] == h:
|
|
@@ -156,10 +160,10 @@ def main(force=False):
|
|
| 156 |
try:
|
| 157 |
if name in published and "id" in published[name]:
|
| 158 |
post_id = published[name]["id"]
|
| 159 |
-
post = update_post(post_id,
|
| 160 |
print(f"♻ Обновлён пост: https://hashnode.com/@yourusername/{post['slug']}")
|
| 161 |
else:
|
| 162 |
-
post = create_post(
|
| 163 |
post = publish_draft(post["id"])
|
| 164 |
print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
|
| 165 |
|
|
|
|
| 134 |
|
| 135 |
for md_file in md_files:
|
| 136 |
name = md_file.stem
|
| 137 |
+
|
| 138 |
+
# Если короткое имя, добавляем суффикс
|
| 139 |
if len(name) < 6:
|
| 140 |
title = name + "-HMP"
|
| 141 |
else:
|
| 142 |
title = name
|
| 143 |
|
| 144 |
+
# slug формируем из title, чтобы Hashnode не ругался
|
| 145 |
+
slug = re.sub(r'[^a-z0-9-]', '-', title.lower())
|
| 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:
|
|
|
|
| 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:
|
| 166 |
+
post = create_post(title, slug, md_text)
|
| 167 |
post = publish_draft(post["id"])
|
| 168 |
print(f"🆕 Пост опубликован: https://hashnode.com/@yourusername/{post['slug']}")
|
| 169 |
|