From 486a7bcaa07cf9912f8c567dfd19fab666f8bdbf Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 17:30:11 -0600 Subject: [PATCH 01/28] Update .gitignore to streamline ignored files and add GitHub Actions workflow for GitHub Pages preview deployment --- .github/workflows/github-pages-preview.yml | 159 +++++++++++++++++++++ .gitignore | 22 +-- 2 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/github-pages-preview.yml diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml new file mode 100644 index 0000000..3ad5c07 --- /dev/null +++ b/.github/workflows/github-pages-preview.yml @@ -0,0 +1,159 @@ +--- +name: GitHub Pages preview +on: + workflow_dispatch: + inputs: + branch: + description: "Branch to deploy" + type: string + required: false + default: "" + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: pages + cancel-in-progress: false + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout content repo + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch || github.ref }} + path: content + + - name: Clone adp-devsite + uses: actions/checkout@v4 + with: + repository: AdobeDocs/adp-devsite + path: adp-devsite + + - name: Clone devsite-runtime-connector + uses: actions/checkout@v4 + with: + repository: aemsites/devsite-runtime-connector + path: devsite-runtime-connector + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/jod" + + - name: Install dependencies + run: | + cd content && npm install && cd .. + cd adp-devsite && npm install && cd .. + cd devsite-runtime-connector && npm install + + - name: Start servers and generate static site + run: | + ROOT_DIR=$(pwd) + + # Start content server (port 3003) + (cd "$ROOT_DIR/content" && npm run dev) & + CONTENT_PID=$! + + # Start adp-devsite (port 3000) + (cd "$ROOT_DIR/adp-devsite" && npm run dev) & + DEVSITE_PID=$! + + # Start runtime connector + (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev) & + CONNECTOR_PID=$! + + # Wait for servers to be ready + echo "Waiting for servers to start..." + sleep 15 + + # Check if servers are running + for port in 3000 3003; do + for i in {1..30}; do + if curl -s "http://localhost:$port" > /dev/null 2>&1; then + echo "Server on port $port is ready" + break + fi + echo "Waiting for port $port... (attempt $i)" + sleep 2 + done + done + + # Generate list of all page URLs from markdown files + # Navigation is JS-driven, so we need to explicitly list all pages + cd "$ROOT_DIR/content" + find src/pages -name "*.md" | sed 's|src/pages/||' | sed 's|\.md$||' | sed 's|/index$|/|' | while read path; do + echo "http://localhost:3000/commerce/testing/$path" + done > "$ROOT_DIR/urls.txt" + + echo "Generated $(wc -l < "$ROOT_DIR/urls.txt") URLs to crawl" + cat "$ROOT_DIR/urls.txt" + + # Create output directory + mkdir -p "$ROOT_DIR/_site" + cd "$ROOT_DIR/_site" + + # Use wget to crawl and generate static site + # --execute robots=off is required because the dev server returns Disallow: / + wget \ + --input-file="$ROOT_DIR/urls.txt" \ + --page-requisites \ + --adjust-extension \ + --convert-links \ + --restrict-file-names=windows \ + --domains localhost \ + --execute robots=off \ + --wait=0.1 \ + --tries=3 \ + --timeout=30 \ + || true + + # Organize the output structure + if [ -d "localhost:3000" ]; then + # Move commerce/testing content to root + if [ -d "localhost:3000/commerce/testing" ]; then + cp -r localhost:3000/commerce/testing/* . 2>/dev/null || true + fi + # Move hlx_statics to root for asset paths + if [ -d "localhost:3000/hlx_statics" ]; then + mkdir -p hlx_statics + cp -r localhost:3000/hlx_statics/* hlx_statics/ 2>/dev/null || true + fi + rm -rf localhost:3000 + fi + + # Stop servers + kill $CONTENT_PID $DEVSITE_PID $CONNECTOR_PID 2>/dev/null || true + + echo "Static site generated successfully" + find . -type f | wc -l + echo "files generated" + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: _site + + deploy: + name: Deploy + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + diff --git a/.gitignore b/.gitignore index 2da8e90..d0d083c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,22 +5,8 @@ .idea .editorconfig -# npm yarn +# npm node_modules -package.lock -yarn-error.log -.pnp.* -.yarn/* - -# keep in repo -!.gitignore -!.yarn.lock -!.yarnrc.yml -!.yarn/patches -!.yarn/plugins -!.yarn/releases -!.yarn/sdks -!.yarn/versions # gatsby files .env @@ -34,7 +20,8 @@ cypress/screenshots # lerna lerna-debug.log -tmp +# static +_site # Super-linter outputs super-linter-output @@ -42,3 +29,6 @@ super-linter.log # GitHub Actions leftovers github_conf + +# local dev +tmp \ No newline at end of file From 6d2ffc70b8da7f9756d6ce412e60cfce79533b8c Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 17:50:47 -0600 Subject: [PATCH 02/28] Enhance GitHub Actions workflow for preview deployment by adding support for issue comments and dynamic branch handling. Implement notification on PR with deployment URL after successful deployment. --- .github/workflows/github-pages-preview.yml | 64 +++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 3ad5c07..1c59145 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -8,12 +8,23 @@ on: type: string required: false default: "" + issue_comment: + types: [created] + # For testing: runs on push to any branch containing 'preview' or 'gh-pages' + # Remove this trigger after testing is complete + push: + branches: + - "**/preview**" + - "**/gh-pages**" + - "preview-**" + - "gh-pages-**" # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write + pull-requests: write # Required to comment on PRs # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. @@ -25,11 +36,43 @@ jobs: build: name: Build runs-on: ubuntu-latest + # Run on workflow_dispatch, push, OR when someone comments "/deploy-preview" on a PR + if: > + github.event_name == 'workflow_dispatch' || + github.event_name == 'push' || + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '/deploy-preview')) steps: + - name: Get PR branch + id: pr-branch + if: github.event_name == 'issue_comment' + uses: actions/github-script@v7 + with: + script: | + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + core.setOutput('branch', pr.data.head.ref); + + - name: Add reaction to comment + if: github.event_name == 'issue_comment' + uses: actions/github-script@v7 + with: + script: | + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: 'rocket' + }); + - name: Checkout content repo uses: actions/checkout@v4 with: - ref: ${{ inputs.branch || github.ref }} + ref: ${{ steps.pr-branch.outputs.branch || inputs.branch || github.ref }} path: content - name: Clone adp-devsite @@ -152,8 +195,27 @@ jobs: url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build + outputs: + page_url: ${{ steps.deployment.outputs.page_url }} steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + notify: + name: Notify PR + runs-on: ubuntu-latest + needs: deploy + if: github.event_name == 'issue_comment' + steps: + - name: Comment on PR with deployment URL + uses: actions/github-script@v7 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `šŸš€ **Preview deployed!**\n\nšŸ“– View the preview: ${{ needs.deploy.outputs.page_url }}\n\n_This preview was generated from this PR's branch._` + }); + From ca473078ca1d64ce45c632a22e6dc9272a2f603d Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 17:59:02 -0600 Subject: [PATCH 03/28] Refactor GitHub Actions workflow for preview deployment by removing issue comment triggers and simplifying branch handling. Enhance output structure organization and add a redirect index.html for commerce/testing documentation. --- .github/workflows/github-pages-preview.yml | 84 ++++++---------------- 1 file changed, 21 insertions(+), 63 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 1c59145..625b512 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -8,8 +8,6 @@ on: type: string required: false default: "" - issue_comment: - types: [created] # For testing: runs on push to any branch containing 'preview' or 'gh-pages' # Remove this trigger after testing is complete push: @@ -24,7 +22,6 @@ permissions: contents: read pages: write id-token: write - pull-requests: write # Required to comment on PRs # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. @@ -36,43 +33,11 @@ jobs: build: name: Build runs-on: ubuntu-latest - # Run on workflow_dispatch, push, OR when someone comments "/deploy-preview" on a PR - if: > - github.event_name == 'workflow_dispatch' || - github.event_name == 'push' || - (github.event_name == 'issue_comment' && - github.event.issue.pull_request && - contains(github.event.comment.body, '/deploy-preview')) steps: - - name: Get PR branch - id: pr-branch - if: github.event_name == 'issue_comment' - uses: actions/github-script@v7 - with: - script: | - const pr = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number - }); - core.setOutput('branch', pr.data.head.ref); - - - name: Add reaction to comment - if: github.event_name == 'issue_comment' - uses: actions/github-script@v7 - with: - script: | - await github.rest.reactions.createForIssueComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: context.payload.comment.id, - content: 'rocket' - }); - - name: Checkout content repo uses: actions/checkout@v4 with: - ref: ${{ steps.pr-branch.outputs.branch || inputs.branch || github.ref }} + ref: ${{ inputs.branch || github.ref }} path: content - name: Clone adp-devsite @@ -159,18 +124,28 @@ jobs: --timeout=30 \ || true - # Organize the output structure + # Organize the output structure - preserve directory structure for relative links if [ -d "localhost:3000" ]; then - # Move commerce/testing content to root - if [ -d "localhost:3000/commerce/testing" ]; then - cp -r localhost:3000/commerce/testing/* . 2>/dev/null || true - fi - # Move hlx_statics to root for asset paths - if [ -d "localhost:3000/hlx_statics" ]; then - mkdir -p hlx_statics - cp -r localhost:3000/hlx_statics/* hlx_statics/ 2>/dev/null || true - fi + # Move everything up from localhost:3000 to _site root + # This keeps commerce/testing/ and hlx_statics/ at correct relative positions + mv localhost:3000/* . 2>/dev/null || true rm -rf localhost:3000 + + # Create a redirect index.html at root that points to commerce/testing/ + cat > index.html << 'EOF' + + + + + Redirecting... + + + + +

Redirecting to Commerce Testing documentation...

