93 lines
4.3 KiB
Plaintext

if [[ ${globaldebug} == "true" ]]; then
local debug=true
else
local debug=false
fi
if ([[ ${config[site_sitemap]} == "true" ]] && ( [[ ${new_updated_blogs} == "true" ]] || [[ ${new_updated_pages} == "true" ]] )) || [[ ${sitemap_force} == "true" ]]; then
setopt extendedglob
_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="${config[site_root]}/${sm_file}"
local sitemap_blog="${config[site_root]}/${b_file}"
local sitemap_page="${config[site_root]}/${p_file}"
builtin cd ${config[site_root]}
local -a html_files=(**/[a-z]*.html(.))
local -a blog_files=()
local -a page_files=()
for file in "${html_files[@]}"; do
if [[ $file == *blog* ]]; then
blog_files+=("$file")
else
page_files+=("$file")
fi
done
echo '<?xml version="1.0" encoding="UTF-8"?>' > ${sitemap_blog}
echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${sitemap_blog}
echo "<?xml-stylesheet type=\"text/xsl\" href=\"${config[site_url]}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${sitemap_blog}
echo '<urlset' >> ${sitemap_blog}
echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${sitemap_blog}
echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${sitemap_blog}
echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${sitemap_blog}
echo '>' >> ${sitemap_blog}
for file in "${blog_files[@]}"
do
local url="${config[site_url]}/${file}"
local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <url>" >> ${sitemap_blog}
echo " <loc>${url}</loc>" >> ${sitemap_blog}
echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${sitemap_blog}
echo " <changefreq><![CDATA[always]]></changefreq>" >> ${sitemap_blog}
echo " <priority><![CDATA[1]]></priority>" >> ${sitemap_blog}
echo " </url>" >> ${sitemap_blog}
done
echo '</urlset>' >> "${sitemap_blog}"
_msg std " - ${b_file}"
echo '<?xml version="1.0" encoding="UTF-8"?>' > ${sitemap_page}
echo "<!-- Sitemap generated by ${QSGEN} ${VERSION} - https://github.com/kekePower/qsgen2 -->" >> ${sitemap_page}
echo "<?xml-stylesheet type=\"text/xsl\" href=\"${config[site_url]}/css/default-sitemap.xsl?sitemap=page\"?>" >> ${sitemap_page}
echo '<urlset' >> ${sitemap_page}
echo ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' >> ${sitemap_page}
echo ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' >> ${sitemap_page}
echo ' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"' >> ${sitemap_page}
echo '>' >> ${sitemap_page}
for file in "${page_files[@]}"
do
local url="${config[site_url]}/${file}"
local lastmod=$(stat -c %y "${file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <url>" >> ${sitemap_page}
echo " <loc>${url}</loc>" >> ${sitemap_page}
echo " <lastmod><![CDATA[${lastmod}+01:00]]></lastmod>" >> ${sitemap_page}
echo " <changefreq><![CDATA[always]]></changefreq>" >> ${sitemap_page}
echo " <priority><![CDATA[1]]></priority>" >> ${sitemap_page}
echo " </url>" >> ${sitemap_page}
done
echo '</urlset>' >> "${sitemap_page}"
_msg std " - ${p_file}"
if (${debug}); then _msg debug "${0:t}_msg_2" " ${sitemap_file}"; fi
echo '<?xml version="1.0" encoding="UTF-8"?>' > "${sitemap_file}"
echo "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" >> "${sitemap_file}"
echo " <sitemap>" >> "${sitemap_file}"
echo " <loc>${config[site_url]}/${b_file}</loc>" >> "${sitemap_file}"
local lastmod_b=$(stat -c %y "${b_file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <lastmod>${lastmod_b}</lastmod>" >> "${sitemap_file}"
echo " </sitemap>" >> "${sitemap_file}"
echo " <sitemap>" >> "${sitemap_file}"
echo " <loc>${config[site_url]}/${p_file}</loc>" >> "${sitemap_file}"
local lastmod_p=$(stat -c %y "${p_file}" 2>/dev/null | cut -d' ' -f1,2 | sed 's/ /T/' | sed 's/\..*$//')
echo " <lastmod>${lastmod_p}</lastmod>" >> "${sitemap_file}"
echo " </sitemap>" >> "${sitemap_file}"
echo "</sitemapindex>" >> "${sitemap_file}"
_msg std " - ${sm_file}"
builtin cd ${config[project_root]}
fi