Skip to content

Commit

Permalink
try to fix prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Oct 4, 2024
1 parent 033c0fc commit 813a51e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-explorer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
19 changes: 15 additions & 4 deletions add_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from bs4 import BeautifulSoup
import sys

if len(sys.argv) != 2:
print("Usage: python add_versions.py <input_file>")
if len(sys.argv) != 3:
print("Usage: python add_versions.py <base> <input_file>")
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:
Expand All @@ -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()):
Expand Down Expand Up @@ -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]}.")
Expand Down
8 changes: 4 additions & 4 deletions build-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>'
for version in $BRICK_VERSIONS; do
Expand All @@ -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"

0 comments on commit 813a51e

Please sign in to comment.