+ + + EOF fi # Stop servers @@ -202,20 +177,3 @@ jobs: id: deployment uses: actions/deploy-pages@v4 - notify: - name: Notify PR - runs-on: ubuntu-latest - needs: deploy - if: github.event_name == 'issue_comment' - steps: - - name: Comment on PR with deployment URL - uses: actions/github-script@v7 - with: - script: | - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body: `šŸš€ **Preview deployed!**\n\nšŸ“– View the preview: ${{ needs.deploy.outputs.page_url }}\n\n_This preview was generated from this PR's branch._` - }); - From 21248bef1fb6d721415cf16500c303e3cbff019a Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 18:10:47 -0600 Subject: [PATCH 04/28] Enhance GitHub Actions workflow for preview deployment by adding debug output, improving server readiness checks, and refining output organization. Implement logging for server processes and wget, along with fallback page creation for failed builds. --- .github/workflows/github-pages-preview.yml | 91 +++++++++++++++------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 625b512..b3e9277 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -65,26 +65,40 @@ jobs: - name: Start servers and generate static site run: | + set -x # Enable debug output ROOT_DIR=$(pwd) # Start content server (port 3003) - (cd "$ROOT_DIR/content" && npm run dev) & + echo "Starting content server..." + (cd "$ROOT_DIR/content" && npm run dev 2>&1 | tee "$ROOT_DIR/content-server.log") & CONTENT_PID=$! # Start adp-devsite (port 3000) - (cd "$ROOT_DIR/adp-devsite" && npm run dev) & + echo "Starting adp-devsite..." + (cd "$ROOT_DIR/adp-devsite" && npm run dev 2>&1 | tee "$ROOT_DIR/devsite-server.log") & DEVSITE_PID=$! # Start runtime connector - (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev) & + echo "Starting runtime connector..." + (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev 2>&1 | tee "$ROOT_DIR/connector-server.log") & CONNECTOR_PID=$! # Wait for servers to be ready echo "Waiting for servers to start..." - sleep 15 + sleep 20 + + # Debug: Show server logs + echo "=== Content server log ===" + cat "$ROOT_DIR/content-server.log" | tail -50 || true + echo "=== Devsite server log ===" + cat "$ROOT_DIR/devsite-server.log" | tail -50 || true + echo "=== Connector server log ===" + cat "$ROOT_DIR/connector-server.log" | tail -50 || true # Check if servers are running + SERVERS_READY=false for port in 3000 3003; do + echo "Checking port $port..." for i in {1..30}; do if curl -s "http://localhost:$port" > /dev/null 2>&1; then echo "Server on port $port is ready" @@ -93,10 +107,23 @@ jobs: echo "Waiting for port $port... (attempt $i)" sleep 2 done + # Verify the port is actually responding + if curl -s "http://localhost:$port" > /dev/null 2>&1; then + SERVERS_READY=true + else + echo "WARNING: Port $port is not responding!" + fi done + # Test if we can actually reach the site + echo "Testing site access..." + curl -v "http://localhost:3000/commerce/testing/" 2>&1 | head -50 || true + + # Create output directory + mkdir -p "$ROOT_DIR/_site" + cd "$ROOT_DIR/_site" + # Generate list of all page URLs from markdown files - # Navigation is JS-driven, so we need to explicitly list all pages cd "$ROOT_DIR/content" find src/pages -name "*.md" | sed 's|src/pages/||' | sed 's|\.md$||' | sed 's|/index$|/|' | while read path; do echo "http://localhost:3000/commerce/testing/$path" @@ -105,12 +132,10 @@ jobs: echo "Generated $(wc -l < "$ROOT_DIR/urls.txt") URLs to crawl" cat "$ROOT_DIR/urls.txt" - # Create output directory - mkdir -p "$ROOT_DIR/_site" cd "$ROOT_DIR/_site" # Use wget to crawl and generate static site - # --execute robots=off is required because the dev server returns Disallow: / + echo "Starting wget crawl..." wget \ --input-file="$ROOT_DIR/urls.txt" \ --page-requisites \ @@ -122,38 +147,44 @@ jobs: --wait=0.1 \ --tries=3 \ --timeout=30 \ - || true + --verbose \ + 2>&1 | tee "$ROOT_DIR/wget.log" || true + + echo "=== wget log tail ===" + tail -100 "$ROOT_DIR/wget.log" + + # Debug: List what was downloaded + echo "=== Downloaded files ===" + find . -type f | head -50 + echo "Total files: $(find . -type f | wc -l)" - # Organize the output structure - preserve directory structure for relative links + # Organize the output structure if [ -d "localhost:3000" ]; then - # Move everything up from localhost:3000 to _site root - # This keeps commerce/testing/ and hlx_statics/ at correct relative positions + echo "Found localhost:3000 directory, organizing..." mv localhost:3000/* . 2>/dev/null || true rm -rf localhost:3000 - - # Create a redirect index.html at root that points to commerce/testing/ - cat > index.html << 'EOF' - - - - - Redirecting... - - - - -

Redirecting to Commerce Testing documentation...

- - - EOF + else + echo "WARNING: localhost:3000 directory not found!" + ls -la + fi + + # Always create at least a minimal index.html + echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html + + # If no commerce directory exists, create a fallback page + if [ ! -d "commerce" ]; then + echo "WARNING: No content was generated. Creating fallback page." + mkdir -p commerce/testing + echo 'Commerce Testing - Build Failed

Preview Build Issue

The static site generation encountered an issue. The development servers may not have started correctly.

Please check the GitHub Actions logs for details.

