Hace unos años hice el crawling de la web antigua de kaosenlared. Ahora tiempo mas tarde el analytics de google les estaba dando muchos errores de páginas no encontradas, así que he tenido que generar los ficheros sitemap.xml para que google indexe el sitio.
He hecho un primer script para listar todas las páginas index.html del directorio y generar el fichero sitemap.xml que ocupaba la friolera de 150Mb pero al metérselo a google analytics daba errores de tamaño de archivo. Buscando los límites, nos encontramos que el sitemap.xml no puede ser más grande de 50Mb ni contener más de 50.000 entradas. Así que ha sido necesario crear un índice y separar los sitemap.xml en ficheros más pequeños.
A continuación el script de como lo he hecho
#!/bin/bash
# Directori on es troben les pàgines html
DIRECTORI=/home/virtualmin/archivo.kaosenlared.net/public_html
# URL base del lloc web
URL_BASE=https://archivo.kaosenlared.net
current_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Funció per generar el sitemap.xml
generar_sitemap() {
# Initialize the URL count and the file number
url_count=0
file_number=1
# Initialize the sitemap file name
sitemap_file="sitemap_${file_number}.xml"
sitemap_index="sitemap.xml"
# Inicialitza el fitxer sitemap.xml
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' > $sitemap_index
echo '<?xml version="1.0" encoding="UTF-8"?>' > $sitemap_file
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' >> $sitemap_file
echo " <sitemap>" >> $sitemap_index
echo " <loc>$URL_BASE/$sitemap_file</loc>" >> $sitemap_index
echo " <lastmod>$current_date</lastmod>" >> $sitemap_index
#echo " <changefreq>monthly</changefreq>" >> $sitemap_index
echo " </sitemap>" >> $sitemap_index
# Recorre els fitxers html del directori i subdirectoris
find $DIRECTORI -type f -name "*.html" -not -path "*mailto*" -not -path "* *" -not -path "*&*" | while read fitxer; do
# Obtenir la URL relativa del fitxer
url_relativa=${fitxer#$DIRECTORI/}
# Afegir la URL al sitemap.xml
echo " <url>" >> $sitemap_file
echo " <loc>$URL_BASE/$url_relativa</loc>" >> $sitemap_file
echo " <lastmod>$current_date</lastmod>" >> $sitemap_file
#echo " <changefreq>monthly</changefreq>" >> $sitemap_file
#echo " <priority>0.5</priority>" >> $sitemap_file
echo " </url>" >> $sitemap_file
# Increment the URL count
((url_count++))
# If the URL count reaches the limit, create a new file
if [ $url_count -ge 40000 ]; then
# Close the current sitemap file
echo '</urlset>' >> $sitemap_file
# Next sitemap file
((file_number++))
echo ${file_number} > last_file_number
url_count=0
# Initialize the new sitemap file
sitemap_file="sitemap_${file_number}.xml"
echo '<?xml version="1.0" encoding="UTF-8"?>' > $sitemap_file
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' >> $sitemap_file
echo " <sitemap>" >> $sitemap_index
echo " <loc>$URL_BASE/$sitemap_file</loc>" >> $sitemap_index
echo " <lastmod>$current_date</lastmod>" >> $sitemap_index
#echo " <changefreq>monthly</changefreq>" >> $sitemap_index
echo " </sitemap>" >> $sitemap_index
fi
done
# Close the last sitemap file
echo '</sitemapindex>' >> $sitemap_index
echo '</urlset>' >> sitemap_`cat last_file_number`.xml
rm -f last_file_number
cp $sitemap_index sitemap_index.xml
}
# Generar el sitemap.xml
generar_sitemap<
chown archivo.kaosenlared.net:archivo.kaosenlared.net *.xml
A ejecutarlo y mover los ficheros en el directorio donde se encuentra el sitio! :)
Los posts mejor en castellano , no en polaco.
te aguantas