@@ -38,9 +38,38 @@ RUN git clone --depth 1 https://www.github.com/docker/docker.github.io archive_s
3838 && git --git-dir=./archive_source/.git --work-tree=./archive_source checkout ${VER} \
3939 && mkdir -p target/${VER} \
4040 && jekyll build -s archive_source -d target/${VER} \
41- && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="/#href="/' "$VER" '/#g' \
42- && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="/#src="/' "$VER" '/#g' \
43- && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="https://docs.docker.com/#href="/' "$VER" '/#g' ; \
41+ # Replace / rewrite some URLs so that links in the archive go to the correct
42+ # location. Note that the order in which these replacements are done is
43+ # important. Changing the order may result in replacements being done
44+ # multiple times.
45+ # First, remove the domain from URLs that include the domain
46+ && BASEURL="$VER/" \
47+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="http://docs-stage.docker.com/#href="/#g' \
48+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="https://docs-stage.docker.com/#src="/#g' \
49+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="https://docs.docker.com/#href="/#g' \
50+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="https://docs.docker.com/#src="/#g' \
51+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="http://docs.docker.com/#href="/#g' \
52+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="http://docs.docker.com/#src="/#g' \
53+ \
54+ # Substitute https:// for schema-less resources (src="//analytics.google.com")
55+ # We're replacing them to prevent them being seen as absolute paths below
56+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="//#href="https://#g' \
57+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="//#src="https://#g' \
58+ \
59+ # And some archive versions already have URLs starting with '/version/'
60+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="/' "$BASEURL" '#href="/#g' \
61+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="/' "$BASEURL" '#src="/#g' \
62+ \
63+ # Archived versions 1.7 and under use some absolute links, and v1.10 uses
64+ # "relative" links to sources (href="./css/"). Remove those to make them
65+ # work :)
66+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="\. /#href="/#g' \
67+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="\. /#src="/#g' \
68+ \
69+ # Create permalinks for archived versions
70+ \
71+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="/#href="/' "$BASEURL" '#g' \
72+ && find target/${VER} -type f -name '*.html' -print0 | xargs -0 sed -i 's#src="/#src="/' "$BASEURL" '#g' ; \
4473 done; \
4574 rm -rf archive_source
4675
0 commit comments