Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions _scripts/download-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
34 changes: 29 additions & 5 deletions _scripts/otp_add_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
# List of html tags added:
#
# - <meta name="exdoc:full-text-search-url" \\
# content="/doc/search.html?v=${MAJOR_VSN}&q=">
# content="/doc/search.html?v=${MAJOR_VSN}&q="> (ex_doc < v0.39.0)
#
# - <meta name="major-vsn" content="${MAJOR_VSN}">
#
# - <meta name="exdoc:autocomplete" content="off">
#
# - <link rel="canonical" href="https://www.erlang.org/doc/(...)"/>
#
# 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
Expand All @@ -26,10 +29,31 @@ CANONICAL_URL="https://www.erlang.org/doc/"


_fixup_search_link() {
META_FULL_TEXT_SEARCH="<meta name=\"exdoc:full-text-search-url\""
EXDOC_SEARCH=$(grep "${META_FULL_TEXT_SEARCH}" "$1" || echo "")
if [ ! "$(echo "$EXDOC_SEARCH" | wc -w)" -gt "0" ]; then
sed 's@\s*<title>@'"${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='<meta name="generator" content="ExDoc v([0-9]+)\.([0-9]+)\.([0-9]+)">'

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 name=\"exdoc:full-text-search-url\""
EXDOC_SEARCH=$(grep "${META_FULL_TEXT_SEARCH}" "$1" || echo "")
if [ ! "$(echo "$EXDOC_SEARCH" | wc -w)" -gt "0" ]; then
sed 's@\s*<title>@'"${META_FULL_TEXT_SEARCH}"' content="/doc/search.html?v='"${MAJOR_VSN}"'\&q=">\n&@g' -i -- "$1"
fi
fi
}

Expand Down
Loading