diff --git a/.ci/lint-docs-source-page.sh b/.ci/lint-docs-source-page.sh index 37b4fdf8cf4e..9311581cd51e 100755 --- a/.ci/lint-docs-source-page.sh +++ b/.ci/lint-docs-source-page.sh @@ -118,4 +118,4 @@ if has_errors: sys.exit(1) print("Success: Source pages validated.") sys.exit(0) -EOF \ No newline at end of file +EOF diff --git a/.ci/lint-docs-tool-page.sh b/.ci/lint-docs-tool-page.sh index 1859c6564c08..9b3cde4089f8 100755 --- a/.ci/lint-docs-tool-page.sh +++ b/.ci/lint-docs-tool-page.sh @@ -132,4 +132,4 @@ if has_errors: sys.exit(1) else: print("Success: All Tool pages passed structure validation.") -EOF \ No newline at end of file +EOF diff --git a/.github/workflows/deploy_dev_docs.yaml b/.github/workflows/deploy_dev_docs.yaml index d71f1db27379..51e20fd19b61 100644 --- a/.github/workflows/deploy_dev_docs.yaml +++ b/.github/workflows/deploy_dev_docs.yaml @@ -69,6 +69,9 @@ jobs: HUGO_BASEURL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/dev HUGO_RELATIVEURLS: false + - name: Build Pagefind Search Index + run: npx pagefind --site public + - name: Create Staging Directory run: | mkdir staging diff --git a/.github/workflows/deploy_previous_version_docs.yaml b/.github/workflows/deploy_previous_version_docs.yaml index e8362536c921..39bd196fa5e2 100644 --- a/.github/workflows/deploy_previous_version_docs.yaml +++ b/.github/workflows/deploy_previous_version_docs.yaml @@ -73,6 +73,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ github.event.inputs.version_tag }} + - name: Build Pagefind Index (Archived Version) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to gh-pages uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: @@ -95,6 +99,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ github.event.inputs.version_tag }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to root uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: @@ -103,4 +111,4 @@ jobs: publish_branch: versioned-gh-pages keep_files: true allow_empty_commit: true - commit_message: "deploy: docs to root for ${{ github.event.inputs.version_tag }}" \ No newline at end of file + commit_message: "deploy: docs to root for ${{ github.event.inputs.version_tag }}" diff --git a/.github/workflows/deploy_previous_version_docs_to_cf.yaml b/.github/workflows/deploy_previous_version_docs_to_cf.yaml index 3a7166b4f571..35b344c942a6 100644 --- a/.github/workflows/deploy_previous_version_docs_to_cf.yaml +++ b/.github/workflows/deploy_previous_version_docs_to_cf.yaml @@ -73,6 +73,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ github.event.inputs.version_tag }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to cloudflare-pages uses: peaceiris/actions-gh-pages@v4 with: @@ -95,6 +99,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ github.event.inputs.version_tag }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to root uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: diff --git a/.github/workflows/deploy_versioned_docs.yaml b/.github/workflows/deploy_versioned_docs.yaml index a7c8300af4db..6decc5738fdd 100644 --- a/.github/workflows/deploy_versioned_docs.yaml +++ b/.github/workflows/deploy_versioned_docs.yaml @@ -63,6 +63,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ steps.get_version.outputs.VERSION }} + - name: Build Pagefind Index (Versioned) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: @@ -84,6 +88,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ steps.get_version.outputs.VERSION }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to root uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: diff --git a/.github/workflows/deploy_versioned_docs_to_cf.yaml b/.github/workflows/deploy_versioned_docs_to_cf.yaml index d3b29c225dbd..cfac34d98c9c 100644 --- a/.github/workflows/deploy_versioned_docs_to_cf.yaml +++ b/.github/workflows/deploy_versioned_docs_to_cf.yaml @@ -63,6 +63,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ steps.get_version.outputs.VERSION }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: @@ -84,6 +88,10 @@ jobs: HUGO_RELATIVEURLS: false HUGO_PARAMS_VERSION: ${{ steps.get_version.outputs.VERSION }} + - name: Build Pagefind Index (Root) + run: npx pagefind --site public + working-directory: .hugo + - name: Deploy to root uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: diff --git a/.github/workflows/docs_preview_deploy.yaml b/.github/workflows/docs_preview_deploy.yaml index fda0e4895f9c..510a2b260dcd 100644 --- a/.github/workflows/docs_preview_deploy.yaml +++ b/.github/workflows/docs_preview_deploy.yaml @@ -17,7 +17,7 @@ name: "docs" permissions: contents: write pull-requests: write - + # This Workflow depends on 'github.event.number', # not compatible with branch or manual triggers. on: @@ -81,6 +81,9 @@ jobs: HUGO_ENVIRONMENT: preview HUGO_RELATIVEURLS: false + - name: Build Pagefind Search Index + run: npx pagefind --site public + - name: Deploy uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 with: diff --git a/.github/workflows/docs_preview_deploy_cf.yaml b/.github/workflows/docs_preview_deploy_cf.yaml index 71a6f7c65c34..b1cc19e3b5b0 100644 --- a/.github/workflows/docs_preview_deploy_cf.yaml +++ b/.github/workflows/docs_preview_deploy_cf.yaml @@ -72,6 +72,9 @@ jobs: HUGO_ENVIRONMENT: preview HUGO_RELATIVEURLS: false + - name: Build Pagefind Search Index + run: npx pagefind --site public + - name: Deploy to Cloudflare Pages via Wrangler id: cf_deploy uses: cloudflare/wrangler-action@v3 diff --git a/.gitignore b/.gitignore index 724bfc3e7d90..fff1611f0cf0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ node_modules # hugo .hugo/public/ .hugo/resources/_gen +.hugo/static/pagefind/ .hugo_build.lock # coverage diff --git a/.hugo/hugo.cloudflare.toml b/.hugo/hugo.cloudflare.toml index d2789ec07a9f..b91baa6983dd 100644 --- a/.hugo/hugo.cloudflare.toml +++ b/.hugo/hugo.cloudflare.toml @@ -49,18 +49,25 @@ ignoreFiles = ["quickstart/shared", "quickstart/python", "quickstart/js", "quick github_repo = "https://github.com/googleapis/genai-toolbox" github_project_repo = "https://github.com/googleapis/genai-toolbox" github_subdir = "docs" - offlineSearch = true + offlineSearch = false version_menu = "Releases" disableMigrationBanner = true releases_url = "/releases.releases" global_logo_url = "/" + pagefind = true version = "Dev" [params.ui] ul_show = 100 showLightDarkModeMenu = true - breadcrumb_disable = true + breadcrumb_disable = false sidebar_menu_foldable = true sidebar_menu_compact = false + [params.ui.feedback] + enable = true + yes = 'Glad to hear it! Please tell us how we can improve.' + no = 'Sorry to hear that. Please tell us how we can improve.' + [params.ui.readingtime] + enable = true [[params.versions]] version = "Dev" @@ -151,3 +158,7 @@ ignoreFiles = ["quickstart/shared", "quickstart/python", "quickstart/js", "quick [outputs] home = ["HTML", "RSS", "LLMS", "LLMS-FULL", "releases"] + +[services] + [services.googleAnalytics] + id = "G-GLSV9KD8BF" diff --git a/.hugo/hugo.toml b/.hugo/hugo.toml index 5af92a191648..cbc825700a04 100644 --- a/.hugo/hugo.toml +++ b/.hugo/hugo.toml @@ -35,17 +35,24 @@ ignoreFiles = ["quickstart/shared", "quickstart/python", "quickstart/js", "quick github_repo = "https://github.com/googleapis/genai-toolbox" github_project_repo = "https://github.com/googleapis/genai-toolbox" github_subdir = "docs" - offlineSearch = true + offlineSearch = false version_menu = "Releases" releases_url = "/genai-toolbox/releases.releases" global_logo_url = "/genai-toolbox/" version = "Dev" + pagefind = true [params.ui] ul_show = 100 showLightDarkModeMenu = true - breadcrumb_disable = true + breadcrumb_disable = false sidebar_menu_foldable = true sidebar_menu_compact = false + [params.ui.feedback] + enable = true + yes = 'Glad to hear it! Please tell us how we can improve.' + no = 'Sorry to hear that. Please tell us how we can improve.' + [params.ui.readingtime] + enable = true [[params.versions]] version = "Dev" @@ -173,3 +180,8 @@ ignoreFiles = ["quickstart/shared", "quickstart/python", "quickstart/js", "quick [outputs] home = ["HTML", "RSS", "LLMS", "LLMS-FULL", "releases"] + +# Google Analytics ID +[services] + [services.googleAnalytics] + id = "G-GLSV9KD8BF" \ No newline at end of file diff --git a/.hugo/layouts/docs/section.html b/.hugo/layouts/docs/section.html index c8d7a5f36fd3..47b41c080af2 100644 --- a/.hugo/layouts/docs/section.html +++ b/.hugo/layouts/docs/section.html @@ -11,8 +11,10 @@

