-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathupdateSitemap.sh
More file actions
executable file
·62 lines (48 loc) · 1.69 KB
/
updateSitemap.sh
File metadata and controls
executable file
·62 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
#
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
#
# Check if the required arguments are provided
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <sitemap_file> <api_docs_dir>"
echo "Example: $0 sitemap.xml docs/pages/api"
exit 1
fi
sitemap_file=$1
api_docs_dir=$2
# Check if the files/directories exist
if [ ! -f "$sitemap_file" ]; then
echo "Error: Sitemap file '$sitemap_file' does not exist."
exit 1
fi
if [ ! -d "$api_docs_dir" ]; then
echo "Error: API docs directory '$api_docs_dir' does not exist."
exit 1
fi
# Get the current date in YYYY-MM-DD format
current_date=$(date +%Y-%m-%d)
# Create a temporary file to store the updated sitemap
temp_file=$(mktemp)
# Extract the first line from sitemap file (XML header), removing closing urlset tag if present
head -n 1 "$sitemap_file" | sed -En 's/<\/urlset>//p' > "$temp_file"
# Find all HTML files in the API docs directory recursively
find "$api_docs_dir" -type f -name "*.html" | while read -r html_file; do
# Convert the file path to a URL path (remove the docs/pages/ prefix)
url_path="${html_file/#$api_docs_dir/api}"
# Create the full URL
url="https://kotlin.github.io/kotlinx-rpc/$url_path"
# Add the URL entry to the temporary file
cat >> "$temp_file" << EOF
<url>
<loc>$url</loc>
<lastmod>$current_date</lastmod>
<changefreq>monthly</changefreq>
<priority>0.15</priority>
</url>
EOF
done
# Add the closing tag
echo "</urlset>" >> "$temp_file"
# Replace the original sitemap file with the updated one
mv "$temp_file" "$sitemap_file"
echo "Sitemap updated successfully with entries from $api_docs_dir"