Skip to content

Commit

Permalink
Merge pull request #3622 from coloraven/main
Browse files Browse the repository at this point in the history
replace necessary strings before zip offline package #3605
  • Loading branch information
szarnyasg authored Sep 12, 2024
2 parents 3fcb294 + 489b13d commit 3b4bf17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/jekyll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
# create a copy of the _site directory for the offline package
cp -r _site duckdb-docs
echo "To browse the DuckDB website locally, run \`python -m http.server\` in this directory and connect to http://localhost:8000/" > duckdb-docs/README.md
# replace the necessary strings to ensure everything works properly after offline deployment.
python scripts/offline_docs_replace.py
# cleanup some directories, including the old (archive) pages
rm -rf scripts single-file-document duckdb-docs/docs/archive
# create archive
Expand Down
37 changes: 37 additions & 0 deletions scripts/offline_docs_replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import re


# Modify the content of a file: replace "https://duckdb.org" in all files,
# and if it's an HTML file, also perform HTML-specific replacements
def modify_file(file_path):
try:
# Read the file content
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()

# Replace "https://duckdb.org" with `"` in all files
content_updated = content.replace('"https://duckdb.org', '"')

# If the file is an HTML file, perform additional replacements
if file_path.endswith(".html"):
content_updated = re.sub(
r'href="(/docs[^"]*(?<!/)(?<!\.html))"', r'href="\1.html"', content_updated
)

# Write back only if changes were made
if content != content_updated:
with open(file_path, "w", encoding="utf-8") as file:
file.write(content_updated)

except (UnicodeDecodeError, IOError):
# Skip binary files or files that cannot be read properly
pass


if __name__ == "__main__":
root_directory = r"./duckdb-docs" # Define duckdb-docs directory
for subdir, dirs, files in os.walk(root_directory):
for file in files:
file_path = os.path.join(subdir, file)
modify_file(file_path)

0 comments on commit 3b4bf17

Please sign in to comment.