GitHub Action commited on
Commit ·
4ba78be
1
Parent(s): 811fb95
Sync from GitHub with Git LFS
Browse files- scripts/AI_friendly.py +14 -16
scripts/AI_friendly.py
CHANGED
|
@@ -95,30 +95,28 @@ def generate_json_ld(content, front_matter, ftype, title, rel_path):
|
|
| 95 |
).replace("}}", f',\n "url": "{url}"\n}}', 1)
|
| 96 |
|
| 97 |
def mirror_md_files():
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
if
|
| 101 |
continue
|
| 102 |
|
| 103 |
-
rel_path =
|
| 104 |
-
target_path =
|
| 105 |
-
|
| 106 |
target_path.parent.mkdir(parents=True, exist_ok=True)
|
| 107 |
|
| 108 |
-
with open(
|
| 109 |
content = f.read()
|
| 110 |
|
| 111 |
-
front_matter =
|
| 112 |
-
ftype =
|
| 113 |
-
title = front_matter.get("title",
|
| 114 |
-
|
| 115 |
-
json_ld = generate_json_ld(content, front_matter, ftype, title)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
f.write(json_ld + content)
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
def generate_index(files):
|
| 124 |
index_lines = ["# ИИ-дружелюбные версии файлов\n"]
|
|
|
|
| 95 |
).replace("}}", f',\n "url": "{url}"\n}}', 1)
|
| 96 |
|
| 97 |
def mirror_md_files():
|
| 98 |
+
for path in REPO_ROOT.rglob("*.md"):
|
| 99 |
+
# пропускаем structured_md и index.md
|
| 100 |
+
if "structured_md" in path.parts or path.name.lower() == "index.md":
|
| 101 |
continue
|
| 102 |
|
| 103 |
+
rel_path = path.relative_to(REPO_ROOT)
|
| 104 |
+
target_path = STRUCTURED_MD / rel_path
|
|
|
|
| 105 |
target_path.parent.mkdir(parents=True, exist_ok=True)
|
| 106 |
|
| 107 |
+
with path.open("r", encoding="utf-8") as f:
|
| 108 |
content = f.read()
|
| 109 |
|
| 110 |
+
front_matter, clean_content = extract_front_matter(content)
|
| 111 |
+
ftype = detect_file_type(clean_content)
|
| 112 |
+
title = front_matter.get("title", path.stem)
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
json_ld = generate_json_ld(clean_content, front_matter, ftype, title, rel_path)
|
|
|
|
| 115 |
|
| 116 |
+
with target_path.open("w", encoding="utf-8") as f:
|
| 117 |
+
f.write(clean_content)
|
| 118 |
+
f.write("\n\n")
|
| 119 |
+
f.write(json_ld)
|
| 120 |
|
| 121 |
def generate_index(files):
|
| 122 |
index_lines = ["# ИИ-дружелюбные версии файлов\n"]
|