diff options
author | Sarah German <sgerman@gitlab.com> | 2023-01-25 13:55:59 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2023-01-25 13:55:59 +0300 |
commit | d98ca853a5b291133ca76323616ce3dd9c34693c (patch) | |
tree | 572f74ee7a875995c55e6fc1b8b7dc87b135784c | |
parent | 911830a6ab2fd270880afef8f4735f31b6974bc8 (diff) |
Rename ALGOLIA_SEARCH variable to be more generic
-rw-r--r-- | .gitlab/ci/build-and-deploy.gitlab-ci.yml | 8 | ||||
-rw-r--r-- | .gitlab/ci/docker-images.gitlab-ci.yml | 9 | ||||
-rw-r--r-- | .gitlab/ci/rules.gitlab-ci.yml | 2 | ||||
-rw-r--r-- | Rules | 2 | ||||
-rw-r--r-- | commands/frontend.rb | 2 | ||||
-rw-r--r-- | content/index.erb | 2 | ||||
-rw-r--r-- | doc/docsearch.md | 8 | ||||
-rw-r--r-- | dockerfiles/single.Dockerfile | 6 | ||||
-rw-r--r-- | layouts/default.html | 2 | ||||
-rw-r--r-- | layouts/head.html | 2 | ||||
-rw-r--r-- | layouts/header.html | 3 | ||||
-rw-r--r-- | layouts/home.html | 2 | ||||
-rw-r--r-- | layouts/search.html | 4 | ||||
-rwxr-xr-x | scripts/check-lunr-index.sh | 4 |
14 files changed, 30 insertions, 26 deletions
diff --git a/.gitlab/ci/build-and-deploy.gitlab-ci.yml b/.gitlab/ci/build-and-deploy.gitlab-ci.yml index ce41b369..5028214c 100644 --- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml +++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml @@ -31,7 +31,7 @@ # Create _redirects for Pages redirects - bundle exec rake redirects # Build the Lunr.js search index if needed - - if [[ "$ALGOLIA_SEARCH" == "false" ]]; then node scripts/lunr/preindex.js; fi + - if [[ "$SEARCH_BACKEND" == "lunr" ]]; then node scripts/lunr/preindex.js; fi # Calculate sizes before and after minifying/gzipping the static files (HTML, CSS, JS) - SIZE_BEFORE_MINIFY=$(du -sh public/ | awk '{print $1}') # Minify the assets of the resulting site @@ -62,7 +62,7 @@ compile_prod: - .rules_prod - .build_base variables: - ALGOLIA_SEARCH: 'true' + SEARCH_BACKEND: 'algolia' NANOC_ENV: 'production' script: - !reference [".compile-and-minify-scripts", "script"] @@ -76,7 +76,7 @@ compile_dev: - .rules_dev - .build_base variables: - ALGOLIA_SEARCH: 'false' + SEARCH_BACKEND: 'lunr' script: - !reference [".compile-and-minify-scripts", "script"] - !reference [".gzip-scripts", "script"] @@ -89,7 +89,7 @@ compile_upstream_review_app: - .rules_upstream_review_app - .build_base variables: - ALGOLIA_SEARCH: 'false' + SEARCH_BACKEND: 'lunr' script: - !reference [".compile-and-minify-scripts", "script"] diff --git a/.gitlab/ci/docker-images.gitlab-ci.yml b/.gitlab/ci/docker-images.gitlab-ci.yml index a3d006e5..7058e09b 100644 --- a/.gitlab/ci/docker-images.gitlab-ci.yml +++ b/.gitlab/ci/docker-images.gitlab-ci.yml @@ -169,7 +169,7 @@ image:docs-single: - docker build --build-arg NANOC_ENV=${NANOC_ENV} --build-arg CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} - --build-arg ALGOLIA_SEARCH="true" + --build-arg SEARCH_BACKEND="algolia" --tag $IMAGE_NAME --file $DOCKERFILE . - docker push $IMAGE_NAME @@ -201,7 +201,7 @@ test:image:docs-single: - docker build --build-arg NANOC_ENV=${NANOC_ENV} --build-arg VER=${GITLAB_VERSION} - --build-arg ALGOLIA_SEARCH="true" + --build-arg SEARCH_BACKEND="algolia" --tag $IMAGE_NAME --file $DOCKERFILE . # @@ -225,7 +225,7 @@ image:docs-single-lunrjs: - docker build --build-arg NANOC_ENV=${NANOC_ENV} --build-arg VER=${CI_COMMIT_REF_NAME} - --build-arg ALGOLIA_SEARCH="false" + --build-arg SEARCH_BACKEND="lunr" --tag $IMAGE_NAME --file $DOCKERFILE . - docker push $IMAGE_NAME @@ -255,10 +255,13 @@ test:image:docs-single-lunrjs: - apk add --no-cache -U make bash git - git fetch --all - git checkout -b $GITLAB_VERSION origin/$GITLAB_VERSION + # We can drop the ALGOLIA_SEARCH arg once we target a GITLAB_VERSION >= 15.9. + # See https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3477#note_1251563455 - docker build --build-arg NANOC_ENV=${NANOC_ENV} --build-arg VER=${GITLAB_VERSION} --build-arg ALGOLIA_SEARCH="false" + --build-arg SEARCH_BACKEND="lunr" --tag $IMAGE_NAME --file $DOCKERFILE . - make check-lunr-index diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index ef954738..911c50b9 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -131,7 +131,7 @@ default: rules: - if: $CI_MERGE_REQUEST_ID && $CI_COMMIT_REF_NAME =~ /algolia/ variables: - ALGOLIA_SEARCH: 'true' + SEARCH_BACKEND: 'algolia' - if: '$CI_MERGE_REQUEST_ID' - if: '$CI_COMMIT_BRANCH =~ /docs-preview/' # TODO: Remove once no projects create such branch - if: '$CI_PIPELINE_SOURCE == "schedule" && $CHORES_PIPELINE == "true"' @@ -51,7 +51,7 @@ preprocess do end end - config[:algolia] = ENV['ALGOLIA_SEARCH'] || 'true' + config[:search_backend] = ENV['SEARCH_BACKEND'] || 'algolia' def get_online_versions uri = URI('https://docs.gitlab.com/versions.json') diff --git a/commands/frontend.rb b/commands/frontend.rb index 48ece62f..b144b5ca 100644 --- a/commands/frontend.rb +++ b/commands/frontend.rb @@ -37,7 +37,7 @@ run do |opts, args, cmd| puts "- Copied #{gl_ui_src}/#{filename}" if filename.include?("map") && File.write("#{gl_ui_dest}/#{filename}", File.read("#{root}/#{gl_ui_src}/#{filename}")) end - if ENV['ALGOLIA_SEARCH'] == "false" + if ENV['SEARCH_BACKEND'] == "lunr" lunr_src = "node_modules/lunr/lunr.min.js" puts 'Copying Lunr.js...' puts "- Copied #{lunr_src}" if File.write('public/assets/javascripts/lunr.min.js', File.read("#{root}/#{lunr_src}")) diff --git a/content/index.erb b/content/index.erb index 218bb26e..c9b73e11 100644 --- a/content/index.erb +++ b/content/index.erb @@ -17,7 +17,7 @@ title: GitLab Documentation <h5 class="card-title pb-3 mb-2">Search the docs</h5> <% if @item[:searchbar].nil? %> <% unless @item.identifier.to_s.split('/')[1] == 'search' %> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <div id="docsearch" class="gl-mb-4 gl-display-flex gl-justify-content-center"></div> <% else %> <div class="js-lunr-form"></div> diff --git a/doc/docsearch.md b/doc/docsearch.md index 93638031..7aa3709a 100644 --- a/doc/docsearch.md +++ b/doc/docsearch.md @@ -362,8 +362,10 @@ Production always runs Algolia, but you can build the site with Lunr either loca ### Local environment -You can compile your local Nanoc site to use a specific search backend by setting the `ALGOLIA_SEARCH` environment variable. +You can compile your local Nanoc site to use a specific search backend by setting the `SEARCH_BACKEND` environment variable. -- Use Algolia search: `export ALGOLIA_SEARCH="true"` (or leave this undefined) -- Use Lunr search: `export ALGOLIA_SEARCH="false"` +- Use Algolia search: `export SEARCH_BACKEND="algolia"` (or leave this undefined) +- Use Lunr search: `export SEARCH_BACKEND="lunr"` - If you do not set this variable before compiling, the build will default to Algolia. + +This variable was named `ALGOLIA_SEARCH`, with values of "true" or "false", prior to version 15.9. diff --git a/dockerfiles/single.Dockerfile b/dockerfiles/single.Dockerfile index ec603f79..0308c49e 100644 --- a/dockerfiles/single.Dockerfile +++ b/dockerfiles/single.Dockerfile @@ -26,11 +26,11 @@ COPY --from=minifier /minify /usr/local/bin/minify # Set versions as build args to fetch corresponding branches ARG VER -ARG ALGOLIA_SEARCH +ARG SEARCH_BACKEND ARG NANOC_ENV ENV CI_COMMIT_REF_NAME=$VER -ENV ALGOLIA_SEARCH=$ALGOLIA_SEARCH +ENV SEARCH_BACKEND=$SEARCH_BACKEND ENV NANOC_ENV=$NANOC_ENV # @@ -79,7 +79,7 @@ RUN yarn install --frozen-lockfile \ && bundle exec rake default \ && bundle exec nanoc compile -VV -RUN if [ "$ALGOLIA_SEARCH" = "false" ]; then make build-lunr-index; fi +RUN if [ "$SEARCH_BACKEND" = "lunr" ]; then make build-lunr-index; fi # Move generated HTML to /site RUN mkdir /site \ diff --git a/layouts/default.html b/layouts/default.html index b5684b6d..67085578 100644 --- a/layouts/default.html +++ b/layouts/default.html @@ -94,7 +94,7 @@ </div> </section> <script src="<%= @items['/frontend/shared/global_imports.*'].path %>"></script> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <script src="<%= @items['/frontend/search/docsearch.*'].path %>"></script> <% else %> <script src="<%= @items['/frontend/search/lunrsearch.*'].path %>"></script> diff --git a/layouts/head.html b/layouts/head.html index ab9e4573..f47ef3e2 100644 --- a/layouts/head.html +++ b/layouts/head.html @@ -17,7 +17,7 @@ <% end %> <meta name="gitlab-docs-version" content="<%= site_version %>"> -<% if @config[:algolia] == "true" %> +<% if @config[:search_backend] == "algolia" %> <!--https://community.algolia.com/docsearch/required-configuration.html#introduces-global-information-as-meta-tags--> <meta name="docsearch:language" content="en" /> <meta name="docsearch:version" content="<%= docsearch_version %>" /> diff --git a/layouts/header.html b/layouts/header.html index d3dd9539..9395afe4 100644 --- a/layouts/header.html +++ b/layouts/header.html @@ -12,7 +12,7 @@ <% if @item[:searchbar].nil? %> <% location = @item.identifier.to_s.split('/')[1] %> <% unless %w(search index.erb).any?(location) %> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <div id="docsearch" class="gl-my-3 gl-md-mt-0 gl-md-mb-0"></div> <% else %> <div class="js-lunr-form"></div> @@ -38,4 +38,3 @@ </ul> </div> </nav> - diff --git a/layouts/home.html b/layouts/home.html index c573033d..3b3afc2b 100644 --- a/layouts/home.html +++ b/layouts/home.html @@ -17,7 +17,7 @@ <script src="<%= @items['/frontend/shared/global_imports.*'].path %>"></script> <script src="<%= @items['/frontend/default/default.*'].path %>"></script> <script src="<%= @items['/assets/javascripts/badges.*'].path %>"></script> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <script src="<%= @items['/frontend/search/docsearch.*'].path %>"></script> <% else %> <script src="<%= @items['/frontend/search/lunrsearch.*'].path %>"></script> diff --git a/layouts/search.html b/layouts/search.html index 9d33e0b8..83a35221 100644 --- a/layouts/search.html +++ b/layouts/search.html @@ -3,7 +3,7 @@ <head> <%= render '/head.*' %> <link rel="canonical" href="<%= @config[:base_url] %>/search/"> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <link rel="stylesheet" href="/frontend/search/instantsearch.css"> <script src="<%= @items['/frontend/search/instantsearch.*'].path %>"></script> <% else %> @@ -18,7 +18,7 @@ <div class="row"> <div class="col-12 mt-5"> <div class="main class pl-lg-4"> - <% if @config[:algolia] == "true" %> + <% if @config[:search_backend] == "algolia" %> <div class="js-instantsearch"></div> <% else %> <div class="js-lunrsearch"></div> diff --git a/scripts/check-lunr-index.sh b/scripts/check-lunr-index.sh index 2e368a38..591b1fcd 100755 --- a/scripts/check-lunr-index.sh +++ b/scripts/check-lunr-index.sh @@ -9,7 +9,7 @@ COLOR_RESET="\e[39m" # # - index_check: checks if the lunr.js index is built. There's two files when the # index is built: 'lunr-index.json' and 'lunr-map.json'. -# - dev_check: when ALGOLIA_SEARCH is set to 'false' the div we're looking for +# - dev_check: when SEARCH_BACKEND is set to 'lunr' the div we're looking for # is set to 'js-lunr-form'. Otherwise, it's set to 'docsearch' by default. # This is defined in # https://gitlab.com/gitlab-org/gitlab-docs/-/blob/83ebc0de813c6e916b522a9203a6182d7425dd20/content/index.erb#L20-24. @@ -37,7 +37,7 @@ else then # shellcheck disable=2059 printf "${COLOR_RED}ERROR: lunr.js index is found, but not enabled!\n" - printf " Did you forget to build the site with ALGOLIA_SEARCH='false'?\n" + printf " Did you forget to build the site with SEARCH_BACKEND='lunr'?\n" # shellcheck disable=2059 printf " For more information, see https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/docsearch.md#lunrjs-search${COLOR_RESET}\n" exit 1; |