Skip to content

Commit da25746

Browse files
authored
Merge 602ba25 into adc36b9
2 parents adc36b9 + 602ba25 commit da25746

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

site/Makefile

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ execute:
165165
quarto render --profile "$$PROFILE" "$$FILE_PATH"; \
166166
rm $$env_file '
167167

168+
# Generate sitemap for the site
168169
# Generate sitemap for the site
169170
generate-sitemap:
171+
$(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
172+
$(eval BRANCH := $(if $(filter HEAD,$(BRANCH)),$(or $(GITHUB_HEAD_REF),$(GITHUB_REF_NAME)),$(BRANCH)))
173+
$(eval BASE_URL := $(if $(filter main staging prod,$(BRANCH)),https://docs.validmind.ai,https://docs-demo.vm.validmind.ai))
174+
$(eval PATH_PREFIX := $(if $(filter main staging prod,$(BRANCH)),,pr_previews/$(BRANCH)/))
170175
@echo "Generating sitemaps ..."
171176
@find _site -name "*.html" -not -path "*/internal/*" -not -path "*/site_libs/*" -not -path "*/sitemap.html/*" -not -path "*/training.html/*" | while read -r file; do \
172177
url_path=$$(echo "$$file" | sed 's|^_site/||'); \
@@ -175,31 +180,29 @@ generate-sitemap:
175180
else \
176181
lastmod=$$(stat -c "%y" "$$file" | sed 's/ /T/;s/$$/Z/'); \
177182
fi; \
178-
printf " <url>\n <loc>https://docs-demo.vm.validmind.ai/pr_previews/$(GIT_BRANCH)/%s</loc>\n <lastmod>%s</lastmod>\n <changefreq>weekly</changefreq>\n <priority>0.8</priority>\n </url>\n" "$$url_path" "$$lastmod" >> sitemap.xml.tmp; \
183+
printf " <url>\n <loc>$(BASE_URL)/$(PATH_PREFIX)%s</loc>\n <lastmod>%s</lastmod>\n <changefreq>weekly</changefreq>\n <priority>0.8</priority>\n </url>\n" "$$url_path" "$$lastmod" >> sitemap.xml.tmp; \
179184
printf "%s\n" "$$url_path" >> sitemap.urls.tmp; \
180185
done
181186
@printf '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' > _site/sitemap.xml
182187
@cat sitemap.xml.tmp >> _site/sitemap.xml
183188
@printf '</urlset>\n' >> _site/sitemap.xml
184189
@rm sitemap.xml.tmp
185-
@printf '<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>ValidMind Documentation & Training Sitemap</title>\n <style>\n body { font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; }\n h1 { color: #333; }\n h2 { color: #444; margin-top: 30px; }\n ul { list-style: none; padding: 0; }\n li { margin: 10px 0; }\n a { color: #0066cc; text-decoration: none; }\n a:hover { text-decoration: underline; }\n .root-pages { margin-bottom: 30px; }\n </style>\n</head>\n<body>\n <div class="root-pages">\n <h2>Root Pages</h2>\n <ul>\n' > _site/sitemap.html
186-
@# Deduplicate URLs before processing
187-
@sort -u sitemap.urls.tmp > sitemap.urls.unique.tmp
188-
@mv sitemap.urls.unique.tmp sitemap.urls.tmp
189-
@grep -E '^(index|404)\.html$$' sitemap.urls.tmp | while read -r url; do \
190+
191+
@printf '<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>ValidMind Documentation & Training Sitemap</title>\n <style>\n body { font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; }\n h1 { color: #333; }\n h2 { color: #444; margin-top: 30px; }\n ul { list-style: none; padding: 0; }\n li { margin: 10px 0; }\n a { color: #0066cc; text-decoration: none; }\n a:hover { text-decoration: underline; }\n .root-pages { margin-bottom: 30px; }\n </style>\n</head>\n<body>\n <div class="root-pages">\n <h2>Root Pages</h2>\n <ul>\n' > _site/sitemap.html; \
192+
sort -u sitemap.urls.tmp > sitemap.urls.unique.tmp && mv sitemap.urls.unique.tmp sitemap.urls.tmp; \
193+
grep -E '^(index|404)\.html$$' sitemap.urls.tmp | while read -r url; do \
190194
file="_site/$$url"; \
191195
if [ -f "$$file" ] && grep -q '<title>' "$$file"; then \
192196
title=$$(grep -m1 '<title>' "$$file" | sed 's/.*<title>\(.*\)<\/title>.*/\1/'); \
193197
else \
194198
title="$$url"; \
195199
fi; \
196200
if [ "$$title" != "Redirect" ]; then \
197-
printf " <li><a href=\"https://docs-demo.vm.validmind.ai/pr_previews/$(GIT_BRANCH)/%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
201+
printf " <li><a href=\"$(BASE_URL)/$(PATH_PREFIX)%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
198202
fi; \
199-
done
200-
@printf ' </ul>\n </div>\n' >> _site/sitemap.html
201-
@# Group remaining pages by top-level directory
202-
@for dir in $$(grep -v -E '^(index|404)\.html$$' sitemap.urls.tmp | cut -d/ -f1 | grep -vE '\.(html|xml)$$' | sort -u); do \
203+
done; \
204+
printf ' </ul>\n </div>\n' >> _site/sitemap.html; \
205+
for dir in $$(grep -v -E '^(index|404)\.html$$' sitemap.urls.tmp | cut -d/ -f1 | grep -vE '\.(html|xml)$$' | sort -u); do \
203206
printf ' <h2>%s/</h2>\n <ul>\n' "$$dir" >> _site/sitemap.html; \
204207
grep -E "^$$dir/[^/]+\.html$$" sitemap.urls.tmp | while read -r url; do \
205208
file="_site/$$url"; \
@@ -209,7 +212,7 @@ generate-sitemap:
209212
title="$$url"; \
210213
fi; \
211214
if [ "$$title" != "Redirect" ]; then \
212-
printf " <li><a href=\"https://docs-demo.vm.validmind.ai/pr_previews/$(GIT_BRANCH)/%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
215+
printf " <li><a href=\"$(BASE_URL)/$(PATH_PREFIX)%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
213216
fi; \
214217
done; \
215218
for sub in $$(grep -E "^$$dir/" sitemap.urls.tmp | grep -o -E "^$$dir/[^/]+/" | sed "s|^$$dir/||;s|/||" | sort -u); do \
@@ -222,17 +225,19 @@ generate-sitemap:
222225
title="$$url"; \
223226
fi; \
224227
if [ "$$title" != "Redirect" ]; then \
225-
printf " <li><a href=\"https://docs-demo.vm.validmind.ai/pr_previews/$(GIT_BRANCH)/%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
228+
printf " <li><a href=\"$(BASE_URL)/$(PATH_PREFIX)%s\">%s</a></li>\n" "$$url" "$$title" >> _site/sitemap.html; \
226229
fi; \
227230
done; \
228231
printf ' </ul>\n </li>\n' >> _site/sitemap.html; \
229232
done; \
230233
printf ' </ul>\n' >> _site/sitemap.html; \
231-
done
232-
@printf '</body>\n</html>\n' >> _site/sitemap.html
234+
done; \
235+
printf '</body>\n</html>\n' >> _site/sitemap.html
233236
@rm sitemap.urls.tmp
234237
@echo "Sitemaps generated at _site/sitemap.xml and _site/sitemap.html"
235238

239+
240+
236241
# Get all source files
237242
get-source: clean clone copy-installation notebooks python-docs test-descriptions
238243

0 commit comments

Comments
 (0)