' > commerce/testing/index.html fi # Stop servers kill $CONTENT_PID $DEVSITE_PID $CONNECTOR_PID 2>/dev/null || true - echo "Static site generated successfully" + echo "=== Final _site contents ===" find . -type f | wc -l - echo "files generated" + echo "files in _site" + ls -la - name: Setup Pages uses: actions/configure-pages@v5 From dbbbf974a0fc499c5e16715ece9b3363431f9c80 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 18:15:18 -0600 Subject: [PATCH 05/28] Update GitHub Actions workflow to handle directory naming changes for localhost, improving output organization and error messaging. --- .github/workflows/github-pages-preview.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index b3e9277..7e3756a 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -159,12 +159,17 @@ jobs: echo "Total files: $(find . -type f | wc -l)" # Organize the output structure - if [ -d "localhost:3000" ]; then + # Note: --restrict-file-names=windows converts : to + in directory names + if [ -d "localhost+3000" ]; then + echo "Found localhost+3000 directory, organizing..." + mv localhost+3000/* . 2>/dev/null || true + rm -rf localhost+3000 + elif [ -d "localhost:3000" ]; then echo "Found localhost:3000 directory, organizing..." mv localhost:3000/* . 2>/dev/null || true rm -rf localhost:3000 else - echo "WARNING: localhost:3000 directory not found!" + echo "WARNING: No localhost directory found!" ls -la fi From c40fb9dcfadeb84a9959be0fc7d27a0adb03ea0d Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 18:20:21 -0600 Subject: [PATCH 06/28] Enhance GitHub Actions workflow by adding steps to fetch dynamically loaded JavaScript files, improving the completeness of the preview deployment. --- .github/workflows/github-pages-preview.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 7e3756a..ce61dae 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -153,6 +153,15 @@ jobs: echo "=== wget log tail ===" tail -100 "$ROOT_DIR/wget.log" + # Fetch additional JS files that are dynamically loaded by scripts.js + echo "Fetching dynamically loaded scripts..." + mkdir -p localhost+3000/hlx_statics/scripts + wget -q -O localhost+3000/hlx_statics/scripts/lib-helix.js "http://localhost:3000/hlx_statics/scripts/lib-helix.js" || true + wget -q -O localhost+3000/hlx_statics/scripts/lib-adobeio.js "http://localhost:3000/hlx_statics/scripts/lib-adobeio.js" || true + + # Also fetch any other common dynamic dependencies + wget -q -O localhost+3000/hlx_statics/scripts/delayed.js "http://localhost:3000/hlx_statics/scripts/delayed.js" || true + # Debug: List what was downloaded echo "=== Downloaded files ===" find . -type f | head -50 From 3ff0f0b91e8fbd576581444ec78f2a809e0d6674 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Fri, 5 Dec 2025 18:29:08 -0600 Subject: [PATCH 07/28] Refactor GitHub Actions workflow to copy hlx_statics directly from adp-devsite source, ensuring all dynamically loaded components are available for preview deployment. --- .github/workflows/github-pages-preview.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index ce61dae..756a12b 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -153,14 +153,15 @@ jobs: echo "=== wget log tail ===" tail -100 "$ROOT_DIR/wget.log" - # Fetch additional JS files that are dynamically loaded by scripts.js - echo "Fetching dynamically loaded scripts..." - mkdir -p localhost+3000/hlx_statics/scripts - wget -q -O localhost+3000/hlx_statics/scripts/lib-helix.js "http://localhost:3000/hlx_statics/scripts/lib-helix.js" || true - wget -q -O localhost+3000/hlx_statics/scripts/lib-adobeio.js "http://localhost:3000/hlx_statics/scripts/lib-adobeio.js" || true + # Copy all hlx_statics from adp-devsite source directly + # This ensures all dynamically loaded blocks/components are available + echo "Copying hlx_statics from adp-devsite source..." + mkdir -p localhost+3000/hlx_statics + cp -r "$ROOT_DIR/adp-devsite/hlx_statics/"* localhost+3000/hlx_statics/ 2>/dev/null || true - # Also fetch any other common dynamic dependencies - wget -q -O localhost+3000/hlx_statics/scripts/delayed.js "http://localhost:3000/hlx_statics/scripts/delayed.js" || true + echo "hlx_statics files copied:" + find localhost+3000/hlx_statics -type f 2>/dev/null | wc -l + echo "files" # Debug: List what was downloaded echo "=== Downloaded files ===" From 33ba0286a42218deb9100b1eb34f59ba698b5919 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 16:27:32 -0600 Subject: [PATCH 08/28] Fix navigation preview Enhance GitHub Actions workflow by adding steps to fetch essential API endpoints for dynamic content, improving the completeness of the preview deployment. --- .github/workflows/github-pages-preview.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 756a12b..96a2edc 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -163,6 +163,27 @@ jobs: find localhost+3000/hlx_statics -type f 2>/dev/null | wc -l echo "files" + # Fetch API endpoints needed for dynamic content + echo "Fetching API endpoints..." + mkdir -p localhost+3000/commerce/testing + mkdir -p localhost+3000/franklin_assets + + # Config endpoint (for side navigation/TOC) + curl -s "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config || true + echo "Config endpoint saved" + + # Footer HTML + curl -s "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html || true + echo "Footer HTML saved" + + # Product index map + curl -s "http://localhost:3000/franklin_assets/product-index-map.json" -o localhost+3000/franklin_assets/product-index-map.json || true + echo "Product index map saved" + + # Site-wide banner config + curl -s "http://localhost:3000/commerce/testing/site-wide-banner.json" -o localhost+3000/commerce/testing/site-wide-banner.json || true + echo "Site-wide banner config saved" + # Debug: List what was downloaded echo "=== Downloaded files ===" find . -type f | head -50 From 1881bfef09438b4a79b4b5d0d86eddac4abd3199 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 16:34:52 -0600 Subject: [PATCH 09/28] Fix: Add fetch interceptor to rewrite absolute paths for GitHub Pages --- .github/workflows/github-pages-preview.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 96a2edc..58bc4c3 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -204,6 +204,19 @@ jobs: ls -la fi + # Fix absolute paths for GitHub Pages + # GitHub Pages serves at /commerce-testing/ but JS requests go to domain root + # Solution: Inject a fetch interceptor script to rewrite URLs + echo "Adding fetch interceptor for GitHub Pages compatibility..." + + INTERCEPTOR_SCRIPT='' + + find . -name "*.html" -type f | while read htmlfile; do + # Add interceptor script right after + sed -i "s||${INTERCEPTOR_SCRIPT}|" "$htmlfile" 2>/dev/null || true + done + echo "Fetch interceptor added to all HTML files" + # Always create at least a minimal index.html echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html From 4f6a0d6c58a467a34a370e3b166fd4ed9fdd9de3 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 16:41:40 -0600 Subject: [PATCH 10/28] Fix: Create interceptor.js file and inject script tag properly --- .github/workflows/github-pages-preview.yml | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 58bc4c3..c5cbe02 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -206,16 +206,26 @@ jobs: # Fix absolute paths for GitHub Pages # GitHub Pages serves at /commerce-testing/ but JS requests go to domain root - # Solution: Inject a fetch interceptor script to rewrite URLs + # Solution: Create an interceptor JS file and inject script tag into HTML echo "Adding fetch interceptor for GitHub Pages compatibility..." - INTERCEPTOR_SCRIPT='' + # Create the interceptor JavaScript file using printf (avoids heredoc YAML issues) + mkdir -p _gh_pages + printf '%s\n' '(function(){' 'var BASE="/commerce-testing";' 'var oF=window.fetch;window.fetch=function(u,o){if(typeof u==="string"&&u.startsWith("/")&&!u.startsWith(BASE)){u=BASE+u}return oF.call(this,u,o)};' 'var oX=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){if(typeof u==="string"&&u.startsWith("/")&&!u.startsWith(BASE)){u=BASE+u}return oX.apply(this,arguments)};' 'console.log("GH Pages interceptor loaded");' '})();' > _gh_pages/interceptor.js + echo "Created _gh_pages/interceptor.js" + cat _gh_pages/interceptor.js - find . -name "*.html" -type f | while read htmlfile; do - # Add interceptor script right after - sed -i "s||${INTERCEPTOR_SCRIPT}|" "$htmlfile" 2>/dev/null || true - done - echo "Fetch interceptor added to all HTML files" + # Inject script tag into all HTML files + SCRIPT_TAG='' + find . -name "*.html" -type f -print0 | xargs -0 -I {} sh -c 'sed -i "s||'"$SCRIPT_TAG"'|g" "{}" 2>/dev/null || sed -i "" "s||'"$SCRIPT_TAG"'|g" "{}" 2>/dev/null || true' + + # Count modified files + MODIFIED=$(grep -rl "_gh_pages/interceptor.js" . --include="*.html" 2>/dev/null | wc -l || echo "0") + echo "Injected interceptor script tag into $MODIFIED HTML files" + + # Debug: show first lines of a sample file + echo "Sample HTML head:" + head -3 commerce/testing/index.html 2>/dev/null || head -3 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" # Always create at least a minimal index.html echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html From f6837c36b61f0574b7448e3cdc5eeadbee0d6d0f Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 16:49:35 -0600 Subject: [PATCH 11/28] Fix: Use inline interceptor script to run before external scripts --- .github/workflows/github-pages-preview.yml | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index c5cbe02..2e33c95 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -206,26 +206,25 @@ jobs: # Fix absolute paths for GitHub Pages # GitHub Pages serves at /commerce-testing/ but JS requests go to domain root - # Solution: Create an interceptor JS file and inject script tag into HTML - echo "Adding fetch interceptor for GitHub Pages compatibility..." + # Solution: Inject INLINE interceptor script (must run before any other scripts) + echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." - # Create the interceptor JavaScript file using printf (avoids heredoc YAML issues) - mkdir -p _gh_pages - printf '%s\n' '(function(){' 'var BASE="/commerce-testing";' 'var oF=window.fetch;window.fetch=function(u,o){if(typeof u==="string"&&u.startsWith("/")&&!u.startsWith(BASE)){u=BASE+u}return oF.call(this,u,o)};' 'var oX=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){if(typeof u==="string"&&u.startsWith("/")&&!u.startsWith(BASE)){u=BASE+u}return oX.apply(this,arguments)};' 'console.log("GH Pages interceptor loaded");' '})();' > _gh_pages/interceptor.js - echo "Created _gh_pages/interceptor.js" - cat _gh_pages/interceptor.js + # Inline script that patches fetch/XHR immediately (no external file to wait for) + INLINE_SCRIPT='' - # Inject script tag into all HTML files - SCRIPT_TAG='' - find . -name "*.html" -type f -print0 | xargs -0 -I {} sh -c 'sed -i "s||'"$SCRIPT_TAG"'|g" "{}" 2>/dev/null || sed -i "" "s||'"$SCRIPT_TAG"'|g" "{}" 2>/dev/null || true' + # Inject inline script into all HTML files + find . -name "*.html" -type f | while read htmlfile; do + sed -i "s||${INLINE_SCRIPT}|" "$htmlfile" 2>/dev/null || \ + sed -i "" "s||${INLINE_SCRIPT}|" "$htmlfile" 2>/dev/null || true + done # Count modified files - MODIFIED=$(grep -rl "_gh_pages/interceptor.js" . --include="*.html" 2>/dev/null | wc -l || echo "0") - echo "Injected interceptor script tag into $MODIFIED HTML files" + MODIFIED=$(grep -c 'commerce-testing.*fetch' commerce/testing/index.html 2>/dev/null || echo "0") + echo "Interceptor injection check: $MODIFIED matches in index.html" # Debug: show first lines of a sample file - echo "Sample HTML head:" - head -3 commerce/testing/index.html 2>/dev/null || head -3 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" + echo "Sample HTML head (first 500 chars):" + head -c 500 commerce/testing/index.html 2>/dev/null || head -c 500 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" # Always create at least a minimal index.html echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html From 83ea961381b288315efb458bbd533b4c489f5356 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 16:54:25 -0600 Subject: [PATCH 12/28] Fix: Use perl for injection to handle && in JS correctly --- .github/workflows/github-pages-preview.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 2e33c95..dc72955 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -209,22 +209,23 @@ jobs: # Solution: Inject INLINE interceptor script (must run before any other scripts) echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." - # Inline script that patches fetch/XHR immediately (no external file to wait for) - INLINE_SCRIPT='' + # Create interceptor file (using echo to avoid heredoc YAML issues) + echo '' > /tmp/interceptor.txt + echo "Interceptor content:" + cat /tmp/interceptor.txt - # Inject inline script into all HTML files + # Use perl for injection (handles special chars correctly) find . -name "*.html" -type f | while read htmlfile; do - sed -i "s||${INLINE_SCRIPT}|" "$htmlfile" 2>/dev/null || \ - sed -i "" "s||${INLINE_SCRIPT}|" "$htmlfile" 2>/dev/null || true + perl -i -pe 'BEGIN{open(F,"/tmp/interceptor.txt");$s=;chomp $s;close F} s//$s/' "$htmlfile" 2>/dev/null || true done # Count modified files - MODIFIED=$(grep -c 'commerce-testing.*fetch' commerce/testing/index.html 2>/dev/null || echo "0") - echo "Interceptor injection check: $MODIFIED matches in index.html" + MODIFIED=$(grep -l 'commerce-testing.*fetch' commerce/testing/*.html 2>/dev/null | wc -l || echo "0") + echo "Interceptor injection check: $MODIFIED files modified" # Debug: show first lines of a sample file - echo "Sample HTML head (first 500 chars):" - head -c 500 commerce/testing/index.html 2>/dev/null || head -c 500 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" + echo "Sample HTML head (first 600 chars):" + head -c 600 commerce/testing/index.html 2>/dev/null || head -c 600 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" # Always create at least a minimal index.html echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html From d5c11dc45f71db30feaeeef482dede2112f5262d Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 17:01:12 -0600 Subject: [PATCH 13/28] Fix: Intercept both relative paths and full URLs --- .github/workflows/github-pages-preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index dc72955..c9cab76 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -209,8 +209,8 @@ jobs: # Solution: Inject INLINE interceptor script (must run before any other scripts) echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." - # Create interceptor file (using echo to avoid heredoc YAML issues) - echo '' > /tmp/interceptor.txt + # Create interceptor file (handles both relative paths and full URLs) + echo '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From bf10a998af6839382e91ac00b5d1f2f1382afe7c Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 17:07:36 -0600 Subject: [PATCH 14/28] Fix: Handle Request and URL objects in fetch interceptor --- .github/workflows/github-pages-preview.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index c9cab76..182b4c4 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -209,8 +209,13 @@ jobs: # Solution: Inject INLINE interceptor script (must run before any other scripts) echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." - # Create interceptor file (handles both relative paths and full URLs) - echo '' > /tmp/interceptor.txt + # Create interceptor file that handles: + # 1. String URLs in fetch() + # 2. Request objects in fetch() + # 3. URL objects in fetch() + # 4. XMLHttpRequest + # Note: Using printf to avoid echo interpretation issues + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From 8f11883af8ab1250ad74782f9f35c22bea91cbe0 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 17:18:54 -0600 Subject: [PATCH 15/28] Fix: Add MutationObserver to fix dynamically created element paths --- .github/workflows/github-pages-preview.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 182b4c4..14a3509 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -210,12 +210,11 @@ jobs: echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." # Create interceptor file that handles: - # 1. String URLs in fetch() - # 2. Request objects in fetch() - # 3. URL objects in fetch() - # 4. XMLHttpRequest - # Note: Using printf to avoid echo interpretation issues - printf '%s' '' > /tmp/interceptor.txt + # 1. fetch() - String URLs, Request objects, URL objects + # 2. XMLHttpRequest + # 3. Dynamically created DOM elements (img src, use href, link href, script src) + # Uses MutationObserver to fix elements as they are added to the DOM + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From ea94375d86eb74f6012976f10caacc65012204ec Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 17:46:11 -0600 Subject: [PATCH 16/28] Fix: Remove no-sidenav class to show side navigation on GitHub Pages --- .github/workflows/github-pages-preview.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 14a3509..cdadbb5 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -169,8 +169,10 @@ jobs: mkdir -p localhost+3000/franklin_assets # Config endpoint (for side navigation/TOC) - curl -s "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config || true - echo "Config endpoint saved" + # IMPORTANT: Copy raw config.md as plain text, NOT the rendered HTML + # The side-nav.js expects plain text format, not HTML + cp "$ROOT_DIR/content/src/pages/config.md" localhost+3000/commerce/testing/config || true + echo "Config (raw markdown) copied for side navigation" # Footer HTML curl -s "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html || true @@ -213,8 +215,9 @@ jobs: # 1. fetch() - String URLs, Request objects, URL objects # 2. XMLHttpRequest # 3. Dynamically created DOM elements (img src, use href, link href, script src) + # 4. Remove 'no-sidenav' class which gets incorrectly added due to path mismatch # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From 3f12b21dd4d73e6cda89d3ec90c637b428bd676e Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 17:58:35 -0600 Subject: [PATCH 17/28] Fix: Only remove no-sidenav on documentation pages (template=documentation) --- .github/workflows/github-pages-preview.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index cdadbb5..13d4183 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -215,9 +215,9 @@ jobs: # 1. fetch() - String URLs, Request objects, URL objects # 2. XMLHttpRequest # 3. Dynamically created DOM elements (img src, use href, link href, script src) - # 4. Remove 'no-sidenav' class which gets incorrectly added due to path mismatch + # 4. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From dda084dcc02c6c863a2a049951a98d1a6782f366 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 18:14:58 -0600 Subject: [PATCH 18/28] Update GitHub Actions workflow to fetch rendered HTML for side navigation and enhance fetch interceptor for URL normalization --- .github/workflows/github-pages-preview.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 13d4183..7e41737 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -169,10 +169,10 @@ jobs: mkdir -p localhost+3000/franklin_assets # Config endpoint (for side navigation/TOC) - # IMPORTANT: Copy raw config.md as plain text, NOT the rendered HTML - # The side-nav.js expects plain text format, not HTML - cp "$ROOT_DIR/content/src/pages/config.md" localhost+3000/commerce/testing/config || true - echo "Config (raw markdown) copied for side navigation" + # IMPORTANT: Fetch the RENDERED HTML from the local server, not the raw markdown + # The side-nav.js parses this HTML to build the navigation tree + curl -s "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config || true + echo "Config HTML fetched from local server" # Footer HTML curl -s "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html || true @@ -212,12 +212,13 @@ jobs: echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." # Create interceptor file that handles: - # 1. fetch() - String URLs, Request objects, URL objects - # 2. XMLHttpRequest - # 3. Dynamically created DOM elements (img src, use href, link href, script src) - # 4. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") + # 1. URL normalization - Remove /index.html suffix from location.href (fixes side-nav selection) + # 2. fetch() - String URLs, Request objects, URL objects + # 3. XMLHttpRequest + # 4. Dynamically created DOM elements (img src, use href, link href, script src) + # 5. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From 48a3e4bf8eb66d35565e3f3148357699b17f68fc Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 15 Dec 2025 18:21:43 -0600 Subject: [PATCH 19/28] Fix: Handle full URLs with origin in fetch interceptor --- .github/workflows/github-pages-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 7e41737..b21080a 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -218,7 +218,7 @@ jobs: # 4. Dynamically created DOM elements (img src, use href, link href, script src) # 5. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From 028263552c3537e45d390b0f73e96290dc78882f Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Tue, 16 Dec 2025 10:35:16 -0600 Subject: [PATCH 20/28] Fix: Rewrite config paths for correct side-nav section filtering --- .github/workflows/github-pages-preview.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index b21080a..3379f6a 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -174,6 +174,15 @@ jobs: curl -s "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config || true echo "Config HTML fetched from local server" + # Rewrite paths in config to include /commerce-testing prefix + # This is needed for side-nav filtering to work correctly on GitHub Pages + if [ -f "localhost+3000/commerce/testing/config" ]; then + perl -i -pe 's|href="/commerce/testing/|href="/commerce-testing/commerce/testing/|g' localhost+3000/commerce/testing/config + perl -i -pe 's|href="/functional-testing-framework/|href="/commerce-testing/commerce/testing/functional-testing-framework/|g' localhost+3000/commerce/testing/config + perl -i -pe 's|href="/guide/|href="/commerce-testing/commerce/testing/guide/|g' localhost+3000/commerce/testing/config + echo "Config paths rewritten for GitHub Pages" + fi + # Footer HTML curl -s "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html || true echo "Footer HTML saved" @@ -217,8 +226,9 @@ jobs: # 3. XMLHttpRequest # 4. Dynamically created DOM elements (img src, use href, link href, script src) # 5. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") + # 6. Filter TOC items to only show items for the current section (Guide vs MFTF) # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt + printf '%s' '' > /tmp/interceptor.txt echo "Interceptor content:" cat /tmp/interceptor.txt From 59310c2e9a6d8ffe2014603afac4a4058d7cc000 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 17 Dec 2025 12:04:28 -0600 Subject: [PATCH 21/28] Refactor: Split workflow into focused steps, add superhero fix --- .github/scripts/gh-pages-interceptor.js | 220 +++++++++++++++++ .github/workflows/github-pages-preview.yml | 274 +++++++++------------ 2 files changed, 343 insertions(+), 151 deletions(-) create mode 100644 .github/scripts/gh-pages-interceptor.js diff --git a/.github/scripts/gh-pages-interceptor.js b/.github/scripts/gh-pages-interceptor.js new file mode 100644 index 0000000..8f86cd4 --- /dev/null +++ b/.github/scripts/gh-pages-interceptor.js @@ -0,0 +1,220 @@ +/** + * GitHub Pages Path Interceptor for AEM Edge Delivery + * + * This script fixes path issues when hosting an AEM Edge Delivery site on GitHub Pages. + * GitHub Pages serves the site at // but the AEM framework expects paths + * to start from the domain root. + * + * Features: + * 1. URL normalization - Removes /index.html suffix for cleaner URLs + * 2. fetch() interception - Rewrites API calls to include base path + * 3. XMLHttpRequest interception - Same for XHR requests + * 4. DOM element fixing - Fixes src/href attributes on dynamically added elements + * 5. Side navigation fix - Removes 'no-sidenav' class on documentation pages + * 6. TOC filtering - Shows only relevant section items in table of contents + * 7. Superhero background fix - Ensures background images load correctly + */ +(function() { + var BASE = "/commerce-testing"; + var ORIGIN = location.origin; + + // 1. URL Normalization - Remove /index.html suffix + if (location.pathname.endsWith("/index.html")) { + history.replaceState( + null, + "", + location.pathname.replace(/\/index\.html$/, "/") + location.search + location.hash + ); + } + + /** + * Fix a URL by adding the base path if needed + * @param {string} url - The URL to fix + * @returns {string|null} - Fixed URL or null if no fix needed + */ + function fix(url) { + if (!url || typeof url !== "string") return null; + + // Handle full URLs (e.g., https://adobedocs.github.io/commerce/testing/config) + if (url.startsWith(ORIGIN) && !url.includes(BASE)) { + var path = url.substring(ORIGIN.length); + if ( + path.startsWith("/hlx_statics") || + path.startsWith("/franklin_assets") || + path.startsWith("/commerce") + ) { + return ORIGIN + BASE + path; + } + } + + // Handle relative paths (e.g., /commerce/testing/config) + if ( + url.startsWith("/") && + !url.startsWith(BASE) && + (url.startsWith("/hlx_statics") || + url.startsWith("/franklin_assets") || + url.startsWith("/commerce")) + ) { + return BASE + url; + } + + return null; + } + + // 2. Intercept fetch() calls + var originalFetch = window.fetch; + window.fetch = function(input, options) { + var fixed; + if (typeof input === "string") { + fixed = fix(input); + if (fixed) input = fixed; + } else if (input instanceof Request) { + fixed = fix(input.url); + if (fixed) input = new Request(fixed, input); + } + return originalFetch.call(this, input, options); + }; + + // 3. Intercept XMLHttpRequest + var originalXHROpen = XMLHttpRequest.prototype.open; + XMLHttpRequest.prototype.open = function(method, url) { + var fixed = fix(url); + if (fixed) url = fixed; + return originalXHROpen.apply(this, [method, url].concat([].slice.call(arguments, 2))); + }; + + /** + * Fix src/href attributes on a DOM element and its children + * @param {Element} el - The element to fix + */ + function fixElement(el) { + if (!el || !el.getAttribute) return; + + ["src", "href", "xlink:href"].forEach(function(attr) { + var value = el.getAttribute(attr); + var fixed = fix(value); + if (fixed) el.setAttribute(attr, fixed); + }); + + if (el.querySelectorAll) { + el.querySelectorAll("[src],[href]").forEach(fixElement); + } + } + + // 4. Watch for dynamically added DOM elements + new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + mutation.addedNodes.forEach(function(node) { + if (node.nodeType === 1) fixElement(node); + }); + }); + }).observe(document.documentElement, { childList: true, subtree: true }); + + // Also fix elements on DOMContentLoaded + document.addEventListener("DOMContentLoaded", function() { + fixElement(document.body); + }); + + // 5. Fix side navigation visibility + function fixSideNav() { + var main = document.querySelector("main"); + var template = document.querySelector('meta[name="template"]'); + if ( + main && + main.classList.contains("no-sidenav") && + template && + template.content === "documentation" + ) { + main.classList.remove("no-sidenav"); + } + } + + // Watch for class changes on main element + new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.target.tagName === "MAIN" && mutation.attributeName === "class") { + fixSideNav(); + } + }); + }).observe(document.documentElement, { + attributes: true, + subtree: true, + attributeFilter: ["class"] + }); + + document.addEventListener("DOMContentLoaded", fixSideNav); + setTimeout(fixSideNav, 500); + setTimeout(fixSideNav, 1500); + + // 6. Filter TOC to show only current section items + function filterToc() { + var nav = document.querySelector("#navigation-links"); + if (!nav) return; + + var currentPath = location.pathname.replace(/\/$/, ""); + var bestMatch = null; + var bestLength = 0; + + // Find the best matching top-level nav item + nav.querySelectorAll("a").forEach(function(anchor) { + if (anchor.getAttribute("fullPath")) return; // Skip items with fullPath attr + var href = new URL(anchor.href).pathname.replace(/\/$/, ""); + if (currentPath === href) { + bestMatch = anchor; + bestLength = 999; + } else if (currentPath.startsWith(href + "/") && href.length > bestLength) { + bestMatch = anchor; + bestLength = href.length; + } + }); + + if (!bestMatch) return; + + var topPath = new URL(bestMatch.href).pathname; + var toc = document.querySelector(".side-nav-subpages-section"); + if (!toc) return; + + // Hide items that don't belong to current section + toc.querySelectorAll(":scope > ul li").forEach(function(li) { + var link = li.querySelector(":scope > a"); + if (!link) { + li.classList.add("hidden"); + return; + } + var linkPath = new URL(link.href, ORIGIN).pathname; + if (!linkPath.startsWith(topPath)) { + li.classList.add("hidden"); + } + }); + } + + setTimeout(filterToc, 1000); + setTimeout(filterToc, 2000); + setTimeout(filterToc, 3000); + + // 7. Fix superhero background image + function fixSuperheroBackground() { + var superhero = document.querySelector(".superhero"); + if (!superhero) return; + + // Check if background is undefined or missing + var style = window.getComputedStyle(superhero); + if (style.backgroundImage.includes("undefined")) { + // Find the img element that should be the background + var img = superhero.querySelector("img"); + if (img && img.src) { + var existingBg = superhero.style.background || ""; + superhero.style.background = + "url(" + img.src + ") center center / cover no-repeat" + + (existingBg ? ", " + existingBg : ", rgb(29, 125, 238)"); + // Hide the img element since it's now a background + img.style.display = "none"; + } + } + } + + document.addEventListener("DOMContentLoaded", fixSuperheroBackground); + setTimeout(fixSuperheroBackground, 500); + setTimeout(fixSuperheroBackground, 1500); +})(); + diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 3379f6a..8ec809a 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -8,8 +8,6 @@ on: type: string required: false default: "" - # For testing: runs on push to any branch containing 'preview' or 'gh-pages' - # Remove this trigger after testing is complete push: branches: - "**/preview**" @@ -17,14 +15,11 @@ on: - "preview-**" - "gh-pages-**" -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: pages cancel-in-progress: false @@ -59,83 +54,62 @@ jobs: - name: Install dependencies run: | - cd content && npm install && cd .. - cd adp-devsite && npm install && cd .. - cd devsite-runtime-connector && npm install + cd content && npm install + cd ../adp-devsite && npm install + cd ../devsite-runtime-connector && npm install - - name: Start servers and generate static site + - name: Start development servers run: | - set -x # Enable debug output ROOT_DIR=$(pwd) - + # Start content server (port 3003) - echo "Starting content server..." - (cd "$ROOT_DIR/content" && npm run dev 2>&1 | tee "$ROOT_DIR/content-server.log") & - CONTENT_PID=$! - + (cd "$ROOT_DIR/content" && npm run dev > "$ROOT_DIR/content-server.log" 2>&1) & + echo $! > /tmp/content.pid + # Start adp-devsite (port 3000) - echo "Starting adp-devsite..." - (cd "$ROOT_DIR/adp-devsite" && npm run dev 2>&1 | tee "$ROOT_DIR/devsite-server.log") & - DEVSITE_PID=$! - - # Start runtime connector - echo "Starting runtime connector..." - (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev 2>&1 | tee "$ROOT_DIR/connector-server.log") & - CONNECTOR_PID=$! - - # Wait for servers to be ready - echo "Waiting for servers to start..." - sleep 20 - - # Debug: Show server logs - echo "=== Content server log ===" - cat "$ROOT_DIR/content-server.log" | tail -50 || true - echo "=== Devsite server log ===" - cat "$ROOT_DIR/devsite-server.log" | tail -50 || true - echo "=== Connector server log ===" - cat "$ROOT_DIR/connector-server.log" | tail -50 || true + (cd "$ROOT_DIR/adp-devsite" && npm run dev > "$ROOT_DIR/devsite-server.log" 2>&1) & + echo $! > /tmp/devsite.pid + + # Start runtime connector (port 3001) + (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev > "$ROOT_DIR/connector-server.log" 2>&1) & + echo $! > /tmp/connector.pid + + echo "Servers starting in background..." - # Check if servers are running - SERVERS_READY=false + - name: Wait for servers to be ready + run: | + echo "Waiting for servers..." for port in 3000 3003; do - echo "Checking port $port..." - for i in {1..30}; do + for i in {1..60}; do if curl -s "http://localhost:$port" > /dev/null 2>&1; then - echo "Server on port $port is ready" + echo "āœ“ Port $port is ready" break fi - echo "Waiting for port $port... (attempt $i)" - sleep 2 + if [ $i -eq 60 ]; then + echo "āœ— Port $port timeout" + exit 1 + fi + sleep 1 done - # Verify the port is actually responding - if curl -s "http://localhost:$port" > /dev/null 2>&1; then - SERVERS_READY=true - else - echo "WARNING: Port $port is not responding!" - fi done + + # Verify site is accessible + curl -sf "http://localhost:3000/commerce/testing/" > /dev/null && echo "āœ“ Site is accessible" - # Test if we can actually reach the site - echo "Testing site access..." - curl -v "http://localhost:3000/commerce/testing/" 2>&1 | head -50 || true - - # Create output directory + - name: Generate static site with wget + run: | + ROOT_DIR=$(pwd) mkdir -p "$ROOT_DIR/_site" - cd "$ROOT_DIR/_site" - - # Generate list of all page URLs from markdown files + + # Generate URL list from markdown files cd "$ROOT_DIR/content" find src/pages -name "*.md" | sed 's|src/pages/||' | sed 's|\.md$||' | sed 's|/index$|/|' | while read path; do echo "http://localhost:3000/commerce/testing/$path" done > "$ROOT_DIR/urls.txt" - - echo "Generated $(wc -l < "$ROOT_DIR/urls.txt") URLs to crawl" - cat "$ROOT_DIR/urls.txt" - + + echo "Crawling $(wc -l < "$ROOT_DIR/urls.txt" | tr -d ' ') pages..." + cd "$ROOT_DIR/_site" - - # Use wget to crawl and generate static site - echo "Starting wget crawl..." wget \ --input-file="$ROOT_DIR/urls.txt" \ --page-requisites \ @@ -147,121 +121,120 @@ jobs: --wait=0.1 \ --tries=3 \ --timeout=30 \ - --verbose \ - 2>&1 | tee "$ROOT_DIR/wget.log" || true - - echo "=== wget log tail ===" - tail -100 "$ROOT_DIR/wget.log" + --quiet \ + 2>&1 || true + + echo "āœ“ wget crawl complete" - # Copy all hlx_statics from adp-devsite source directly - # This ensures all dynamically loaded blocks/components are available - echo "Copying hlx_statics from adp-devsite source..." - mkdir -p localhost+3000/hlx_statics - cp -r "$ROOT_DIR/adp-devsite/hlx_statics/"* localhost+3000/hlx_statics/ 2>/dev/null || true + - name: Copy static assets + run: | + cd _site - echo "hlx_statics files copied:" - find localhost+3000/hlx_statics -type f 2>/dev/null | wc -l - echo "files" + # Copy hlx_statics from adp-devsite source + mkdir -p localhost+3000/hlx_statics + cp -r ../adp-devsite/hlx_statics/* localhost+3000/hlx_statics/ + echo "āœ“ Copied $(find localhost+3000/hlx_statics -type f | wc -l | tr -d ' ') static files" - # Fetch API endpoints needed for dynamic content - echo "Fetching API endpoints..." + - name: Fetch API endpoints + run: | + cd _site mkdir -p localhost+3000/commerce/testing mkdir -p localhost+3000/franklin_assets - # Config endpoint (for side navigation/TOC) - # IMPORTANT: Fetch the RENDERED HTML from the local server, not the raw markdown - # The side-nav.js parses this HTML to build the navigation tree - curl -s "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config || true - echo "Config HTML fetched from local server" + # Config (for side navigation) + curl -sf "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config && echo "āœ“ config" + + # Footer + curl -sf "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html && echo "āœ“ footer" + + # Product index map + curl -sf "http://localhost:3000/franklin_assets/product-index-map.json" -o localhost+3000/franklin_assets/product-index-map.json && echo "āœ“ product-index-map" + + # Site-wide banner + curl -sf "http://localhost:3000/commerce/testing/site-wide-banner.json" -o localhost+3000/commerce/testing/site-wide-banner.json || echo "ā—‹ site-wide-banner (optional)" + + - name: Rewrite paths for GitHub Pages + run: | + cd _site - # Rewrite paths in config to include /commerce-testing prefix - # This is needed for side-nav filtering to work correctly on GitHub Pages + # Rewrite config paths for side-nav filtering if [ -f "localhost+3000/commerce/testing/config" ]; then perl -i -pe 's|href="/commerce/testing/|href="/commerce-testing/commerce/testing/|g' localhost+3000/commerce/testing/config perl -i -pe 's|href="/functional-testing-framework/|href="/commerce-testing/commerce/testing/functional-testing-framework/|g' localhost+3000/commerce/testing/config perl -i -pe 's|href="/guide/|href="/commerce-testing/commerce/testing/guide/|g' localhost+3000/commerce/testing/config - echo "Config paths rewritten for GitHub Pages" + echo "āœ“ Config paths rewritten" fi - - # Footer HTML - curl -s "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html || true - echo "Footer HTML saved" - - # Product index map - curl -s "http://localhost:3000/franklin_assets/product-index-map.json" -o localhost+3000/franklin_assets/product-index-map.json || true - echo "Product index map saved" - - # Site-wide banner config - curl -s "http://localhost:3000/commerce/testing/site-wide-banner.json" -o localhost+3000/commerce/testing/site-wide-banner.json || true - echo "Site-wide banner config saved" - - # Debug: List what was downloaded - echo "=== Downloaded files ===" - find . -type f | head -50 - echo "Total files: $(find . -type f | wc -l)" - # Organize the output structure - # Note: --restrict-file-names=windows converts : to + in directory names + - name: Organize output structure + run: | + cd _site + + # Move content from localhost+3000 to root if [ -d "localhost+3000" ]; then - echo "Found localhost+3000 directory, organizing..." mv localhost+3000/* . 2>/dev/null || true rm -rf localhost+3000 - elif [ -d "localhost:3000" ]; then - echo "Found localhost:3000 directory, organizing..." - mv localhost:3000/* . 2>/dev/null || true - rm -rf localhost:3000 - else - echo "WARNING: No localhost directory found!" - ls -la + echo "āœ“ Output structure organized" fi - # Fix absolute paths for GitHub Pages - # GitHub Pages serves at /commerce-testing/ but JS requests go to domain root - # Solution: Inject INLINE interceptor script (must run before any other scripts) - echo "Adding INLINE fetch interceptor for GitHub Pages compatibility..." + - name: Inject GitHub Pages interceptor + run: | + cd _site - # Create interceptor file that handles: - # 1. URL normalization - Remove /index.html suffix from location.href (fixes side-nav selection) - # 2. fetch() - String URLs, Request objects, URL objects - # 3. XMLHttpRequest - # 4. Dynamically created DOM elements (img src, use href, link href, script src) - # 5. Remove 'no-sidenav' class ONLY on documentation pages (template="documentation") - # 6. Filter TOC items to only show items for the current section (Guide vs MFTF) - # Uses MutationObserver to fix elements as they are added to the DOM - printf '%s' '' > /tmp/interceptor.txt - echo "Interceptor content:" - cat /tmp/interceptor.txt + # Minify the interceptor script for injection + INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | tr '\n' ' ' | sed 's/ */ /g') - # Use perl for injection (handles special chars correctly) + # Create script tag + echo "" > /tmp/interceptor.txt + + # Inject into all HTML files find . -name "*.html" -type f | while read htmlfile; do perl -i -pe 'BEGIN{open(F,"/tmp/interceptor.txt");$s=;chomp $s;close F} s//$s/' "$htmlfile" 2>/dev/null || true done - # Count modified files - MODIFIED=$(grep -l 'commerce-testing.*fetch' commerce/testing/*.html 2>/dev/null | wc -l || echo "0") - echo "Interceptor injection check: $MODIFIED files modified" - - # Debug: show first lines of a sample file - echo "Sample HTML head (first 600 chars):" - head -c 600 commerce/testing/index.html 2>/dev/null || head -c 600 commerce/testing/guide/index.html 2>/dev/null || echo "Could not read sample file" + MODIFIED=$(grep -l 'commerce-testing' commerce/testing/*.html 2>/dev/null | wc -l | tr -d ' ') + echo "āœ“ Interceptor injected into $MODIFIED files" - # Always create at least a minimal index.html - echo 'Commerce Testing - Preview

