_sitemap: More optimization

This commit is contained in:
Stig-Ørjan Smelror 2024-02-18 11:39:40 +01:00
parent bbf5a65943
commit dc8ee08709

68
qsgen2
View File

@ -927,20 +927,24 @@ function _sitemap() {
# Find all HTML files and store them in an array # 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=("${(@f)$(find "${www_root}" -type f -name "*.html")}")
local -a html_files=(${www_root}/**/[a-z]*.html(.)) local -a html_files=(${www_root}/**/[a-z]*.html(.))
local -a blog_files=(${html_files[@]:#*blog*}) local -a blog_files=(${html_files[@]:#*blog/2*})
local -a page_files=("${(@)html_files[@]}" | grep -v blog) local -a page_files=()
for file in "${html_files[@]}"; do
[[ $file != *blog* ]] && blog_files+=("$file")
done
local -a xml_files=(${www_root}/[a-z]*.xml(.)) local -a xml_files=(${www_root}/[a-z]*.xml(.))
xml_files=( "${(@)xml_files[@]}" | grep -v "sitemap.xml" ) xml_files=( "${(@)xml_files[@]}" | grep -v "sitemap.xml" )
# Start of the XML file for BLOGS # Start of the XML file for BLOGS
echo '<?xml version="1.0" encoding="UTF-8"?>' > ${b_file} echo '<?xml version="1.0" encoding="UTF-8"?>' > ${sitemap_blog}
echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${b_file} echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${sitemap_blog}
echo "<?xml-stylesheet type=\"text/xsl\" href=\"${site_url}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${b_file} echo "<?xml-stylesheet type=\"text/xsl\" href=\"${site_url}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${sitemap_blog}
echo '<urlset' >> ${b_file} echo '<urlset' >> ${sitemap_blog}
echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${b_file} echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${sitemap_blog}
echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${b_file} echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${sitemap_blog}
echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${b_file} echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${sitemap_blog}
echo '>' >> ${b_file} echo '>' >> ${sitemap_blog}
# Add each URL to the sitemap # Add each URL to the sitemap
for file in "${blog_files[@]}" for file in "${blog_files[@]}"
@ -949,27 +953,27 @@ function _sitemap() {
local url="${site_url}${file#$www_root}" 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/\..*$//') local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <url>" >> ${b_file} echo " <url>" >> ${sitemap_blog}
echo " <loc>${url}</loc>" >> ${b_file} echo " <loc>${url}</loc>" >> ${sitemap_blog}
echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${b_file} echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${sitemap_blog}
echo " <changefreq><![CDATA[always]]></changefreq>" >> ${b_file} echo " <changefreq><![CDATA[always]]></changefreq>" >> ${sitemap_blog}
echo " <priority><![CDATA[1]]></priority>" >> ${b_file} echo " <priority><![CDATA[1]]></priority>" >> ${sitemap_blog}
echo " </url>" >> ${b_file} echo " </url>" >> ${sitemap_blog}
done done
# End of the XML file # End of the XML file
echo '</urlset>' >> "${b_file}" echo '</urlset>' >> "${sitemap_blog}"
_msg std " - ${b_file}" _msg std " - ${b_file}"
# Start of the XML file for PAGES # Start of the XML file for PAGES
echo '<?xml version="1.0" encoding="UTF-8"?>' > ${p_file} echo '<?xml version="1.0" encoding="UTF-8"?>' > ${sitemap_page}
echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${p_file} echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${sitemap_page}
echo "<?xml-stylesheet type=\"text/xsl\" href=\"${site_url}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${p_file} echo "<?xml-stylesheet type=\"text/xsl\" href=\"${site_url}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${sitemap_page}
echo '<urlset' >> ${p_file} echo '<urlset' >> ${sitemap_page}
echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${p_file} echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${sitemap_page}
echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${p_file} echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${sitemap_page}
echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${p_file} echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${sitemap_page}
echo '>' >> ${p_file} echo '>' >> ${sitemap_page}
# Add each URL to the sitemap # Add each URL to the sitemap
for file in "${page_files[@]}" for file in "${page_files[@]}"
@ -978,16 +982,16 @@ function _sitemap() {
local url="${site_url}${file#$www_root}" 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/\..*$//') local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <url>" >> ${p_file} echo " <url>" >> ${sitemap_page}
echo " <loc>${url}</loc>" >> ${p_file} echo " <loc>${url}</loc>" >> ${sitemap_page}
echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${p_file} echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${sitemap_page}
echo " <changefreq><![CDATA[always]]></changefreq>" >> ${p_file} echo " <changefreq><![CDATA[always]]></changefreq>" >> ${sitemap_page}
echo " <priority><![CDATA[1]]></priority>" >> ${p_file} echo " <priority><![CDATA[1]]></priority>" >> ${sitemap_page}
echo " </url>" >> ${p_file} echo " </url>" >> ${sitemap_page}
done done
# End of the XML file # End of the XML file
echo '</urlset>' >> "${p_file}" echo '</urlset>' >> "${sitemap_page}"
_msg std " - ${p_file}" _msg std " - ${p_file}"
# Start of the XML file # Start of the XML file