diff --git a/qsgen2 b/qsgen2 index d71ca8b..4b729fd 100755 --- a/qsgen2 +++ b/qsgen2 @@ -916,20 +916,81 @@ function _sitemap() { _msg main "${0:t}_msg_1" local sm_file="sitemap.xml" + local b_file="sitemap-blogs.xml" + local p_file="sitemap-pages.xml" local sitemap_file="${www_root}/${sm_file}" - #local sitemap_blog="${www_root}/sitemap-blogs.xml" - #local sitemap_page="${www_root}/sitemap-pages.xml" + local sitemap_blog="${www_root}/${b_file}" + local sitemap_page="${www_root}/${p_file}" # Find all HTML files and store them in an array # local -a html_files=("${(@f)$(find "${www_root}" -type f -name "*.html")}") local -a html_files=(${www_root}/**/[a-z]*.html(.)) + local -a blog_files=$(echo ${html_files[@]} | grep blog) + local -a page_files=$(echo ${html_files[@]} | grep -v blog) + local -a xml_files=(${www_root}/[a-z]*.xml(.)) + local -a xml_files=$( echo ${xml_files[@]} | grep -v "sitemap.xml" ) # Working on provinding 2 sitemaps, 1 for pages and 1 for blogs. # sitemap-pages.xml # sitemap-blogs.xml # And in the main sitemap.xml file we link to these two - #local -a html_files=("${(@f)$(find "${www_root}" -type f -name "*.xml")}") - #local -a blog_files=("${(@f)$(find "${www_root}" -type f -name "*.html" | grep blog)}") - #local -a page_files=("${(@f)$(find "${www_root}" -type f -name "*.html" | grep -v blog)}") + + # Start of the XML file for BLOGS + echo '' > ${b_file} + echo "" >> ${b_file} + echo "" >> ${b_file} + echo '> ${b_file} + echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${b_file} + echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${b_file} + echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${b_file} + echo '>' >> ${b_file} + + # Add each URL to the sitemap + for file in "${blog_files[@]}" + do + # Remove www_root from the path and prepend site_url + local url="${site_url}${file#$www_root}" + local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//') + + echo " " >> ${b_file} + echo " ${url}" >> ${b_file} + echo " " >> ${b_file} + echo " " >> ${b_file} + echo " " >> ${b_file} + echo " " >> ${b_file} + done + + # End of the XML file + echo '' >> "${b_file}" + _msg std " - ${b_file}" + + # Start of the XML file for PAGES + echo '' > ${p_file} + echo "" >> ${p_file} + echo "" >> ${p_file} + echo '> ${p_file} + echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${p_file} + echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${p_file} + echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${p_file} + echo '>' >> ${p_file} + + # Add each URL to the sitemap + for file in "${page_files[@]}" + do + # Remove www_root from the path and prepend site_url + local url="${site_url}${file#$www_root}" + local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//') + + echo " " >> ${p_file} + echo " ${url}" >> ${p_file} + echo " " >> ${p_file} + echo " " >> ${p_file} + echo " " >> ${p_file} + echo " " >> ${p_file} + done + + # End of the XML file + echo '' >> "${p_file}" + _msg std " - ${p_file}" # Start of the XML file echo '' > ${sitemap_file} @@ -942,7 +1003,7 @@ function _sitemap() { echo '>' >> ${sitemap_file} # Add each URL to the sitemap - for file in "${html_files[@]}" + for file in "${xml_files[@]}" do # Remove www_root from the path and prepend site_url local url="${site_url}${file#$www_root}"