@@ -165,8 +165,13 @@ execute:
165
165
quarto render --profile " $$ PROFILE" " $$ FILE_PATH" ; \
166
166
rm $$ env_file '
167
167
168
+ # Generate sitemap for the site
168
169
# Generate sitemap for the site
169
170
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 ) /) )
170
175
@echo " Generating sitemaps ..."
171
176
@find _site -name " *.html" -not -path " */internal/*" -not -path " */site_libs/*" -not -path " */sitemap.html/*" -not -path " */training.html/*" | while read -r file; do \
172
177
url_path=$$(echo "$$file" | sed 's|^_site/||' ) ; \
@@ -175,31 +180,29 @@ generate-sitemap:
175
180
else \
176
181
lastmod=$$(stat -c "%y" "$$file" | sed 's/ /T/;s/$$/Z/' ) ; \
177
182
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; \
179
184
printf " %s\n" " $$ url_path" >> sitemap.urls.tmp; \
180
185
done
181
186
@printf ' <?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' > _site/sitemap.xml
182
187
@cat sitemap.xml.tmp >> _site/sitemap.xml
183
188
@printf ' </urlset>\n' >> _site/sitemap.xml
184
189
@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 \
190
194
file="_site/$$url"; \
191
195
if [ -f "$$file" ] && grep -q '<title>' "$$file"; then \
192
196
title=$$(grep -m1 '<title>' "$$file" | sed 's/.*<title>\(.*\)<\/title>.*/\1/'); \
193
197
else \
194
198
title="$$url"; \
195
199
fi; \
196
200
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; \
198
202
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 \
203
206
printf ' <h2>%s/</h2>\n <ul>\n' "$$dir" >> _site/sitemap.html; \
204
207
grep -E "^$$dir/[^/]+\.html$$" sitemap.urls.tmp | while read -r url; do \
205
208
file="_site/$$url"; \
@@ -209,7 +212,7 @@ generate-sitemap:
209
212
title="$$url"; \
210
213
fi; \
211
214
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; \
213
216
fi; \
214
217
done; \
215
218
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:
222
225
title="$$url"; \
223
226
fi; \
224
227
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; \
226
229
fi; \
227
230
done; \
228
231
printf ' </ul>\n </li>\n' >> _site/sitemap.html; \
229
232
done; \
230
233
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
233
236
@rm sitemap.urls.tmp
234
237
@echo "Sitemaps generated at _site/sitemap.xml and _site/sitemap.html"
235
238
239
+
240
+
236
241
# Get all source files
237
242
get-source : clean clone copy-installation notebooks python-docs test-descriptions
238
243
0 commit comments