GitHub Action commited on
Commit
a5ffa73
·
1 Parent(s): 13f52e0

Sync from GitHub with Git LFS

Browse files
Files changed (1) hide show
  1. scripts/AI_friendly.py +18 -4
scripts/AI_friendly.py CHANGED
@@ -125,8 +125,8 @@ def generate_json_ld(content, front_matter, ftype, title, rel_path):
125
  def mirror_md_files():
126
  processed = []
127
  for path in REPO_ROOT.rglob("*.md"):
128
- # пропускаем всё внутри structured_md
129
- if "structured_md" in path.parts:
130
  continue
131
 
132
  rel_path = path.relative_to(REPO_ROOT)
@@ -136,14 +136,28 @@ def mirror_md_files():
136
  with path.open("r", encoding="utf-8") as f:
137
  content = f.read()
138
 
 
139
  front_matter, clean_content = extract_front_matter(content)
140
  ftype = detect_file_type(clean_content, front_matter)
141
  title = front_matter.get("title", path.stem)
142
-
 
 
 
 
 
 
 
 
 
 
 
 
143
  json_ld = generate_json_ld(clean_content, front_matter, ftype, title, rel_path)
144
 
 
145
  with target_path.open("w", encoding="utf-8") as f:
146
- # сначала оригинальный контент (без YAML-шапки), затем JSON-LD
147
  f.write(clean_content.rstrip())
148
  f.write("\n\n")
149
  f.write(json_ld)
 
125
  def mirror_md_files():
126
  processed = []
127
  for path in REPO_ROOT.rglob("*.md"):
128
+ # пропускаем всё внутри structured_md и index.md
129
+ if "structured_md" in path.parts or path.name.lower() == "index.md":
130
  continue
131
 
132
  rel_path = path.relative_to(REPO_ROOT)
 
136
  with path.open("r", encoding="utf-8") as f:
137
  content = f.read()
138
 
139
+ # извлекаем существующий фронт-маттер
140
  front_matter, clean_content = extract_front_matter(content)
141
  ftype = detect_file_type(clean_content, front_matter)
142
  title = front_matter.get("title", path.stem)
143
+ description = front_matter.get("description", clean_content[:100].replace("\n", " ") + "...")
144
+ tags = front_matter.get("tags", [])
145
+
146
+ # формируем YAML фронт-маттер для structured_md
147
+ fm_dict = {
148
+ "title": title,
149
+ "description": description,
150
+ "type": ftype,
151
+ "tags": tags,
152
+ }
153
+ yaml_fm = "---\n" + yaml.safe_dump(fm_dict, sort_keys=False, allow_unicode=True) + "---\n\n"
154
+
155
+ # формируем JSON-LD
156
  json_ld = generate_json_ld(clean_content, front_matter, ftype, title, rel_path)
157
 
158
+ # пишем новый Markdown с фронт-маттер + оригинальный текст + JSON-LD
159
  with target_path.open("w", encoding="utf-8") as f:
160
+ f.write(yaml_fm)
161
  f.write(clean_content.rstrip())
162
  f.write("\n\n")
163
  f.write(json_ld)