Redirecting to Commerce Testing documentation...

' > index.html + - name: Create root redirect + run: | + cd _site + cat > index.html << 'EOF' + + + + + Commerce Testing - Preview + + + + +

Redirecting to Commerce Testing documentation...

+ + + EOF + echo "āœ“ Root redirect created" + + - name: Stop servers + if: always() + run: | + for pidfile in /tmp/content.pid /tmp/devsite.pid /tmp/connector.pid; do + if [ -f "$pidfile" ]; then + kill $(cat "$pidfile") 2>/dev/null || true + fi + done - # If no commerce directory exists, create a fallback page + - name: Verify build output + run: | + cd _site + echo "=== Build Summary ===" + echo "Total files: $(find . -type f | wc -l | tr -d ' ')" + echo "HTML files: $(find . -name '*.html' | wc -l | tr -d ' ')" + if [ ! -d "commerce" ]; then - echo "WARNING: No content was generated. Creating fallback page." - mkdir -p commerce/testing - echo 'Commerce Testing - Build Failed

Preview Build Issue

The static site generation encountered an issue. The development servers may not have started correctly.

Please check the GitHub Actions logs for details.

' > commerce/testing/index.html + echo "ERROR: No content generated!" + exit 1 fi - - # Stop servers - kill $CONTENT_PID $DEVSITE_PID $CONNECTOR_PID 2>/dev/null || true - - echo "=== Final _site contents ===" - find . -type f | wc -l - echo "files in _site" - ls -la + + echo "āœ“ Build verification passed" - name: Setup Pages uses: actions/configure-pages@v5 @@ -284,4 +257,3 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 - From f0cb8c1f606799fbf0c23df3aeae16bbef6a3325 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 17 Dec 2025 12:15:35 -0600 Subject: [PATCH 22/28] Fix: Superhero background + interceptor minification --- .github/scripts/gh-pages-interceptor.js | 65 +++++++--------------- .github/workflows/github-pages-preview.yml | 12 ++++ 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/.github/scripts/gh-pages-interceptor.js b/.github/scripts/gh-pages-interceptor.js index 8f86cd4..6cbf43a 100644 --- a/.github/scripts/gh-pages-interceptor.js +++ b/.github/scripts/gh-pages-interceptor.js @@ -1,24 +1,9 @@ -/** - * GitHub Pages Path Interceptor for AEM Edge Delivery - * - * This script fixes path issues when hosting an AEM Edge Delivery site on GitHub Pages. - * GitHub Pages serves the site at // but the AEM framework expects paths - * to start from the domain root. - * - * Features: - * 1. URL normalization - Removes /index.html suffix for cleaner URLs - * 2. fetch() interception - Rewrites API calls to include base path - * 3. XMLHttpRequest interception - Same for XHR requests - * 4. DOM element fixing - Fixes src/href attributes on dynamically added elements - * 5. Side navigation fix - Removes 'no-sidenav' class on documentation pages - * 6. TOC filtering - Shows only relevant section items in table of contents - * 7. Superhero background fix - Ensures background images load correctly - */ +/* GitHub Pages Path Interceptor for AEM Edge Delivery - Fixes path issues when hosting on GitHub Pages */ (function() { var BASE = "/commerce-testing"; var ORIGIN = location.origin; - // 1. URL Normalization - Remove /index.html suffix + /* URL Normalization - Remove /index.html suffix */ if (location.pathname.endsWith("/index.html")) { history.replaceState( null, @@ -27,15 +12,11 @@ ); } - /** - * Fix a URL by adding the base path if needed - * @param {string} url - The URL to fix - * @returns {string|null} - Fixed URL or null if no fix needed - */ + /* Fix a URL by adding the base path if needed */ function fix(url) { if (!url || typeof url !== "string") return null; - // Handle full URLs (e.g., https://adobedocs.github.io/commerce/testing/config) + /* Handle full URLs */ if (url.startsWith(ORIGIN) && !url.includes(BASE)) { var path = url.substring(ORIGIN.length); if ( @@ -47,7 +28,7 @@ } } - // Handle relative paths (e.g., /commerce/testing/config) + /* Handle relative paths */ if ( url.startsWith("/") && !url.startsWith(BASE) && @@ -61,7 +42,7 @@ return null; } - // 2. Intercept fetch() calls + /* Intercept fetch() calls */ var originalFetch = window.fetch; window.fetch = function(input, options) { var fixed; @@ -75,7 +56,7 @@ return originalFetch.call(this, input, options); }; - // 3. Intercept XMLHttpRequest + /* Intercept XMLHttpRequest */ var originalXHROpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url) { var fixed = fix(url); @@ -83,10 +64,7 @@ return originalXHROpen.apply(this, [method, url].concat([].slice.call(arguments, 2))); }; - /** - * Fix src/href attributes on a DOM element and its children - * @param {Element} el - The element to fix - */ + /* Fix src/href attributes on a DOM element and its children */ function fixElement(el) { if (!el || !el.getAttribute) return; @@ -101,7 +79,7 @@ } } - // 4. Watch for dynamically added DOM elements + /* Watch for dynamically added DOM elements */ new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { mutation.addedNodes.forEach(function(node) { @@ -110,12 +88,12 @@ }); }).observe(document.documentElement, { childList: true, subtree: true }); - // Also fix elements on DOMContentLoaded + /* Also fix elements on DOMContentLoaded */ document.addEventListener("DOMContentLoaded", function() { fixElement(document.body); }); - // 5. Fix side navigation visibility + /* Fix side navigation visibility */ function fixSideNav() { var main = document.querySelector("main"); var template = document.querySelector('meta[name="template"]'); @@ -129,7 +107,7 @@ } } - // Watch for class changes on main element + /* Watch for class changes on main element */ new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.target.tagName === "MAIN" && mutation.attributeName === "class") { @@ -146,7 +124,7 @@ setTimeout(fixSideNav, 500); setTimeout(fixSideNav, 1500); - // 6. Filter TOC to show only current section items + /* Filter TOC to show only current section items */ function filterToc() { var nav = document.querySelector("#navigation-links"); if (!nav) return; @@ -155,9 +133,9 @@ var bestMatch = null; var bestLength = 0; - // Find the best matching top-level nav item + /* Find the best matching top-level nav item */ nav.querySelectorAll("a").forEach(function(anchor) { - if (anchor.getAttribute("fullPath")) return; // Skip items with fullPath attr + if (anchor.getAttribute("fullPath")) return; var href = new URL(anchor.href).pathname.replace(/\/$/, ""); if (currentPath === href) { bestMatch = anchor; @@ -174,7 +152,7 @@ var toc = document.querySelector(".side-nav-subpages-section"); if (!toc) return; - // Hide items that don't belong to current section + /* Hide items that don't belong to current section */ toc.querySelectorAll(":scope > ul li").forEach(function(li) { var link = li.querySelector(":scope > a"); if (!link) { @@ -192,22 +170,22 @@ setTimeout(filterToc, 2000); setTimeout(filterToc, 3000); - // 7. Fix superhero background image + /* Fix superhero background image */ function fixSuperheroBackground() { var superhero = document.querySelector(".superhero"); if (!superhero) return; - // Check if background is undefined or missing + /* Check if background is undefined or missing */ var style = window.getComputedStyle(superhero); if (style.backgroundImage.includes("undefined")) { - // Find the img element that should be the background + /* Find the img element that should be the background */ var img = superhero.querySelector("img"); - if (img && img.src) { + if (img && img.src && !img.src.includes("undefined")) { var existingBg = superhero.style.background || ""; superhero.style.background = "url(" + img.src + ") center center / cover no-repeat" + (existingBg ? ", " + existingBg : ", rgb(29, 125, 238)"); - // Hide the img element since it's now a background + /* Hide the img element since it's now a background */ img.style.display = "none"; } } @@ -217,4 +195,3 @@ setTimeout(fixSuperheroBackground, 500); setTimeout(fixSuperheroBackground, 1500); })(); - diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 8ec809a..4ebabbb 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -176,6 +176,18 @@ jobs: echo "āœ“ Output structure organized" fi + - name: Fix superhero block images + run: | + cd _site + + # The superhero.js expects but we have plain + # Wrap superhero images in elements so the background works + if [ -f "commerce/testing/index.html" ]; then + # Find tags in superhero blocks and wrap them in + perl -i -0pe 's|(
.*?
\s*)]+)>(.*?
\s*
)|$1$3|gs' commerce/testing/index.html + echo "āœ“ Superhero images wrapped in " + fi + - name: Inject GitHub Pages interceptor run: | cd _site From f36201a5f8fcb7a785d6c1c519a3e42f37c9df2e Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 17 Dec 2025 12:39:36 -0600 Subject: [PATCH 23/28] Update: Modify GitHub Pages interceptor to use dynamic path prefix and adjust workflow for path rewriting --- .github/scripts/gh-pages-interceptor.js | 2 +- .github/workflows/github-pages-preview.yml | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/scripts/gh-pages-interceptor.js b/.github/scripts/gh-pages-interceptor.js index 6cbf43a..2867377 100644 --- a/.github/scripts/gh-pages-interceptor.js +++ b/.github/scripts/gh-pages-interceptor.js @@ -1,6 +1,6 @@ /* GitHub Pages Path Interceptor for AEM Edge Delivery - Fixes path issues when hosting on GitHub Pages */ (function() { - var BASE = "/commerce-testing"; + var BASE = "/__PATH_PREFIX__"; var ORIGIN = location.origin; /* URL Normalization - Remove /index.html suffix */ diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 4ebabbb..857f2cf 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -28,6 +28,8 @@ jobs: build: name: Build runs-on: ubuntu-latest + env: + PATH_PREFIX: ${{ github.event.repository.name }} steps: - name: Checkout content repo uses: actions/checkout@v4 @@ -159,9 +161,9 @@ jobs: # Rewrite config paths for side-nav filtering if [ -f "localhost+3000/commerce/testing/config" ]; then - perl -i -pe 's|href="/commerce/testing/|href="/commerce-testing/commerce/testing/|g' localhost+3000/commerce/testing/config - perl -i -pe 's|href="/functional-testing-framework/|href="/commerce-testing/commerce/testing/functional-testing-framework/|g' localhost+3000/commerce/testing/config - perl -i -pe 's|href="/guide/|href="/commerce-testing/commerce/testing/guide/|g' localhost+3000/commerce/testing/config + perl -i -pe "s|href=\"/commerce/testing/|href=\"/${PATH_PREFIX}/commerce/testing/|g" localhost+3000/commerce/testing/config + perl -i -pe "s|href=\"/functional-testing-framework/|href=\"/${PATH_PREFIX}/commerce/testing/functional-testing-framework/|g" localhost+3000/commerce/testing/config + perl -i -pe "s|href=\"/guide/|href=\"/${PATH_PREFIX}/commerce/testing/guide/|g" localhost+3000/commerce/testing/config echo "āœ“ Config paths rewritten" fi @@ -192,8 +194,8 @@ jobs: run: | cd _site - # Minify the interceptor script for injection - INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | tr '\n' ' ' | sed 's/ */ /g') + # Minify the interceptor script and replace placeholder with actual path prefix + INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | sed "s/__PATH_PREFIX__/$PATH_PREFIX/g" | tr '\n' ' ' | sed 's/ */ /g') # Create script tag echo "" > /tmp/interceptor.txt @@ -203,7 +205,7 @@ jobs: perl -i -pe 'BEGIN{open(F,"/tmp/interceptor.txt");$s=;chomp $s;close F} s//$s/' "$htmlfile" 2>/dev/null || true done - MODIFIED=$(grep -l 'commerce-testing' commerce/testing/*.html 2>/dev/null | wc -l | tr -d ' ') + MODIFIED=$(grep -l "$PATH_PREFIX" commerce/testing/*.html 2>/dev/null | wc -l | tr -d ' ') echo "āœ“ Interceptor injected into $MODIFIED files" - name: Create root redirect From 0a6def2cc88311188b7ac44a43be997c30dc4341 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 17 Dec 2025 12:57:32 -0600 Subject: [PATCH 24/28] Enhance: Add sitePath configuration to package.json and update GitHub Actions workflow to dynamically handle site paths in interceptor and fetch operations --- .github/scripts/gh-pages-interceptor.js | 5 ++- .github/workflows/github-pages-preview.yml | 51 +++++++++++++--------- package.json | 3 ++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/scripts/gh-pages-interceptor.js b/.github/scripts/gh-pages-interceptor.js index 2867377..d68fa32 100644 --- a/.github/scripts/gh-pages-interceptor.js +++ b/.github/scripts/gh-pages-interceptor.js @@ -1,6 +1,7 @@ /* GitHub Pages Path Interceptor for AEM Edge Delivery - Fixes path issues when hosting on GitHub Pages */ (function() { var BASE = "/__PATH_PREFIX__"; + var SITE_PREFIX = "/__SITE_PREFIX__"; var ORIGIN = location.origin; /* URL Normalization - Remove /index.html suffix */ @@ -22,7 +23,7 @@ if ( path.startsWith("/hlx_statics") || path.startsWith("/franklin_assets") || - path.startsWith("/commerce") + path.startsWith(SITE_PREFIX) ) { return ORIGIN + BASE + path; } @@ -34,7 +35,7 @@ !url.startsWith(BASE) && (url.startsWith("/hlx_statics") || url.startsWith("/franklin_assets") || - url.startsWith("/commerce")) + url.startsWith(SITE_PREFIX)) ) { return BASE + url; } diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index 857f2cf..bd54488 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -37,6 +37,17 @@ jobs: ref: ${{ inputs.branch || github.ref }} path: content + - name: Read site config + id: config + run: | + SITE_PATH=$(node -p "require('./content/package.json').config.sitePath") + # Strip leading slash if present, then extract first path segment + SITE_PREFIX=$(echo "$SITE_PATH" | sed 's|^/||' | cut -d'/' -f1) + echo "SITE_PATH=$SITE_PATH" >> $GITHUB_ENV + echo "SITE_PREFIX=$SITE_PREFIX" >> $GITHUB_ENV + echo "site_path=$SITE_PATH" >> $GITHUB_OUTPUT + echo "Site path: $SITE_PATH (prefix: $SITE_PREFIX)" + - name: Clone adp-devsite uses: actions/checkout@v4 with: @@ -96,7 +107,7 @@ jobs: done # Verify site is accessible - curl -sf "http://localhost:3000/commerce/testing/" > /dev/null && echo "āœ“ Site is accessible" + curl -sf "http://localhost:3000/${SITE_PATH}/" > /dev/null && echo "āœ“ Site is accessible" - name: Generate static site with wget run: | @@ -106,7 +117,7 @@ jobs: # Generate URL list from markdown files cd "$ROOT_DIR/content" find src/pages -name "*.md" | sed 's|src/pages/||' | sed 's|\.md$||' | sed 's|/index$|/|' | while read path; do - echo "http://localhost:3000/commerce/testing/$path" + echo "http://localhost:3000/${SITE_PATH}/$path" done > "$ROOT_DIR/urls.txt" echo "Crawling $(wc -l < "$ROOT_DIR/urls.txt" | tr -d ' ') pages..." @@ -140,11 +151,11 @@ jobs: - name: Fetch API endpoints run: | cd _site - mkdir -p localhost+3000/commerce/testing + mkdir -p "localhost+3000/${SITE_PATH}" mkdir -p localhost+3000/franklin_assets # Config (for side navigation) - curl -sf "http://localhost:3000/commerce/testing/config" -o localhost+3000/commerce/testing/config && echo "āœ“ config" + curl -sf "http://localhost:3000/${SITE_PATH}/config" -o "localhost+3000/${SITE_PATH}/config" && echo "āœ“ config" # Footer curl -sf "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html && echo "āœ“ footer" @@ -153,17 +164,17 @@ jobs: curl -sf "http://localhost:3000/franklin_assets/product-index-map.json" -o localhost+3000/franklin_assets/product-index-map.json && echo "āœ“ product-index-map" # Site-wide banner - curl -sf "http://localhost:3000/commerce/testing/site-wide-banner.json" -o localhost+3000/commerce/testing/site-wide-banner.json || echo "ā—‹ site-wide-banner (optional)" + curl -sf "http://localhost:3000/${SITE_PATH}/site-wide-banner.json" -o "localhost+3000/${SITE_PATH}/site-wide-banner.json" || echo "ā—‹ site-wide-banner (optional)" - name: Rewrite paths for GitHub Pages run: | cd _site # Rewrite config paths for side-nav filtering - if [ -f "localhost+3000/commerce/testing/config" ]; then - perl -i -pe "s|href=\"/commerce/testing/|href=\"/${PATH_PREFIX}/commerce/testing/|g" localhost+3000/commerce/testing/config - perl -i -pe "s|href=\"/functional-testing-framework/|href=\"/${PATH_PREFIX}/commerce/testing/functional-testing-framework/|g" localhost+3000/commerce/testing/config - perl -i -pe "s|href=\"/guide/|href=\"/${PATH_PREFIX}/commerce/testing/guide/|g" localhost+3000/commerce/testing/config + if [ -f "localhost+3000/${SITE_PATH}/config" ]; then + perl -i -pe "s|href=\"/${SITE_PATH}/|href=\"/${PATH_PREFIX}/${SITE_PATH}/|g" "localhost+3000/${SITE_PATH}/config" + perl -i -pe "s|href=\"/functional-testing-framework/|href=\"/${PATH_PREFIX}/${SITE_PATH}/functional-testing-framework/|g" "localhost+3000/${SITE_PATH}/config" + perl -i -pe "s|href=\"/guide/|href=\"/${PATH_PREFIX}/${SITE_PATH}/guide/|g" "localhost+3000/${SITE_PATH}/config" echo "āœ“ Config paths rewritten" fi @@ -184,9 +195,9 @@ jobs: # The superhero.js expects but we have plain # Wrap superhero images in elements so the background works - if [ -f "commerce/testing/index.html" ]; then + if [ -f "${SITE_PATH}/index.html" ]; then # Find tags in superhero blocks and wrap them in - perl -i -0pe 's|(
.*?
\s*)]+)>(.*?
\s*
)|$1$3|gs' commerce/testing/index.html + perl -i -0pe 's|(
.*?
\s*)]+)>(.*?
\s*
)|$1$3|gs' "${SITE_PATH}/index.html" echo "āœ“ Superhero images wrapped in " fi @@ -194,8 +205,8 @@ jobs: run: | cd _site - # Minify the interceptor script and replace placeholder with actual path prefix - INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | sed "s/__PATH_PREFIX__/$PATH_PREFIX/g" | tr '\n' ' ' | sed 's/ */ /g') + # Minify the interceptor script and replace placeholders with actual values + INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | sed "s/__PATH_PREFIX__/$PATH_PREFIX/g" | sed "s/__SITE_PREFIX__/$SITE_PREFIX/g" | tr '\n' ' ' | sed 's/ */ /g') # Create script tag echo "" > /tmp/interceptor.txt @@ -205,23 +216,23 @@ jobs: perl -i -pe 'BEGIN{open(F,"/tmp/interceptor.txt");$s=;chomp $s;close F} s//$s/' "$htmlfile" 2>/dev/null || true done - MODIFIED=$(grep -l "$PATH_PREFIX" commerce/testing/*.html 2>/dev/null | wc -l | tr -d ' ') + MODIFIED=$(grep -l "$PATH_PREFIX" "${SITE_PATH}"/*.html 2>/dev/null | wc -l | tr -d ' ') echo "āœ“ Interceptor injected into $MODIFIED files" - name: Create root redirect run: | cd _site - cat > index.html << 'EOF' + cat > index.html << EOF - Commerce Testing - Preview - - + Preview + + -

