From 2120bd105dd8a2cd649f06960e96fd5b55db0680 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 18 May 2022 18:00:02 +0200 Subject: [PATCH] jekyll: create plugin to update api toc Signed-off-by: CrazyMax --- Dockerfile | 6 ------ _plugins/update_api_toc.rb | 26 ++++++++++++++++++++++++++ _scripts/update-api-toc.sh | 18 ------------------ 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 _plugins/update_api_toc.rb delete mode 100755 _scripts/update-api-toc.sh diff --git a/Dockerfile b/Dockerfile index bf4a0cf956..ac8204b96e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,11 +49,6 @@ ENV TARGET=/out RUN --mount=type=bind,target=.,rw \ --mount=type=cache,target=/src/.jekyll-cache < ${TARGET}/js/metadata.json ) fi - find ${TARGET} -type f -name '*.html' | while read i; do sed -i 's#\(]* href="\)https://${DOMAIN}/#\1/#g' "$i" done diff --git a/_plugins/update_api_toc.rb b/_plugins/update_api_toc.rb new file mode 100644 index 0000000000..c71adbc0f7 --- /dev/null +++ b/_plugins/update_api_toc.rb @@ -0,0 +1,26 @@ +require 'jekyll' +require 'octopress-hooks' + +module Jekyll + + class UpdateApiToc < Octopress::Hooks::Site + def pre_read(site) + beginning_time = Time.now + Jekyll.logger.info "Starting plugin update_api_toc.rb..." + + if File.file?("_config.yml") && File.file?("_data/toc.yaml") + # substitute the "{site.latest_engine_api_version}" in the title for the latest + # API docs, based on the latest_engine_api_version parameter in _config.yml + engine_ver = site.config['latest_engine_api_version'] + toc_file = File.read("_data/toc.yaml") + replace = toc_file.gsub!("{{ site.latest_engine_api_version }}", engine_ver) + Jekyll.logger.info " Replacing '{{ site.latest_engine_api_version }}' with #{engine_ver} in _data/toc.yaml" + File.open("_data/toc.yaml", "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/_scripts/update-api-toc.sh b/_scripts/update-api-toc.sh deleted file mode 100755 index 95608d4824..0000000000 --- a/_scripts/update-api-toc.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# Do some sanity-checking to make sure we are running this from the right place -if ! [ -f _config.yml ]; then - echo "Could not find _config.yml. We may not be in the right place. Bailing." - exit 1 -fi - -# Helper function to deal with sed differences between osx and Linux -# See https://stackoverflow.com/a/38595160 -sedi () { - sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" -} - -# Parse latest_engine_api_version variables from _config.yml to replace the value -# in toc.yaml. This is brittle! -latest_engine_api_version="$(grep 'latest_engine_api_version:' ./_config.yml | grep -oh '"[0-9].*"$' | sed 's/"//g')" -sedi "s/{{ site.latest_engine_api_version }}/${latest_engine_api_version}/g" ./_data/toc.yaml