@@ -33,28 +33,28 @@ def generate_cross_references():
3333 cross_references = {
3434 "weaknesses" : {},
3535 "tests" : {},
36- "mitigations " : {}
36+ "best-practices " : {}
3737 }
3838
3939 for test_id , test_meta in tests .items ():
4040 weakness_id = test_meta .get ("weakness" )
4141 test_path = test_meta .get ("path" )
4242 test_title = test_meta .get ("title" )
4343 test_platform = test_meta .get ("platform" )
44- mitigations_ids = test_meta .get ("mitigations " )
44+ best_practices_ids = test_meta .get ("best-practices " )
4545
4646 # Create cross-references for weaknesses listing all tests that reference each weakness ID
4747 if weakness_id :
4848 if weakness_id not in cross_references ["weaknesses" ]:
4949 cross_references ["weaknesses" ][weakness_id ] = []
5050 cross_references ["weaknesses" ][weakness_id ].append ({"id" : test_id , "path" : test_path , "title" : test_title , "platform" : test_platform })
5151
52- # Create cross-references for mitigations listing all tests that reference each mitigation ID
53- if mitigations_ids :
54- for mitigation_id in mitigations_ids :
55- if mitigation_id not in cross_references ["mitigations " ]:
56- cross_references ["mitigations " ][mitigation_id ] = []
57- cross_references ["mitigations " ][mitigation_id ].append ({"id" : test_id , "path" : test_path , "title" : test_title , "platform" : test_platform })
52+ # Create cross-references for best_practices listing all tests that reference each best_practice ID
53+ if best_practices_ids :
54+ for best_practice_id in best_practices_ids :
55+ if best_practice_id not in cross_references ["best-practices " ]:
56+ cross_references ["best-practices " ][best_practice_id ] = []
57+ cross_references ["best-practices " ][best_practice_id ].append ({"id" : test_id , "path" : test_path , "title" : test_title , "platform" : test_platform })
5858
5959 for demo_id , demo_meta in demos .items ():
6060 test_id = demo_meta .get ("test" )
@@ -108,6 +108,20 @@ def on_page_markdown(markdown, page, config, **kwargs):
108108 markdown += f"\n \n { tests_section } "
109109
110110 if "MASTG-TEST-" in path :
111+
112+ # Add best_practices section to tests as a bullet point list with IDs, links are resolved in a separate hook
113+ # ORIGIN: Test metadata
114+
115+ best_practices = meta .get ('best-practices' )
116+ if best_practices :
117+ best_practices_section = "## Mitigations\n \n "
118+ for best_practice_id in best_practices :
119+ best_practice_path = f"MASTG/best-practices/{ best_practice_id } .md"
120+ relPath = os .path .relpath (best_practice_path , os .path .dirname (path ))
121+ best_practices_section += f"- @{ best_practice_id } \n "
122+
123+ markdown += f"\n \n { best_practices_section } "
124+
111125 test_id = meta .get ('id' )
112126
113127 # Add Demos section to tests as buttons
@@ -123,35 +137,22 @@ def on_page_markdown(markdown, page, config, **kwargs):
123137 demos_section += f"[{ get_platform_icon (demo ['platform' ])} { demo ['id' ]} : { demo ['title' ]} ]({ relPath } ){{: .mas-demo-button}} "
124138
125139 markdown += f"\n \n { demos_section } "
126-
127- # Add Mitigations section to tests as a bullet point list with IDs, links are resolved in a separate hook
128- # ORIGIN: Test metadata
129-
130- mitigations = meta .get ('mitigations' )
131- if mitigations :
132- mitigations_section = "## Mitigations\n \n "
133- for mitigation_id in mitigations :
134- mitigation_path = f"MASTG/mitigations/{ mitigation_id } .md"
135- relPath = os .path .relpath (mitigation_path , os .path .dirname (path ))
136- mitigations_section += f"- @{ mitigation_id } \n "
137-
138- markdown += f"\n \n { mitigations_section } "
139140
140- if "MASTG-MITIG " in path :
141- mitig_id = meta .get ('id' )
141+ if "MASTG-BEST " in path :
142+ best_practice_id = meta .get ('id' )
142143
143- # Add Tests section to mitigations as buttons
144+ # Add Tests section to best_practices as buttons
144145 # ORIGIN: Cross-references from this script
145146
146- if mitig_id in cross_references ["mitigations " ]:
147- mitigations = cross_references ["mitigations " ].get (mitig_id )
148- meta ['mitigations ' ] = mitigations
149- if mitigations :
150- mitigations_section = "## Tests\n \n "
151- for mitigation in mitigations :
152- relPath = os .path .relpath (mitigation ['path' ], os .path .dirname (path ))
153- mitigations_section += f"[{ get_platform_icon (mitigation ['platform' ])} { mitigation ['id' ]} : { mitigation ['title' ]} ]({ relPath } ){{: .mas-test-button}} "
147+ if best_practice_id in cross_references ["best-practices " ]:
148+ best_practices = cross_references ["best-practices " ].get (best_practice_id )
149+ meta ['best-practices ' ] = best_practices
150+ if best_practices :
151+ best_practices_section = "## Tests\n \n "
152+ for best_practice in best_practices :
153+ relPath = os .path .relpath (best_practice ['path' ], os .path .dirname (path ))
154+ best_practices_section += f"[{ get_platform_icon (best_practice ['platform' ])} { best_practice ['id' ]} : { best_practice ['title' ]} ]({ relPath } ){{: .mas-test-button}} "
154155
155- markdown += f"\n \n { mitigations_section } "
156+ markdown += f"\n \n { best_practices_section } "
156157
157158 return markdown
0 commit comments