diff options
author | Evan Read <eread@gitlab.com> | 2023-03-28 02:05:36 +0300 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2023-03-28 02:05:36 +0300 |
commit | e5dbbccc7d2a97772d1c13b0d1e12c8df3f8ee87 (patch) | |
tree | ebddfd631713ea1b85cfa1ab2341c9d89a2c10a7 | |
parent | f11398dcbccfb51880c3e2209cdff881b96cf885 (diff) | |
parent | f5161be9c2726cee7397682c899aa9de02fbf92b (diff) |
Merge branch 'axil-refactor-sed-normalize' into 'main'
Replace multiple strings at once when normalizing links
See merge request https://gitlab.com/gitlab-org/gitlab-docs/-/merge_requests/3701
Merged-by: Evan Read <eread@gitlab.com>
Approved-by: Sarah German <sgerman@gitlab.com>
Approved-by: Evan Read <eread@gitlab.com>
Co-authored-by: Achilleas Pipinellis <axil@gitlab.com>
-rwxr-xr-x | scripts/normalize-links.sh | 75 |
1 files changed, 26 insertions, 49 deletions
diff --git a/scripts/normalize-links.sh b/scripts/normalize-links.sh index 01ef116d..bfaf2bd7 100755 --- a/scripts/normalize-links.sh +++ b/scripts/normalize-links.sh @@ -50,55 +50,32 @@ fi ## ## Relative URLs ## -echo "Replace relative URLs in $TARGET/$VER for /ee/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/ee/#="/'"$VER"'/ee/#g' - -echo "Replace relative URLs in $TARGET/$VER for /runner/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/runner/#="/'"$VER"'/runner/#g' - -echo "Replace relative URLs in $TARGET/$VER for /omnibus/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/omnibus/#="/'"$VER"'/omnibus/#g' - -echo "Replace relative URLs in $TARGET/$VER for /charts/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/charts/#="/'"$VER"'/charts/#g' - -echo "Replace relative URLs in $TARGET/$VER for /operator/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/operator/#="/'"$VER"'/operator/#g' - -echo "Replace relative URLs in $TARGET/$VER for /assets/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/assets/#="/'"$VER"'/assets/#g' -find "${TARGET}/$VER" -type f -name '*.css' -print0 | xargs -0 "$SED" -i 's#/assets/#/'"$VER"'/assets/#g' -find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 "$SED" -i 's#/assets/#/'"$VER"'/assets/#g' - -echo "Replace relative URLs in $TARGET/$VER for /frontend/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/frontend/#="/'"$VER"'/frontend/#g' - -echo "Replace relative URLs in $TARGET/$VER for /search/" -find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 "$SED" -i 's#/search/#/'"$VER"'/search/#g' - -echo "Replace relative URLs in $TARGET/$VER for /" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#<a href="/">#<a href="/'"$VER"'/">#g' - -echo "Replace relative URLs in $TARGET/$VER for opensearch.xml" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="/opensearch.xml#="/'"$VER"'/opensearch.xml#g' - +echo "=> Replace relative URLs in $TARGET/$VER for HTML files" +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i -e 's|href="/ee/|href="/'"$VER"'/ee/|g' \ + -e 's|href="/runner/|href="/'"$VER"'/runner/|g' \ + -e 's|href="/omnibus/|href="/'"$VER"'/omnibus/|g' \ + -e 's|href="/charts/|href="/'"$VER"'/charts/|g' \ + -e 's|href="/operator/|href="/'"$VER"'/operator/|g' \ + -e 's|href="/assets/|href="/'"$VER"'/assets/|g' \ + -e 's|href="/frontend/|href="/'"$VER"'/frontend/|g' \ + -e 's|<a href="/">|<a href="/'"$VER"'/">|g' \ + -e 's|href="/opensearch.xml|href="/'"$VER"'/opensearch.xml|g' + +echo "=> Replace relative URLs in $TARGET/$VER for CSS files" +find "${TARGET}/$VER" -type f -name '*.css' -print0 | xargs -0 "$SED" -i 's|/assets/|/'"$VER"'/assets/|g' + +echo "=> Replace relative URLs in $TARGET/$VER for JavaScript files" +find "${TARGET}/$VER" -type f -name '*.js' -print0 | xargs -0 "$SED" -i -e 's|/search/|/'"$VER"'/search/|g' \ + -e 's|/assets/|/'"$VER"'/assets/|g' ## ## Full URLs ## -echo "Replace full URLs in $TARGET/$VER for /ee/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="https://docs.gitlab.com/ee/#="/'"$VER"'/ee/#g' - -echo "Replace full URLs in $TARGET/$VER for /runner/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="https://docs.gitlab.com/runner/#="/'"$VER"'/runner/#g' - -echo "Replace full URLs in $TARGET/$VER for /omnibus/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="https://docs.gitlab.com/omnibus/#="/'"$VER"'/omnibus/#g' - -echo "Replace full URLs in $TARGET/$VER for /charts/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="https://docs.gitlab.com/charts/#="/'"$VER"'/charts/#g' - -echo "Replace full URLs in $TARGET/$VER for /operator/" -find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i 's#="https://docs.gitlab.com/operator/#="/'"$VER"'/operator/#g' - -echo "Fix URLs inside the sitemap" -find "${TARGET}/$VER" -type f -name 'sitemap.xml' -print0 | xargs -0 "$SED" -i 's#docs.gitlab.com/#docs.gitlab.com/'"$VER"'/#g' +echo "=> Replace full URLs in $TARGET/$VER for HTML files" +find "${TARGET}/$VER" -type f -name '*.html' -print0 | xargs -0 "$SED" -i -e 's|href="https://docs.gitlab.com/ee/|href="/'"$VER"'/ee/|g' \ + -e 's|href="https://docs.gitlab.com/runner/|href="/'"$VER"'/runner/|g' \ + -e 's|href="https://docs.gitlab.com/omnibus/|href="/'"$VER"'/omnibus/|g' \ + -e 's|href="https://docs.gitlab.com/charts/|href="/'"$VER"'/charts/|g' \ + -e 's|href="https://docs.gitlab.com/operator/|href="/'"$VER"'/operator/|g' + +echo "=> Fix URLs inside the sitemap" +find "${TARGET}/$VER" -type f -name 'sitemap.xml' -print0 | xargs -0 "$SED" -i 's|docs.gitlab.com/|docs.gitlab.com/'"$VER"'/|g' |