{{ .Title }}

{{ .Content }} {{ partial "section-index.html" . }} {{ partial "pager.html" . }} - {{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable) (.Site.GoogleAnalytics)) }} - {{ partial "feedback.html" .Site.Params.ui.feedback }} + {{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable) (.Site.Config.Services.GoogleAnalytics.ID)) }} +
+
+ {{ partial "feedback.html" . }}
{{ end }} {{ if (.Site.Params.DisqusShortname) }} diff --git a/.hugo/layouts/docs/single.html b/.hugo/layouts/docs/single.html index c8d7a5f36fd3..47b41c080af2 100644 --- a/.hugo/layouts/docs/single.html +++ b/.hugo/layouts/docs/single.html @@ -11,8 +11,10 @@

{{ .Title }}

{{ .Content }} {{ partial "section-index.html" . }} {{ partial "pager.html" . }} - {{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable) (.Site.GoogleAnalytics)) }} - {{ partial "feedback.html" .Site.Params.ui.feedback }} + {{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable) (.Site.Config.Services.GoogleAnalytics.ID)) }} +
+
+ {{ partial "feedback.html" . }}
{{ end }} {{ if (.Site.Params.DisqusShortname) }} diff --git a/.hugo/layouts/partials/search-input.html b/.hugo/layouts/partials/search-input.html new file mode 100644 index 000000000000..4c0eb0a189af --- /dev/null +++ b/.hugo/layouts/partials/search-input.html @@ -0,0 +1,271 @@ +{{ .Scratch.Set "docsy-search" 0 }} + +{{ if .Site.Params.pagefind }} + {{ .Scratch.Add "docsy-search" 1 }} + + + + + + + + + +{{ end }} + +{{ if .Site.Params.offlineSearch }} + {{ .Scratch.Add "docsy-search" 1 }} + +{{ end }} \ No newline at end of file diff --git a/DEVELOPER.md b/DEVELOPER.md index 1063cea3e29d..fb70241743e9 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -473,18 +473,28 @@ Follow these steps to preview documentation changes locally using a Hugo server: npm ci ``` -1. **Start the Server:** +1. **Generate Search Index & Start the Server:** Because the Pagefind search engine requires physical files to build its index, `hugo server` (which runs purely in memory) will not display search results by default. To test the search bar locally, build the physical site once (using the development environment to avoid triggering production analytics), generate the index into the static folder, and then start the server: ```bash + hugo --environment development + npx pagefind --site public --output-path static/pagefind hugo server ``` + *(Note: The `static/pagefind/` directory is git-ignored to prevent committing local search indexes).* ### Previewing Documentation on Pull Requests +Documentation preview links are automatically generated and commented on your pull request when working from a branch within the main repository. + +**For external contributors (forks):** +For security reasons, automated deployment previews are disabled for pull requests originating from external forks for the cloudflare deployments. To review your documentation changes, please follow the [Running a Local Hugo Server](#running-a-local-hugo-server) instructions to build and view the site on your local machine before requesting a review. + ### Document Versioning Setup The documentation uses a dynamic versioning system that outputs standard HTML sites alongside AI-optimized plain text files (`llms.txt` and `llms-full.txt`). +**Search Indexing:** All deployment workflows automatically execute `npx pagefind --site public` to generate a version-scoped search index specific to that deployment's base URL. + There are 6 GHA workflows we use to achieve document versioning (each deployment scenario has one workflow for GitHub Pages and one for Cloudflare Pages): 1. **Deploy In-development docs:** diff --git a/GEMINI.md b/GEMINI.md index b1a045eabe8c..5966fab51d9a 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -57,13 +57,15 @@ This file (symlinked as `CLAUDE.md` and `AGENTS.md`) provides context and guidel 1. Navigate to `.hugo` directory: `cd .hugo` 2. Install dependencies: `npm ci` -3. Start server: `hugo server` +3. **Generate Search Index:** Because Pagefind requires physical files, `hugo server` alone will not populate the search bar. Build the local index first (using the development environment to block analytics) by running: + `hugo --environment development && npx pagefind --site public --output-path static/pagefind` +4. Start server: `hugo server` ### Versioning Workflows Documentation builds automatically generate standard HTML alongside AI-friendly text files (`llms.txt` and `llms-full.txt`). -There are 6 workflows in total, handling parallel deployments to both GitHub Pages and Cloudflare Pages. +There are 6 workflows in total, handling parallel deployments to both GitHub Pages and Cloudflare Pages. **All deployment workflows automatically execute `npx pagefind --site public` to generate version-scoped search indexes.** 1. **Deploy In-development docs**: Commits merged to `main` deploy to the `/dev/` path. Automatically defaults to version `Dev`. 2. **Deploy Versioned Docs**: New GitHub releases deploy to `//` and the root path. The release tag is automatically injected into the build as the documentation version. *(Note: Developers must manually add the new version to the `[[params.versions]]` dropdown array in `hugo.toml` prior to merging a release PR).*