diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000..0caf823 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,61 @@ +# Deploy preview of the website for PRs +name: Deploy PR Previews + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - closed + workflow_dispatch: + +concurrency: preview-${{ github.ref }} + +permissions: + contents: read + pages: write + actions: write + +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Hugo CLI + run: | + wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.128.0/hugo_extended_0.128.0_linux-amd64.deb \ + && sudo dpkg -i hugo.deb + + - name: Install Node.js dependencies + run: | + if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci; else npm install; fi + + - name: Build Hugo Site + if: github.event.action != 'closed' + env: + HUGO_ENVIRONMENT: preview + run: | + echo "Building site with baseURL: https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" + hugo --environment preview --baseURL "https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" --minify -d public + + - name: List Public Directory + if: github.event.action != 'closed' + run: | + echo "Contents of the public directory:" + ls -R public + + - name: Check Base URL in Generated HTML + if: github.event.action != 'closed' + run: | + echo "Checking base URL in generated HTML files:" + grep -r "https://${{ github.repository_owner }}.github.io/${{ github.repository }}/pr-preview/pr-${{ github.event.number }}/" public || echo "Base URL not found in some files" + + - name: Deploy PR Preview + uses: rossjrw/pr-preview-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + source-dir: ./public + action: auto \ No newline at end of file diff --git a/hugo.yaml b/hugo.yaml index 95cb9b4..5d69fd5 100644 --- a/hugo.yaml +++ b/hugo.yaml @@ -2,7 +2,7 @@ baseURL: https://neurodatawithoutborders.github.io/ languageCode: en title: Neurodata Without Borders paginate: 6 -# Markup +# Markup markup: goldmark: renderer: @@ -12,3 +12,8 @@ module: mounts: - source: assets target: assets + +# Environment-specific settings +environments: + preview: + baseURL: https://neurodatawithoutborders.github.io/pr-preview/ \ No newline at end of file