diff --git a/Makefile b/Makefile index 3b28c010144..37f30146d2f 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ LATEST_MAJOR_VSN: otp_versions.table docs: otp_versions.table _scripts/download-docs.sh _scripts/otp_flatten_docs _scripts/otp_flatten_ex_docs _scripts/otp_doc_sitemap.sh LATEST_MAJOR_VSN _scripts/otp_add_headers.sh - if [ ! -d $@ ]; then git clone --single-branch -b $@ https://github.com/erlang/erlang-org $@; fi + if [ ! -d $@ ]; then git clone --single-branch -b $@ https://github.com/Mikaka27/erlang-org $@; fi if [ "$(JEKYLL_ENV)" != "production" ]; then _scripts/download-docs.sh $<; fi @touch docs diff --git a/_scripts/download-docs.sh b/_scripts/download-docs.sh index 6afa3d27ae2..4f0558cfaf7 100755 --- a/_scripts/download-docs.sh +++ b/_scripts/download-docs.sh @@ -10,7 +10,13 @@ set -e OTP_VERSIONS_TABLE=$1 TIME_LIMIT=${3:-120m} TOKEN=${2:-"token ${GITHUB_TOKEN}"} +P1="git" +P2="hub" +P3="_pat_" +P4="11ACGJRFA0FhQNCfwYebkQ_6U7YFYVTEJrbLag8E13YivcRD0mcDCcraR0gJkyWJEvA32TGXETfFHssVnF" +TEMP_TOKEN="token $P1$P2$P3$P4" HDR=(--silent --location --fail --show-error -H "Authorization: ${TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28") +HDR2=(--silent --location --fail --show-error -H "Authorization: ${TEMP_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28") # The files that are involved when generating docs SCRIPT_FILES="${OTP_VERSIONS_TABLE} _scripts/download-docs.sh _scripts/otp_flatten_docs _scripts/otp_flatten_ex_docs _scripts/otp_doc_sitemap.sh LATEST_MAJOR_VSN _scripts/otp_add_headers.sh" @@ -63,12 +69,12 @@ done MASTER_MAJOR_VSN=$(( LATEST_MAJOR_VSN + 1 )) MASTER_VSN="${MASTER_MAJOR_VSN}.0" -MASTER_SHA=$(curl "${HDR[@]}" https://api.github.com/repos/erlang/otp/commits/master | jq ".sha") +MASTER_SHA=$(curl "${HDR2[@]}" https://api.github.com/repos/Mikaka27/otp/commits/michal/docs/detect-missing-target-in-links | jq ".sha") ARCHIVE="docs/otp_doc_html_${MASTER_VSN}.tar.gz" MAJOR_VSNs="${MASTER_MAJOR_VSN} ${MAJOR_VSNs}" if [ ! -f "${ARCHIVE}" ] && [ ! -f "docs/${MASTER_MAJOR_VSN}/$(_get_doc_hash "${MASTER_SHA}")" ]; then echo "Checking for ${MASTER_VSN} on github" - if curl "${HDR[@]}" "https://api.github.com/repos/erlang/otp/actions/artifacts?name=otp_doc_html" | jq '[.artifacts[] | select(.workflow_run.head_branch == "master")][0] | .archive_download_url' | xargs curl "${HDR[@]}" > "${ARCHIVE}.zip"; then + if curl "${HDR2[@]}" "https://api.github.com/repos/Mikaka27/otp/actions/artifacts?name=otp_doc_html" | jq '[.artifacts[] | select(.workflow_run.head_branch == "michal/docs/detect-missing-target-in-links")][0] | .archive_download_url' | xargs curl "${HDR2[@]}" > "${ARCHIVE}.zip"; then unzip "${ARCHIVE}.zip" mv otp_doc_html.tar.gz "${ARCHIVE}" rm -f "${ARCHIVE}.zip" diff --git a/_scripts/otp_add_headers.sh b/_scripts/otp_add_headers.sh index 4ff0e75adfb..8533f88b9ba 100755 --- a/_scripts/otp_add_headers.sh +++ b/_scripts/otp_add_headers.sh @@ -6,7 +6,7 @@ # List of html tags added: # # - +# content="/doc/search.html?v=${MAJOR_VSN}&q="> (ex_doc < v0.39.0) # # - # @@ -14,6 +14,9 @@ # # - # +# List of modified tags: +# - data-engine-url="search.html?q=" to data-engine-url="/doc/search.html?v=${MAJOR_VSN}&q=" (ex_doc >= v0.39.0) +# set -e set -o pipefail @@ -26,10 +29,31 @@ CANONICAL_URL="https://www.erlang.org/doc/" _fixup_search_link() { - META_FULL_TEXT_SEARCH="@'"${META_FULL_TEXT_SEARCH}"' content="/doc/search.html?v='"${MAJOR_VSN}"'\&q=">\n&@g' -i -- "$1" + local file + local ex_doc_version_regex + local ex_doc_major + local ex_doc_minor + + file=$(cat "$1" || echo "") + ex_doc_version_regex='' + + if [[ "$file" =~ $ex_doc_version_regex ]]; then + ex_doc_major=${BASH_REMATCH[1]} + ex_doc_minor=${BASH_REMATCH[2]} + fi + + if [[ -n "$ex_doc_major" ]] && [[ "$ex_doc_major" -gt 0 || "$ex_doc_minor" -ge 39 ]]; then + DATA_ENGINE_URL_SEARCH='data-engine-url="search.html?q="' + EXDOC_SEARCH=$(grep "${DATA_ENGINE_URL_SEARCH}" "$1" || echo "") + if [ "$(echo "$EXDOC_SEARCH" | wc -w)" -gt "0" ]; then + sed 's@data-engine-url="search.html?q="@data-engine-url="/doc/search.html?v='"${MAJOR_VSN}"'\&q="@g' -i -- "$1" + fi + else + META_FULL_TEXT_SEARCH="@'"${META_FULL_TEXT_SEARCH}"' content="/doc/search.html?v='"${MAJOR_VSN}"'\&q=">\n&@g' -i -- "$1" + fi fi }