Skip to content

Commit

Permalink
Reduce sitemap size
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jan 17, 2024
1 parent f1b1f17 commit 385178d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions scripts/build-docc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ if test "$BUILD_SYMBOLS" == 1; then
fi

# Build documentation
mkdir -p $OUTPUT_PATH
rm -rf ${OUTPUT_PATH:?}/*
mkdir -p "$OUTPUT_PATH"
rm -rf "${OUTPUT_PATH:?}"/*
$DOCC convert Hummingbird.docc \
--transform-for-static-hosting \
--hosting-base-path /"$HUMMINGBIRD_VERSION" \
--fallback-display-name Hummingbird \
--fallback-bundle-identifier com.opticalaberration.hummingbird \
--fallback-bundle-version 1 \
--additional-symbol-graph-dir $HB_SG_FOLDER \
--output-path $OUTPUT_PATH \
--output-path "$OUTPUT_PATH" \
--hosting-base-path /hummingbird-docs/"$HUMMINGBIRD_VERSION"
# copy root files template to docs file
rsync -trv scripts/docsTemplate/* $BASE_OUTPUT_PATH
31 changes: 17 additions & 14 deletions scripts/build-sitemap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,42 @@ BASE_PATH=docs/hummingbird-docs/

pushd "$BASE_PATH"

FILES=$(find $DOCUMENTATION_PATH -name 'index.html' -print)
FILES=$(find "$DOCUMENTATION_PATH" -name 'index.html' -print)

cat > sitemap.xml << EOF
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
EOF

# Calculate the minimum number of slashes in a file
minSlashes=100
for FILE in $FILES; do
slashCount=$(echo $FILE | text.count "/")
minSlashes=$(($minSlashes>$slashCount ? $slashCount : $minSlashes))
done
slashCount=$(echo "$DOCUMENTATION_PATH" | text.count "/")
minSlashes=$(($slashCount + 2))

for FILE in $FILES; do
URL=$(echo ${FILE%index.html} | sed 's/:/%3A/g')
URL=$(echo "${FILE%index.html}" | sed 's/:/%3A/g')
# work out priority, by counting slashes in filename, subtract the minimum
# number of slashes, calculate 2 to the power of the resulting number and
# invert it
slashCount=$(echo $FILE | text.count "/")
slashCount=$(echo "$FILE" | text.count "/")
slashCount=$(($slashCount - $minSlashes))
slashCount=$(($slashCount>0 ? $slashCount : 0))
inv_priority=$((2 ** $slashCount))
priority=$(bc <<< "scale=2; 1/$inv_priority" )

DATE=$(date -r $FILE "+%Y-%m-%d")
cat >> sitemap.xml << EOF
# only include pages which are modules or top level types
if [ "$slashCount" -lt 2 ]; then
# Give Hummingbird page higher priority than anything else
if [[ "$URL" == */hummingbird/ ]]; then
priority=1.0
else
inv_priority=$((2 ** $slashCount))
priority=$(bc <<< "scale=2; 0.8/$inv_priority" )
fi
DATE=$(date -r "$FILE" "+%Y-%m-%d")
cat >> sitemap.xml << EOF
<url>
<loc>$URL_PREFIX/$URL</loc>
<lastmod>$DATE</lastmod>
<priority>$priority</priority>
</url>
EOF
fi
done
cat >> sitemap.xml << EOF
</urlset>
Expand Down

0 comments on commit 385178d

Please sign in to comment.