1111@author: Michiel Lachaert (Ghent University)
1212@author: Lara Peeters (Ghent University)
1313"""
14+ import copy
1415import json
1516import os
1617import re
1718import subprocess
1819import sys
1920import time
21+ import yaml
2022from typing import Union , Tuple
23+ from string import Template
2124import numpy as np
2225from mdutils .mdutils import MdUtils
2326from natsort import natsorted
@@ -339,6 +342,41 @@ def generate_software_table_data(software_data: dict, targets: list) -> list:
339342 return table_data
340343
341344
345+ # LD+JSON Template with placeholders
346+ ldjson_template = Template ("""
347+ {
348+ "json_ld": {
349+ "@context": "https://schema.org",
350+ "@type": "SoftwareApplication",
351+ "name": "$name",
352+ "url": "$homepage",
353+ "softwareVersion": "$version",
354+ "description": "$description",
355+ "operatingSystem": "LINUX",
356+ "applicationCategory": "DeveloperApplication",
357+ "softwareRequirements": "See https://www.eessi.io/docs/ for how to make EESSI available on your system",
358+ "license": "Not confirmed",
359+ "review": {
360+ "@type": "Review",
361+ "reviewRating": {
362+ "@type": "Rating",
363+ "ratingValue": 5
364+ },
365+ "author": {
366+ "@type": "Organization",
367+ "name": "EESSI"
368+ },
369+ "reviewBody": "Application has been successfully made available on all architectures supported by EESSI"
370+ },
371+ "offers": {
372+ "@type": "Offer",
373+ "price": 0
374+ }
375+ }
376+ }
377+ """ )
378+
379+
342380def generate_software_detail_page (
343381 software_name : str ,
344382 software_data : dict ,
@@ -357,15 +395,20 @@ def generate_software_detail_page(
357395 """
358396 sorted_versions = dict_sort (software_data ["versions" ])
359397 newest_version = list (sorted_versions .keys ())[- 1 ]
398+ ldjson_software_data = copy .deepcopy (software_data )
360399
361400 filename = f"{ path } /{ software_name } .md"
362401 md_file = MdUtils (file_name = filename , title = f"{ software_name } " )
363402 if 'description' in software_data .keys ():
364403 description = software_data ['description' ]
365404 md_file .new_paragraph (f"{ description } " )
405+ else :
406+ ldjson_software_data ['description' ] = ''
366407 if 'homepage' in software_data .keys ():
367408 homepage = software_data ['homepage' ]
368409 md_file .new_paragraph (f"{ homepage } " )
410+ else :
411+ ldjson_software_data ["homepage" ] = ''
369412
370413 md_file .new_header (level = 1 , title = "Available modules" )
371414
@@ -392,11 +435,21 @@ def generate_software_detail_page(
392435
393436 md_file .create_md_file ()
394437
395- # Remove the TOC
396438 with open (filename ) as f :
397439 read_data = f .read ()
398440 with open (filename , 'w' ) as f :
399- f .write ("---\n hide:\n - toc\n ---\n " + read_data )
441+ # Add the software name
442+ ldjson_software_data ['name' ] = software_name
443+ # Just output the supported versions (with toolchains)
444+ ldjson_software_data ["version" ] = list (sorted_versions .keys ())
445+ # Make the description safe for json (and remove surrounding quotes)
446+ ldjson_software_data ['description' ] = json .dumps (ldjson_software_data ['description' ])[1 :- 1 ]
447+ json_str = ldjson_template .substitute (ldjson_software_data ) # Replace placeholders
448+ json_topmatter = json .loads (json_str )
449+ # Remove the TOC
450+ json_topmatter ["hide" ] = ["toc" ]
451+ yaml_topmatter = yaml .dump (json_topmatter )
452+ f .write ("---\n " + yaml_topmatter + "---\n " + read_data )
400453
401454
402455def generate_detail_pages (json_path , dest_path ) -> None :
0 commit comments