Redirecting to Commerce Testing documentation...

+

Redirecting to documentation...

EOF @@ -243,7 +254,7 @@ jobs: echo "Total files: $(find . -type f | wc -l | tr -d ' ')" echo "HTML files: $(find . -name '*.html' | wc -l | tr -d ' ')" - if [ ! -d "commerce" ]; then + if [ ! -d "${SITE_PATH}" ]; then echo "ERROR: No content generated!" exit 1 fi diff --git a/package.json b/package.json index 3780e78..acd3323 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "type": "git", "url": "https://github.com/AdobeDocs/commerce-testing" }, + "config": { + "sitePath": "commerce/testing" + }, "scripts": { "dev": "node ./dev.mjs", "lint": "npx --yes github:AdobeDocs/adp-devsite-utils runLint -v", From d3bdfd8fabf89380cc193cd3aaa4e68eee9325b7 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Wed, 17 Dec 2025 13:16:47 -0600 Subject: [PATCH 25/28] Enhance: Update GitHub Actions workflow to rewrite config paths and extract unique top-level navigation paths for improved side-nav filtering --- .github/workflows/github-pages-preview.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml index bd54488..3e4135a 100644 --- a/.github/workflows/github-pages-preview.yml +++ b/.github/workflows/github-pages-preview.yml @@ -171,10 +171,19 @@ jobs: cd _site # Rewrite config paths for side-nav filtering - if [ -f "localhost+3000/${SITE_PATH}/config" ]; then - perl -i -pe "s|href=\"/${SITE_PATH}/|href=\"/${PATH_PREFIX}/${SITE_PATH}/|g" "localhost+3000/${SITE_PATH}/config" - perl -i -pe "s|href=\"/functional-testing-framework/|href=\"/${PATH_PREFIX}/${SITE_PATH}/functional-testing-framework/|g" "localhost+3000/${SITE_PATH}/config" - perl -i -pe "s|href=\"/guide/|href=\"/${PATH_PREFIX}/${SITE_PATH}/guide/|g" "localhost+3000/${SITE_PATH}/config" + CONFIG_FILE="localhost+3000/${SITE_PATH}/config" + if [ -f "$CONFIG_FILE" ]; then + # Rewrite the main site path + perl -i -pe "s|href=\"/${SITE_PATH}/|href=\"/${PATH_PREFIX}/${SITE_PATH}/|g" "$CONFIG_FILE" + + # Extract unique top-level nav paths from config.md pages section + # Looks for patterns like [Label](/path/...) and extracts the first directory segment + grep -oE '\]\(/[^/)]+/' ../content/src/pages/config.md | \ + sed 's/](//' | \ + sort -u | while read nav_path; do + perl -i -pe "s|href=\"${nav_path}|href=\"/${PATH_PREFIX}/${SITE_PATH}${nav_path}|g" "$CONFIG_FILE" + done + echo "āœ“ Config paths rewritten" fi From a732a52446d213fbfccaeb16148c2411cb93da62 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Thu, 18 Dec 2025 16:54:44 -0600 Subject: [PATCH 26/28] Refactor: Replace deprecated GitHub Actions workflow with a reusable workflow and update .gitignore --- .github/scripts/gh-pages-interceptor.js | 198 -------------- .github/workflows/deploy-github-pages.yml | 21 ++ .github/workflows/github-pages-preview.yml | 293 --------------------- .gitignore | 3 +- 4 files changed, 23 insertions(+), 492 deletions(-) delete mode 100644 .github/scripts/gh-pages-interceptor.js create mode 100644 .github/workflows/deploy-github-pages.yml delete mode 100644 .github/workflows/github-pages-preview.yml diff --git a/.github/scripts/gh-pages-interceptor.js b/.github/scripts/gh-pages-interceptor.js deleted file mode 100644 index d68fa32..0000000 --- a/.github/scripts/gh-pages-interceptor.js +++ /dev/null @@ -1,198 +0,0 @@ -/* GitHub Pages Path Interceptor for AEM Edge Delivery - Fixes path issues when hosting on GitHub Pages */ -(function() { - var BASE = "/__PATH_PREFIX__"; - var SITE_PREFIX = "/__SITE_PREFIX__"; - var ORIGIN = location.origin; - - /* URL Normalization - Remove /index.html suffix */ - if (location.pathname.endsWith("/index.html")) { - history.replaceState( - null, - "", - location.pathname.replace(/\/index\.html$/, "/") + location.search + location.hash - ); - } - - /* Fix a URL by adding the base path if needed */ - function fix(url) { - if (!url || typeof url !== "string") return null; - - /* Handle full URLs */ - if (url.startsWith(ORIGIN) && !url.includes(BASE)) { - var path = url.substring(ORIGIN.length); - if ( - path.startsWith("/hlx_statics") || - path.startsWith("/franklin_assets") || - path.startsWith(SITE_PREFIX) - ) { - return ORIGIN + BASE + path; - } - } - - /* Handle relative paths */ - if ( - url.startsWith("/") && - !url.startsWith(BASE) && - (url.startsWith("/hlx_statics") || - url.startsWith("/franklin_assets") || - url.startsWith(SITE_PREFIX)) - ) { - return BASE + url; - } - - return null; - } - - /* Intercept fetch() calls */ - var originalFetch = window.fetch; - window.fetch = function(input, options) { - var fixed; - if (typeof input === "string") { - fixed = fix(input); - if (fixed) input = fixed; - } else if (input instanceof Request) { - fixed = fix(input.url); - if (fixed) input = new Request(fixed, input); - } - return originalFetch.call(this, input, options); - }; - - /* Intercept XMLHttpRequest */ - var originalXHROpen = XMLHttpRequest.prototype.open; - XMLHttpRequest.prototype.open = function(method, url) { - var fixed = fix(url); - if (fixed) url = fixed; - return originalXHROpen.apply(this, [method, url].concat([].slice.call(arguments, 2))); - }; - - /* Fix src/href attributes on a DOM element and its children */ - function fixElement(el) { - if (!el || !el.getAttribute) return; - - ["src", "href", "xlink:href"].forEach(function(attr) { - var value = el.getAttribute(attr); - var fixed = fix(value); - if (fixed) el.setAttribute(attr, fixed); - }); - - if (el.querySelectorAll) { - el.querySelectorAll("[src],[href]").forEach(fixElement); - } - } - - /* Watch for dynamically added DOM elements */ - new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - mutation.addedNodes.forEach(function(node) { - if (node.nodeType === 1) fixElement(node); - }); - }); - }).observe(document.documentElement, { childList: true, subtree: true }); - - /* Also fix elements on DOMContentLoaded */ - document.addEventListener("DOMContentLoaded", function() { - fixElement(document.body); - }); - - /* Fix side navigation visibility */ - function fixSideNav() { - var main = document.querySelector("main"); - var template = document.querySelector('meta[name="template"]'); - if ( - main && - main.classList.contains("no-sidenav") && - template && - template.content === "documentation" - ) { - main.classList.remove("no-sidenav"); - } - } - - /* Watch for class changes on main element */ - new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - if (mutation.target.tagName === "MAIN" && mutation.attributeName === "class") { - fixSideNav(); - } - }); - }).observe(document.documentElement, { - attributes: true, - subtree: true, - attributeFilter: ["class"] - }); - - document.addEventListener("DOMContentLoaded", fixSideNav); - setTimeout(fixSideNav, 500); - setTimeout(fixSideNav, 1500); - - /* Filter TOC to show only current section items */ - function filterToc() { - var nav = document.querySelector("#navigation-links"); - if (!nav) return; - - var currentPath = location.pathname.replace(/\/$/, ""); - var bestMatch = null; - var bestLength = 0; - - /* Find the best matching top-level nav item */ - nav.querySelectorAll("a").forEach(function(anchor) { - if (anchor.getAttribute("fullPath")) return; - var href = new URL(anchor.href).pathname.replace(/\/$/, ""); - if (currentPath === href) { - bestMatch = anchor; - bestLength = 999; - } else if (currentPath.startsWith(href + "/") && href.length > bestLength) { - bestMatch = anchor; - bestLength = href.length; - } - }); - - if (!bestMatch) return; - - var topPath = new URL(bestMatch.href).pathname; - var toc = document.querySelector(".side-nav-subpages-section"); - if (!toc) return; - - /* Hide items that don't belong to current section */ - toc.querySelectorAll(":scope > ul li").forEach(function(li) { - var link = li.querySelector(":scope > a"); - if (!link) { - li.classList.add("hidden"); - return; - } - var linkPath = new URL(link.href, ORIGIN).pathname; - if (!linkPath.startsWith(topPath)) { - li.classList.add("hidden"); - } - }); - } - - setTimeout(filterToc, 1000); - setTimeout(filterToc, 2000); - setTimeout(filterToc, 3000); - - /* Fix superhero background image */ - function fixSuperheroBackground() { - var superhero = document.querySelector(".superhero"); - if (!superhero) return; - - /* Check if background is undefined or missing */ - var style = window.getComputedStyle(superhero); - if (style.backgroundImage.includes("undefined")) { - /* Find the img element that should be the background */ - var img = superhero.querySelector("img"); - if (img && img.src && !img.src.includes("undefined")) { - var existingBg = superhero.style.background || ""; - superhero.style.background = - "url(" + img.src + ") center center / cover no-repeat" + - (existingBg ? ", " + existingBg : ", rgb(29, 125, 238)"); - /* Hide the img element since it's now a background */ - img.style.display = "none"; - } - } - } - - document.addEventListener("DOMContentLoaded", fixSuperheroBackground); - setTimeout(fixSuperheroBackground, 500); - setTimeout(fixSuperheroBackground, 1500); -})(); diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml new file mode 100644 index 0000000..ca7c0d0 --- /dev/null +++ b/.github/workflows/deploy-github-pages.yml @@ -0,0 +1,21 @@ +--- +name: Deploy GitHub Pages preview +on: + workflow_dispatch: + inputs: + branch: + description: "Branch to deploy" + type: string + required: true + default: main + +permissions: + contents: read + pages: write + id-token: write + +jobs: + preview: + uses: AdobeDocs/commerce-contributor/.github/workflows/github-pages-preview.yml@main + with: + branch: ${{ inputs.branch || github.ref }} diff --git a/.github/workflows/github-pages-preview.yml b/.github/workflows/github-pages-preview.yml deleted file mode 100644 index 3e4135a..0000000 --- a/.github/workflows/github-pages-preview.yml +++ /dev/null @@ -1,293 +0,0 @@ ---- -name: GitHub Pages preview -on: - workflow_dispatch: - inputs: - branch: - description: "Branch to deploy" - type: string - required: false - default: "" - push: - branches: - - "**/preview**" - - "**/gh-pages**" - - "preview-**" - - "gh-pages-**" - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: pages - cancel-in-progress: false - -jobs: - build: - name: Build - runs-on: ubuntu-latest - env: - PATH_PREFIX: ${{ github.event.repository.name }} - steps: - - name: Checkout content repo - uses: actions/checkout@v4 - with: - ref: ${{ inputs.branch || github.ref }} - path: content - - - name: Read site config - id: config - run: | - SITE_PATH=$(node -p "require('./content/package.json').config.sitePath") - # Strip leading slash if present, then extract first path segment - SITE_PREFIX=$(echo "$SITE_PATH" | sed 's|^/||' | cut -d'/' -f1) - echo "SITE_PATH=$SITE_PATH" >> $GITHUB_ENV - echo "SITE_PREFIX=$SITE_PREFIX" >> $GITHUB_ENV - echo "site_path=$SITE_PATH" >> $GITHUB_OUTPUT - echo "Site path: $SITE_PATH (prefix: $SITE_PREFIX)" - - - name: Clone adp-devsite - uses: actions/checkout@v4 - with: - repository: AdobeDocs/adp-devsite - path: adp-devsite - - - name: Clone devsite-runtime-connector - uses: actions/checkout@v4 - with: - repository: aemsites/devsite-runtime-connector - path: devsite-runtime-connector - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "lts/jod" - - - name: Install dependencies - run: | - cd content && npm install - cd ../adp-devsite && npm install - cd ../devsite-runtime-connector && npm install - - - name: Start development servers - run: | - ROOT_DIR=$(pwd) - - # Start content server (port 3003) - (cd "$ROOT_DIR/content" && npm run dev > "$ROOT_DIR/content-server.log" 2>&1) & - echo $! > /tmp/content.pid - - # Start adp-devsite (port 3000) - (cd "$ROOT_DIR/adp-devsite" && npm run dev > "$ROOT_DIR/devsite-server.log" 2>&1) & - echo $! > /tmp/devsite.pid - - # Start runtime connector (port 3001) - (cd "$ROOT_DIR/devsite-runtime-connector" && npm run dev > "$ROOT_DIR/connector-server.log" 2>&1) & - echo $! > /tmp/connector.pid - - echo "Servers starting in background..." - - - name: Wait for servers to be ready - run: | - echo "Waiting for servers..." - for port in 3000 3003; do - for i in {1..60}; do - if curl -s "http://localhost:$port" > /dev/null 2>&1; then - echo "āœ“ Port $port is ready" - break - fi - if [ $i -eq 60 ]; then - echo "āœ— Port $port timeout" - exit 1 - fi - sleep 1 - done - done - - # Verify site is accessible - curl -sf "http://localhost:3000/${SITE_PATH}/" > /dev/null && echo "āœ“ Site is accessible" - - - name: Generate static site with wget - run: | - ROOT_DIR=$(pwd) - mkdir -p "$ROOT_DIR/_site" - - # Generate URL list from markdown files - cd "$ROOT_DIR/content" - find src/pages -name "*.md" | sed 's|src/pages/||' | sed 's|\.md$||' | sed 's|/index$|/|' | while read path; do - echo "http://localhost:3000/${SITE_PATH}/$path" - done > "$ROOT_DIR/urls.txt" - - echo "Crawling $(wc -l < "$ROOT_DIR/urls.txt" | tr -d ' ') pages..." - - cd "$ROOT_DIR/_site" - wget \ - --input-file="$ROOT_DIR/urls.txt" \ - --page-requisites \ - --adjust-extension \ - --convert-links \ - --restrict-file-names=windows \ - --domains localhost \ - --execute robots=off \ - --wait=0.1 \ - --tries=3 \ - --timeout=30 \ - --quiet \ - 2>&1 || true - - echo "āœ“ wget crawl complete" - - - name: Copy static assets - run: | - cd _site - - # Copy hlx_statics from adp-devsite source - mkdir -p localhost+3000/hlx_statics - cp -r ../adp-devsite/hlx_statics/* localhost+3000/hlx_statics/ - echo "āœ“ Copied $(find localhost+3000/hlx_statics -type f | wc -l | tr -d ' ') static files" - - - name: Fetch API endpoints - run: | - cd _site - mkdir -p "localhost+3000/${SITE_PATH}" - mkdir -p localhost+3000/franklin_assets - - # Config (for side navigation) - curl -sf "http://localhost:3000/${SITE_PATH}/config" -o "localhost+3000/${SITE_PATH}/config" && echo "āœ“ config" - - # Footer - curl -sf "http://localhost:3000/franklin_assets/footer.plain.html" -o localhost+3000/franklin_assets/footer.plain.html && echo "āœ“ footer" - - # Product index map - curl -sf "http://localhost:3000/franklin_assets/product-index-map.json" -o localhost+3000/franklin_assets/product-index-map.json && echo "āœ“ product-index-map" - - # Site-wide banner - curl -sf "http://localhost:3000/${SITE_PATH}/site-wide-banner.json" -o "localhost+3000/${SITE_PATH}/site-wide-banner.json" || echo "ā—‹ site-wide-banner (optional)" - - - name: Rewrite paths for GitHub Pages - run: | - cd _site - - # Rewrite config paths for side-nav filtering - CONFIG_FILE="localhost+3000/${SITE_PATH}/config" - if [ -f "$CONFIG_FILE" ]; then - # Rewrite the main site path - perl -i -pe "s|href=\"/${SITE_PATH}/|href=\"/${PATH_PREFIX}/${SITE_PATH}/|g" "$CONFIG_FILE" - - # Extract unique top-level nav paths from config.md pages section - # Looks for patterns like [Label](/path/...) and extracts the first directory segment - grep -oE '\]\(/[^/)]+/' ../content/src/pages/config.md | \ - sed 's/](//' | \ - sort -u | while read nav_path; do - perl -i -pe "s|href=\"${nav_path}|href=\"/${PATH_PREFIX}/${SITE_PATH}${nav_path}|g" "$CONFIG_FILE" - done - - echo "āœ“ Config paths rewritten" - fi - - - name: Organize output structure - run: | - cd _site - - # Move content from localhost+3000 to root - if [ -d "localhost+3000" ]; then - mv localhost+3000/* . 2>/dev/null || true - rm -rf localhost+3000 - echo "āœ“ Output structure organized" - fi - - - name: Fix superhero block images - run: | - cd _site - - # The superhero.js expects but we have plain - # Wrap superhero images in elements so the background works - if [ -f "${SITE_PATH}/index.html" ]; then - # Find tags in superhero blocks and wrap them in - perl -i -0pe 's|(
.*?
\s*)]+)>(.*?
\s*
)|$1$3|gs' "${SITE_PATH}/index.html" - echo "āœ“ Superhero images wrapped in " - fi - - - name: Inject GitHub Pages interceptor - run: | - cd _site - - # Minify the interceptor script and replace placeholders with actual values - INTERCEPTOR=$(cat ../content/.github/scripts/gh-pages-interceptor.js | sed "s/__PATH_PREFIX__/$PATH_PREFIX/g" | sed "s/__SITE_PREFIX__/$SITE_PREFIX/g" | tr '\n' ' ' | sed 's/ */ /g') - - # Create script tag - echo "" > /tmp/interceptor.txt - - # Inject into all HTML files - find . -name "*.html" -type f | while read htmlfile; do - perl -i -pe 'BEGIN{open(F,"/tmp/interceptor.txt");$s=;chomp $s;close F} s//$s/' "$htmlfile" 2>/dev/null || true - done - - MODIFIED=$(grep -l "$PATH_PREFIX" "${SITE_PATH}"/*.html 2>/dev/null | wc -l | tr -d ' ') - echo "āœ“ Interceptor injected into $MODIFIED files" - - - name: Create root redirect - run: | - cd _site - cat > index.html << EOF - - - - - Preview - - - - -

