class SiSU_Sitemaps::Source

Public Class Methods

new(opt) click to toggle source
# File lib/sisu/sitemaps.rb, line 63
def initialize(opt)
  @opt=opt
end

Public Instance Methods

make_file(path,filename) click to toggle source
# File lib/sisu/sitemaps.rb, line 101
def make_file(path,filename)
  (File.writable?("#{path}/.")) \
  ? (File.new("#{path}/#{filename}",'w+'))
  : (SiSU_Screen::Ansi.new(
       '',
       "is the file or directory writable?, could not create #{filename}"
     ).warn)
end
output_idx(sitemap) click to toggle source
# File lib/sisu/sitemaps.rb, line 121
def output_idx(sitemap)
  path=@env.path.output
  filename=@sitemap_idx_fn
  make_path(path)
  file=make_file(path,filename)
  file << sitemap
end
output_map(sitemap) click to toggle source
# File lib/sisu/sitemaps.rb, line 109
def output_map(sitemap)
  path=@md.file.output_path.sitemaps.dir
  filename=@fn[:sitemap]
  touch_path=@md.file.output_path.sitemaps.dir
  touch_filename=@fn[:sitemap_touch]
  SiSU_Env::FileOp.new(@md).make_path(path)
  file=SiSU_Env::FileOp.new(@md).make_file(path,filename)
  file << sitemap
  if FileTest.file?("#{touch_path}/#{touch_filename}")
    FileUtils::rm("#{touch_path}/#{touch_filename}")
  end
end
read() click to toggle source
# File lib/sisu/sitemaps.rb, line 66
def read
  songsheet
end
sitemap() click to toggle source
# File lib/sisu/sitemaps.rb, line 153
def sitemap
  if defined? @md.date.modified \
  and @md.date.modified=~/\d{4}-\d{2}-\d{2}/
    sitemap_date_modified
  else sitemap_no_date
  end
end
sitemap_date_modified() click to toggle source
# File lib/sisu/sitemaps.rb, line 160
    def sitemap_date_modified
<<WOK
<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemaps/0.9
  http://www.sitemaps.org/schemas/sitemaps/sitemap.xsd"
  xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#{@rdf.comment_xml}
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:toc]}</loc>
    <lastmod>#{@md.date.modified}</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:doc]}</loc>
    <lastmod>#{@md.date.modified}</lastmod>
    <priority>0.5</priority>
  </url>
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:manifest]}</loc>
    <lastmod>#{@md.date.modified}</lastmod>
    <priority>0.5</priority>
  </url>
</urlset>
WOK
    end
sitemap_index() click to toggle source
# File lib/sisu/sitemaps.rb, line 128
    def sitemap_index
      sitemap_files=Dir.glob("#{@env.path.sitemaps}/sitemap_*.xml")
      sitemap_idx=[]
      sitemap_idx << <<WOK
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemaps/0.9
   http://www.sitemaps.org/schemas/sitemaps/sitemap.xsd"
     xmlns="http://www.sitemaps.org/schemas/sitemapindex/0.9">
WOK
      sitemap_files.each do |s|
        f=s.gsub(/.+?\/sitemap_([^\/]+?)\.xml$/,'\1')
        @trans.char_enc.utf8(f) \
          if @sys.locale =~/utf-?8/i
sitemap_idx << <<WOK
  <sitemap>
    <loc>#{@env.path.url.remote}/#{f}/sitemap.xml</loc>
  </sitemap>
WOK
      end
      sitemap_idx << <<WOK
</sitemapindex>
WOK
      sitemap_idx.join
    end
sitemap_no_date() click to toggle source
# File lib/sisu/sitemaps.rb, line 187
    def sitemap_no_date
<<WOK
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#{@rdf.comment_xml}
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:toc]}</loc>
    <changefreq>monthly</changefreq>
    <priority>0.7</priority>
  </url>
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:doc]}</loc>
    <priority>0.5</priority>
  </url>
  <url>
    <loc>#{@env.path.url.remote}/#{@fnb_utf8_xml}/#{@fn[:manifest]}</loc>
    <priority>0.5</priority>
  </url>
</urlset>
WOK
    end
songsheet() click to toggle source
# File lib/sisu/sitemaps.rb, line 69
    def songsheet
      begin
        @sys=SiSU_Env::SystemCall.new
        fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language
        @fn=SiSU_Env::EnvCall.new(@opt.fns).lang(fn_set_lang[:c])
        if @opt.act[:sitemap][:set]==:on
          @md=SiSU_Param::Parameters.new(@opt).get
          @trans=SiSU_XML_Munge::Trans.new(@md) #check @md is required
          @env=SiSU_Env::InfoEnv.new(@md.fns)
#         @file=SiSU_Env::FileOp.new(@md)
          @rdf=SiSU_XML_Tags::RDF.new(@md)
          @fnb_utf8_xml=@md.fnb.dup
          @trans.char_enc.utf8(@fnb_utf8_xml) \
            if @sys.locale =~/utf-?8/i
          output_map(sitemap)
        elsif @opt.selections.str =~/--sitemaps/
          @sitemap_idx_fn='sitemapindex.xml'
          @env=SiSU_Env::InfoEnv.new
          output_idx(sitemap_index)
          SiSU_Screen::Ansi.new(
            @opt.act[:color_state][:set],
            'sitemap index:',
            "#{@env.path.output}/#{@sitemap_idx_fn}"
          ).result unless @opt.act[:quiet][:set]==:on
        end
      rescue
        SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do
          __LINE__.to_s + ':' + __FILE__
        end
      ensure
      end
    end