diff --git a/Dockerfile b/Dockerfile index 81523470e3..e8c0da542b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,16 +47,11 @@ ARG JEKYLL_ENV ARG DOCS_URL ENV TARGET=/out RUN --mount=type=bind,target=.,rw \ - --mount=type=cache,target=/src/.jekyll-cache <]* href=\"\)${DOCS_URL}/#\1/#g" "$i" -done EOT # htmlproofer checks for broken links diff --git a/_plugins/fix_swagger.rb b/_plugins/fix_swagger.rb new file mode 100644 index 0000000000..87352b4236 --- /dev/null +++ b/_plugins/fix_swagger.rb @@ -0,0 +1,25 @@ +require 'jekyll' +require 'octopress-hooks' + +require_relative 'util.rb' + +module Jekyll + class FetchRemote < Octopress::Hooks::Site + def post_read(site) + beginning_time = Time.now + Jekyll.logger.info "Starting plugin fix_swagger.rb..." + + files = Dir.glob(%w[./docker-hub/api/*.yaml ./engine/api/*.yaml]) + Jekyll.logger.info " Fixing up #{files.size} swagger file(s)..." + files.each do |f| + Jekyll.logger.info " #{f}" + text = File.read(f) + replace = text.gsub(get_docs_url, "") + File.open(f, "w") { |f2| f2.puts replace } + end + + end_time = Time.now + Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds" + end + end +end diff --git a/_plugins/fix_url.rb b/_plugins/fix_url.rb new file mode 100644 index 0000000000..90f641c4fa --- /dev/null +++ b/_plugins/fix_url.rb @@ -0,0 +1,29 @@ +require 'jekyll' +require 'octopress-hooks' + +require_relative 'util.rb' + +module Jekyll + class FetchRemote < Octopress::Hooks::Site + def post_write(site) + beginning_time = Time.now + Jekyll.logger.info "Starting plugin fix_url.rb..." + + # TODO: use dynamic URL from util.get_docs_url instead of hardcoded one + # but needs to remove first all absolute URLs in our code base. + docs_url = "https://docs.docker.com" + + dest = site.config['destination'] || '_site' + files = Dir.glob("#{dest}/**/*.html") + Jekyll.logger.info " Fixing up URLs in #{files.size} html file(s) to be relative" + files.each do|f| + text = File.read(f) + replace = text.gsub(/(]* href=\")#{docs_url}/, '\1') + File.open(f, "w") { |f2| f2.puts replace } + end + + end_time = Time.now + Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds" + end + end +end diff --git a/_plugins/fix_urls.rb b/_plugins/fix_urls.rb deleted file mode 100644 index 1d96f38ebc..0000000000 --- a/_plugins/fix_urls.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'jekyll' -require 'octopress-hooks' - -module Jekyll - class FetchRemote < Octopress::Hooks::Site - def post_read(site) - beginning_time = Time.now - Jekyll.logger.info "Starting plugin fix_urls.rb..." - - Jekyll.logger.info " Fixing up URLs in swagger files" - Dir.glob(%w[./docker-hub/api/*.yaml ./engine/api/*.yaml]) do |file_name| - Jekyll.logger.info " #{file_name}" - text = File.read(file_name) - replace = text.gsub("https://docs.docker.com", "") - File.open(file_name, "w") { |file| file.puts replace } - end - - end_time = Time.now - Jekyll.logger.info "done in #{(end_time - beginning_time)} seconds" - end - end -end diff --git a/_plugins/update_sitemap.rb b/_plugins/update_sitemap.rb index 667b8f73d5..a3be4a06ed 100644 --- a/_plugins/update_sitemap.rb +++ b/_plugins/update_sitemap.rb @@ -1,16 +1,15 @@ +require_relative 'util.rb' + 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}" + replace = sitemap_file.gsub!("/", "#{get_docs_url}/") + Jekyll.logger.info " Replacing '/' with '#{get_docs_url}/' in #{sitemap_path}" File.open(sitemap_path, "w") { |file| file.puts replace } end diff --git a/_plugins/util.rb b/_plugins/util.rb new file mode 100644 index 0000000000..d8f118d571 --- /dev/null +++ b/_plugins/util.rb @@ -0,0 +1,5 @@ +def get_docs_url + # DEPLOY_URL is from Netlify for preview + # https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata + ENV['DEPLOY_URL'] || ENV['DOCS_URL'] || 'https://docs.docker.com' +end