Redirecting to documentation...

- - - EOF - echo "āœ“ Root redirect created" - - - name: Stop servers - if: always() - run: | - for pidfile in /tmp/content.pid /tmp/devsite.pid /tmp/connector.pid; do - if [ -f "$pidfile" ]; then - kill $(cat "$pidfile") 2>/dev/null || true - fi - done - - - name: Verify build output - run: | - cd _site - echo "=== Build Summary ===" - echo "Total files: $(find . -type f | wc -l | tr -d ' ')" - echo "HTML files: $(find . -name '*.html' | wc -l | tr -d ' ')" - - if [ ! -d "${SITE_PATH}" ]; then - echo "ERROR: No content generated!" - exit 1 - fi - - echo "āœ“ Build verification passed" - - - name: Setup Pages - uses: actions/configure-pages@v5 - - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: _site - - deploy: - name: Deploy - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - outputs: - page_url: ${{ steps.deployment.outputs.page_url }} - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore index d0d083c..3985e46 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .history .idea .editorconfig +.cursor # npm node_modules @@ -31,4 +32,4 @@ super-linter.log github_conf # local dev -tmp \ No newline at end of file +tmp From b45b0808dfb92d307bed801204d5d9dc91aff88f Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Thu, 18 Dec 2025 16:58:19 -0600 Subject: [PATCH 27/28] Testing: Add push trigger to GitHub Pages deployment workflow for testing --- .github/workflows/deploy-github-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml index ca7c0d0..eb9c1a7 100644 --- a/.github/workflows/deploy-github-pages.yml +++ b/.github/workflows/deploy-github-pages.yml @@ -1,6 +1,7 @@ --- name: Deploy GitHub Pages preview on: + push: workflow_dispatch: inputs: branch: From 0723bfbc234d5079372096f0b4ec6d970c05b1bd Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Thu, 18 Dec 2025 17:05:52 -0600 Subject: [PATCH 28/28] Remove push trigger from GitHub Pages deployment workflow, allowing manual dispatch only --- .github/workflows/deploy-github-pages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-github-pages.yml b/.github/workflows/deploy-github-pages.yml index eb9c1a7..ca7c0d0 100644 --- a/.github/workflows/deploy-github-pages.yml +++ b/.github/workflows/deploy-github-pages.yml @@ -1,7 +1,6 @@ --- name: Deploy GitHub Pages preview on: - push: workflow_dispatch: inputs: branch: