9
# Registry used to decide which README.md should symlink to which generated file
10
symlink_dict = {}
11
12
+# Mapping of integration id → output file path (repo-relative), populated by write_to_file()
13
+id_to_path = {}
14
+
15
16
# -----------------------------
17
# FS utilities
38
39
def clean_and_write(md: str, path: Path):
40
"""
38
- Convert custom {% details %} markers to HTML <details> and write file.
41
+ Convert custom markers to HTML/plain text for GitHub-rendered .md files.
42
+ relatedResource tags are left as-is here; they are resolved in a post-pass
43
+ once id_to_path is fully populated.
44
"""
45
md = re.sub(r'\{% details open=true summary="(.*?)" %\}', r'<details open><summary>\1</summary>\n', md)
46
md = re.sub(r'\{% details summary="(.*?)" %\}', r'<details><summary>\1</summary>\n', md)
48
path.write_text(md, encoding="utf-8")
49
50
51
+def resolve_related_links():
52
+ """
53
+ Post-process all written files: convert relatedResource tags to markdown links.
54
+ Must be called after all files are written and id_to_path is fully populated.
55
+ """
56
+ for fpath in id_to_path.values():
57
+ p = Path(fpath)
58
+ if not p.exists():
59
+ continue
60
+ md = p.read_text(encoding="utf-8")
61
+ if '{% relatedResource' not in md:
62
+ continue
63
+
64
+ def _resolve(m):
65
+ rid = m.group(1)
66
+ name = m.group(2)
67
+ target = id_to_path.get(rid)
68
+ if target:
69
+ return f'[{name}](/{target})'
70
+ return name
71
+
72
+ md = re.sub(r'\{% relatedResource id="([^"]*)" %\}(.*?)\{% /relatedResource %\}', _resolve, md)
73
+ p.write_text(md, encoding="utf-8")
74
+
75
+
76
def build_path(meta_yaml_link: str) -> str:
77
"""
78
Convert GitHub edit link to local repo path (without trailing /metadata.yaml).
375
376
377
def write_to_file(path: str, md: str, meta_yaml: str, sidebar_label: str, community: str, integration=None,
348
- mode: str = "default"):
378
+ mode: str = "default", integration_id: str = None):
379
"""
380
Write the generated markdown into an `integrations/` subdirectory located alongside the `metadata.yaml` file.
381
This mirrors the original behavior of placing docs next to their source metadata.
382
+ Also registers the actual output path in id_to_path for later link resolution.
383
"""
384
md = create_overview_banner(md, community)
385
393
md2 = add_custom_edit_url(md, meta_yaml, sidebar_label)
394
outfile = integrations_dir / f"{clean_string(sidebar_label)}.md"
395
clean_and_write(md2, outfile)
396
+ if integration_id:
397
+ id_to_path[integration_id] = str(outfile)
398
except FileNotFoundError as e:
399
print("Exception in writing to file", e)
400
416
finalpath = integrations_dir / f"{name}.md"
417
try:
418
clean_and_write(md2, finalpath)
419
+ if integration_id:
420
+ id_to_path[integration_id] = str(finalpath)
421
except FileNotFoundError as e:
422
print("Exception in writing to file", e)
423
426
finalpath = Path(path) / "README.md"
427
try:
428
clean_and_write(md2, finalpath)
429
+ if integration_id:
430
+ id_to_path[integration_id] = str(finalpath)
431
except FileNotFoundError as e:
432
print("Exception in writing to file", e)
433
440
finalpath = integrations_dir / f"{name}.md"
441
try:
442
clean_and_write(md2, finalpath)
443
+ if integration_id:
444
+ id_to_path[integration_id] = str(finalpath)
445
except FileNotFoundError as e:
446
print("Exception in writing to file", e)
447
454
finalpath = integrations_dir / f"{name}.md"
455
try:
456
clean_and_write(md2, finalpath)
457
+ if integration_id:
458
+ id_to_path[integration_id] = str(finalpath)
459
except FileNotFoundError as e:
460
print("Exception in writing to file", e)
461
532
# full cleanup (legacy behavior)
533
cleanup()
534
494
- # Generate
535
+ # Generate (pass 1: write all files, record id → actual output path)
536
for integration in integrations:
537
itype = integration.get("integration_type")
538
+ iid = integration.get("id")
539
540
# If -c is used, process ONLY the matching collector; skip everything else
541
if args.collector:
552
integration, categories, mode="collector"
553
)
554
path = build_path(meta_yaml)
513
- write_to_file(path, md, meta_yaml, sidebar_label, community)
555
+ write_to_file(path, md, meta_yaml, sidebar_label, community, integration_id=iid)
556
557
elif itype == "exporter" and not args.collector:
558
meta_yaml, sidebar_label, learn_rel_path, md, community = build_readme_from_integration(
559
integration, categories, mode="exporter"
560
)
561
path = build_path(meta_yaml)
520
- write_to_file(path, md, meta_yaml, sidebar_label, community)
562
+ write_to_file(path, md, meta_yaml, sidebar_label, community, integration_id=iid)
563
564
elif itype == "agent_notification" and not args.collector:
565
meta_yaml, sidebar_label, learn_rel_path, md, community = build_readme_from_integration(
567
)
568
path = build_path(meta_yaml)
569
write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration,
528
- mode="agent-notification")
570
+ mode="agent-notification", integration_id=iid)
571
572
elif itype == "cloud_notification" and not args.collector:
573
meta_yaml, sidebar_label, learn_rel_path, md, community = build_readme_from_integration(
575
)
576
path = build_path(meta_yaml)
577
write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration,
536
- mode="cloud-notification")
578
+ mode="cloud-notification", integration_id=iid)
579
580
elif itype == "logs" and not args.collector:
581
meta_yaml, sidebar_label, learn_rel_path, md, community = build_readme_from_integration(
582
integration, categories, mode="logs"
583
)
584
path = build_path(meta_yaml)
543
- write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration, mode="logs")
585
+ write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration,
586
+ mode="logs", integration_id=iid)
587
588
elif itype == "authentication" and not args.collector:
589
meta_yaml, sidebar_label, learn_rel_path, md, community = build_readme_from_integration(
590
integration, categories, mode="authentication"
591
)
592
path = build_path(meta_yaml)
550
- write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration, mode="authentication")
593
+ write_to_file(path, md, meta_yaml, sidebar_label, community, integration=integration,
594
+ mode="authentication", integration_id=iid)
595
+
596
+ # Pass 2: resolve relatedResource tags to markdown links now that all paths are known
597
+ resolve_related_links()
598
599
make_symlinks(symlink_dict)
600