Skip to content

Instantly share code, notes, and snippets.

@libkazz
Created November 16, 2012 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libkazz/4085015 to your computer and use it in GitHub Desktop.
Save libkazz/4085015 to your computer and use it in GitHub Desktop.
Puts loc entry in sitemap_index.xml.gz

Puts loc entry in sitemap_index.xml.gz

##
# Usage: puts_locs `file`
# Puts loc entry in sitemap_index.xml.gz
# 
function _puts_locs() {
  zcat $1 | \
  ruby -anle '$_.sub(/^.*?<loc>/, "").gsub(/<loc>/, "\n").split("\n").each{|l| puts l.sub(/<\/loc>.*$/, "") }'
}

function _path_of() {
  echo $1 | sed 's|.*/sitemap|public/sitemap|' 
}

function puts_locs() {
  for sitemap in `_puts_locs $1`; do
    _puts_locs `_path_of $sitemap`
  done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment