From 813a51ea5e7ef2cade3989ce1a6eee58a916c8e9 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Fri, 4 Oct 2024 12:15:56 -0600 Subject: [PATCH] try to fix prefix --- .github/workflows/build-explorer.yml | 2 +- add_versions.py | 19 +++++++++++++++---- build-site.sh | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-explorer.yml b/.github/workflows/build-explorer.yml index 3691b11..76adaa8 100644 --- a/.github/workflows/build-explorer.yml +++ b/.github/workflows/build-explorer.yml @@ -78,7 +78,7 @@ jobs: npx rdf make site --output public/1.4 -B 1.3 - name: rewrite for version navigation - run: find rdf-toolkit/explorer/public -name "*.html" | xargs -n 1 -P 4 uv run add_versions.py + run: find rdf-toolkit/explorer/public -name "*.html" | xargs -n 1 -P 4 uv run add_versions.py `pwd`/rdf-toolkit/explorer/public - name: Commit Built Files run: | diff --git a/add_versions.py b/add_versions.py index c540010..dc5c2eb 100644 --- a/add_versions.py +++ b/add_versions.py @@ -7,12 +7,13 @@ from bs4 import BeautifulSoup import sys -if len(sys.argv) != 2: - print("Usage: python add_versions.py ") +if len(sys.argv) != 3: + print("Usage: python add_versions.py ") sys.exit(1) # Define the file name of the existing HTML file -input_file = sys.argv[1] +base_dir = sys.argv[1] +input_file = sys.argv[2] # Read the contents of the existing HTML file with open(input_file, 'r', encoding='utf-8') as file: @@ -28,6 +29,16 @@ "Brick v1.3": "/1.3", } +# if the input file starts with any value from the links dict, then +# rewrite ALL data-href attributes to start with the corresponding value +print(f"Check INPUT_FILE: {input_file.removeprefix(base_dir)}") +input_file_end = input_file.removeprefix(base_dir) +for text, href in links.items(): + if input_file_end.startswith(href) and href != "/": + print(f"Rewriting all data-href attributes to start with {href}") + for a in soup.find_all('a', {'data-href': True}): + a['data-href'] = href + a['data-href'] + select = soup.new_tag('select', {'id': 'brickVersionDropdown'}) # create options for index,(text, href) in enumerate(links.items()): @@ -74,7 +85,7 @@ search_container.append(select_div) # Write the modified content back to a new file or overwrite the existing one - with open(sys.argv[1], 'w', encoding='utf-8') as file: + with open(sys.argv[2], 'w', encoding='utf-8') as file: file.write(str(soup)) print(f"Dropdown menu added successfully to {sys.argv[1]}.") diff --git a/build-site.sh b/build-site.sh index 3032a4e..6a0d69d 100755 --- a/build-site.sh +++ b/build-site.sh @@ -47,7 +47,7 @@ npx rdf add file "http://qudt.org/2.1/vocab/quantitykind" $CURRENT_DIR/ontologie npx rdf add file "http://www.w3.org/ns/shacl" $CURRENT_DIR/ontologies/shacl.ttl npx rdf add file "https://brickschema.org/schema/Brick/ref" $CURRENT_DIR/ontologies/ref-schema.ttl npx rdf add file "https://w3id.org/rec" $CURRENT_DIR/ontologies/rec.ttl -npx rdf make site --output "$DEST/$version" --project "$TEMP_DIR/explorer" +npx rdf make site --output "$DEST/$version" --project "$TEMP_DIR/explorer" --base '' # loop through and build the site for each version by calling './b2.sh ' for version in $BRICK_VERSIONS; do @@ -60,9 +60,9 @@ for version in $BRICK_VERSIONS; do wget -O $CURRENT_DIR/ontologies/brick/$version/Brick.ttl https://brickschema.org/schema/$version/Brick.ttl #./b2.sh $version cd "$TEMP_DIR/explorer" - npx rdf add file "https://brickschema.org/schema/$version/Brick" $CURRENT_DIR/ontologies/brick/$version/Brick.ttl - npx rdf make site --output "$DEST/$version" --project "$TEMP_DIR/explorer" + npx rdf add file "https://brickschema.org/schema/$version/Brick" $CURRENT_DIR/ontologies/brick/$version/Brick.ttl + npx rdf make site --output "$DEST/$version" --project "$TEMP_DIR/explorer" --base $version done # Run add_versions.py on all .html files in the site directory -find "$DEST" -name "*.html" | xargs -n 1 -P 8 uv run "$CURRENT_DIR/add_versions.py" +find "$DEST" -name "*.html" | xargs -n 1 -P 8 uv run "$CURRENT_DIR/add_versions.py" "$DEST"