diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 83575b0e0568..bb9412fac3ac 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,18 +15,21 @@ jobs: run: | JEKYLL_ENV=development if [ "${{ github.ref }}" = "refs/heads/master" ]; then + DOCS_URL="https://docs-stage.docker.com" DOCS_S3_HOST="docs.docker.com-stage-us-east-1" DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-stage-cache-invalidator" DOCS_SLACK_MSG="Successfully promoted docs-stage from master. https://docs-stage.docker.com/" DOCS_WEBCONFIG="_website-config-docs-stage.json" elif [ "${{ github.ref }}" = "refs/heads/published" ]; then JEKYLL_ENV=production + DOCS_URL="https://docs.docker.com" DOCS_S3_HOST="docs.docker.com-us-east-1" DOCS_AWS_LAMBDA="arn:aws:lambda:us-east-1:710015040892:function:docs-cache-invalidator" DOCS_SLACK_MSG="Successfully published docs. https://docs.docker.com/" DOCS_WEBCONFIG="_website-config-docs.json" fi echo "JEKYLL_ENV=$JEKYLL_ENV" >> $GITHUB_ENV + echo "DOCS_URL=$DOCS_URL" >> $GITHUB_ENV echo "DOCS_S3_HOST=$DOCS_S3_HOST" >> $GITHUB_ENV echo "DOCS_AWS_LAMBDA=$DOCS_AWS_LAMBDA" >> $GITHUB_ENV echo "DOCS_SLACK_MSG=$DOCS_SLACK_MSG" >> $GITHUB_ENV diff --git a/Dockerfile b/Dockerfile index ac8204b96e97..b11c6b0c9ce3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ARG RUBY_VERSION=2.6.10 ARG BUNDLER_VERSION=2.3.13 ARG JEKYLL_ENV=development -ARG DOMAIN=docs.docker.com +ARG DOCS_URL=http://localhost:4000 # Base stage for building FROM ruby:${RUBY_VERSION}-alpine AS base @@ -44,7 +44,7 @@ COPY --from=vendored /out / # After building with jekyll, fix up some links FROM gem AS generate ARG JEKYLL_ENV -ARG DOMAIN +ARG DOCS_URL ENV TARGET=/out RUN --mount=type=bind,target=.,rw \ --mount=type=cache,target=/src/.jekyll-cache </#https://${DOMAIN}/#' "${TARGET}/sitemap.xml" ) else ( @@ -64,7 +63,7 @@ else ) fi find ${TARGET} -type f -name '*.html' | while read i; do - sed -i 's#\(]* href="\)https://${DOMAIN}/#\1/#g' "$i" + sed -i 's#\(]* href="\)${DOCS_URL}/#\1/#g' "$i" done EOT diff --git a/_config.yml b/_config.yml index 64d8aca0a05e..e59b88fe3c2d 100644 --- a/_config.yml +++ b/_config.yml @@ -63,11 +63,11 @@ compose_switch_version: "1.0.4" min_api_threshold: 1.40 # List of plugins to enable for local development builds. Mostly the same as -# for production, but without the "jekyll-sitemap" plugin, which is not needed -# for previewing, and excluding saves some time to build +# for production. plugins: - jekyll-redirect-from - jekyll-relative-links + - jekyll-sitemap # Assets # @@ -96,7 +96,6 @@ defaults: type: "pages" values: layout: docs - sitemap: false toc_min: 2 toc_max: 4 diff --git a/_plugins/update_sitemap.rb b/_plugins/update_sitemap.rb new file mode 100644 index 000000000000..667b8f73d5b5 --- /dev/null +++ b/_plugins/update_sitemap.rb @@ -0,0 +1,19 @@ +Jekyll::Hooks.register :site, :post_write do |site| + beginning_time = Time.now + Jekyll.logger.info "Starting plugin update_sitemap.rb..." + + sitemap_path = File.join(site.dest, 'sitemap.xml') + # DEPLOY_URL is from Netlify for preview of sitemap on PR + # https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata + docs_url = ENV['DEPLOY_URL'] || ENV['DOCS_URL'] || 'http://localhost:4000' + + if File.exist?(sitemap_path) + sitemap_file = File.read(sitemap_path) + replace = sitemap_file.gsub!("/", "#{docs_url}/") + Jekyll.logger.info " Replacing '/' with '#{docs_url}/' in #{sitemap_path}" + File.open(sitemap_path, "w") { |file| file.puts replace } + end + + end_time = Time.now + Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds" +end diff --git a/docker-bake.hcl b/docker-bake.hcl index d058256271e7..f07338530fea 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,16 +1,24 @@ variable "JEKYLL_ENV" { default = "development" } +variable "DOCS_URL" { + default = "http://localhost:4000" +} + +target "_common" { + args = { + JEKYLL_ENV = JEKYLL_ENV + DOCS_URL = DOCS_URL + } +} group "default" { targets = ["release"] } target "release" { + inherits = ["_common"] target = "release" - args = { - JEKYLL_ENV = JEKYLL_ENV - } no-cache-filter = ["generate"] output = ["./_site"] } @@ -21,9 +29,7 @@ target "vendor" { } target "htmlproofer" { + inherits = ["_common"] target = "htmlproofer" - args = { - JEKYLL_ENV = JEKYLL_ENV - } output = ["type=cacheonly"] } diff --git a/docker-compose.yml b/docker-compose.yml index 7d5ab9d730b5..6e9c5f8f5dfe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: build: args: - JEKYLL_ENV + - DOCS_URL context: . image: docs/docstage ports: diff --git a/sitemap.xsl b/sitemap.xsl new file mode 100644 index 000000000000..95ce53b1c949 --- /dev/null +++ b/sitemap.xsl @@ -0,0 +1,81 @@ + + + + + + + Docker Docs XML Sitemap + + + + +

Docker Docs XML Sitemap

+
+

This is an XML Sitemap which is supposed to be processed by search engines like Google, Bing, ...

+

You can find more information about XML sitemaps on sitemaps.org and Google's list of sitemap programs.

+

This sitemap contains URLs.

+
+
+ + + + + + + + + high + + + + + +
LocationLast Modification
+ + + + + + + + +
+
+ + +
+