Skip to content

Commit

Permalink
Tweak sitemap generation
Browse files Browse the repository at this point in the history
  • Loading branch information
matsbov committed Oct 22, 2024
1 parent 530a88f commit a623371
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions grails-app/services/au/org/ala/bie/SitemapService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class SitemapService{
Locale defaultLocale


String URLSET_HEADER = "<?xml version='1.0' encoding='UTF-8'?><urlset 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\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"
String URLSET_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset 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\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"
String URLSET_FOOTER = "</urlset>"

// Batch size for solr queries/commits and page sizes
static BATCH_SIZE = 5000

int MAX_URLS = 50000 // maximum number of URLs in a sitemap file
int MAX_URLS = 10000 // maximum number of URLs in a sitemap file
int MAX_SIZE = 9*1024*1024 // use 9MB to keep the actual file size below 10MB (a gateway limit)

File currentFile
Expand Down Expand Up @@ -72,7 +72,7 @@ class SitemapService{

// write parent sitemap file
fw = new FileWriter(grailsApplication.config.sitemap.dir + "/sitemap.xml")
fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">")
fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n")

for (int i=0;i<fileCount;i++) {

Expand All @@ -84,9 +84,9 @@ class SitemapService{
new File(grailsApplication.config.sitemap.dir + "/sitemap" + i + ".xml.tmp").renameTo(newFile)

// add an entry for this new file
// SBDI: should be 'loc' and not 'url'
fw.write("<sitemap><loc>" + grailsApplication.config.grails.serverURL + '/sitemap' + i + ".xml" + "</loc>")
fw.write("<lastmod>" + simpleDateFormat.format(new Date()) + "</lastmod></sitemap>")
// SBDI: Should be 'loc' and not 'url'. Serve sitemap without /ws path.
fw.write("<sitemap><loc>" + grailsApplication.config.getProperty('bie.baseURL') + '/sitemap' + i + ".xml" + "</loc>")
fw.write("<lastmod>" + simpleDateFormat.format(new Date()) + "</lastmod></sitemap>\n")
}

fw.write("</sitemapindex>")
Expand All @@ -99,7 +99,7 @@ class SitemapService{

fw = new FileWriter(currentFile)

fw.write(URLSET_HEADER)
fw.write(URLSET_HEADER + "\n")

countUrls = 0
fileCount++
Expand Down Expand Up @@ -173,7 +173,7 @@ class SitemapService{
fw.write("<loc>" + encodedUrl + "</loc>")
fw.write("<lastmod>" + simpleDateFormat.format(new Date()) + "</lastmod>")
fw.write("<changefreq>" + changefreq + "</changefreq>")
fw.write("</url>")
fw.write("</url>\n")

fw.flush()

Expand Down

0 comments on commit a623371

Please sign in to comment.