module Roroacms module SeoHelper @seo_title = '' @seo_description = '' # Returns a block of html with all the necessary headers for the front end html to include. # this is for the SEO functionallity to be included on each page. get_meta_headers is a # bootstrap to include all of the necessary functions def get_meta_headers # decide wether it is a page or it is a template displying other content i.e. the category page if !@content.nil? # if it has ACTUAL content then generate meta from the page content if !(@content.respond_to? :length) home_id = Setting.get('home_page') if @content.id == home_id.to_f # if it is the homepage create the meta tags manually headtags = get_manual_metadata 'home' else # use the page content to generate the meta data headtags = "#{get_page_title}\n" headtags += "#{get_meta_description}\n" headtags += "#{get_google_analytics}\n" headtags += "#{get_robots_tag}" headtags += "#{canonical_urls}" end render :inline => headtags else url_arr = params[:slug].split('/') if !params[:slug].nil? # get generic variables article_url = Setting.get('articles_slug') category_url = Setting.get('category_slug') # if the url is equal to the article, category or archive area if (!url_arr.blank? && (url_arr.last == article_url || url_arr.last.match(/\A\+?\d+(?:\.\d+)?\Z/) || url_arr[1] == category_url)) last_url = url_arr.last robots_var = nil if url_arr[0] == article_url || url_arr[1] == category_url robots_var = 'category' elsif last_url.match(/\A\+?\d+(?:\.\d+)?\Z/) robots_var = 'archive' end new_string = last_url.slice(0,1).capitalize + last_url.slice(1..-1) if last_url.match(/\A\+?\d+(?:\.\d+)?\Z/) if !url_arr[2].blank? new_string = Date::MONTHNAMES[url_arr[2].to_i] new_string = "#{new_string} #{url_arr[1]}" if !url_arr[3].blank? new_string = "#{url_arr[3]} #{new_string}" end end end headtags = "#{get_page_title new_string}\n" headtags += "#{get_google_analytics}\n" headtags += "#{get_robots_tag robots_var}" render :inline => headtags end end else # render the 404 meta data headtags = response.status == 404 ? get_manual_metadata('404') : application_set_headers render :inline => headtags end end private # returns the description meta tag. It will return a truncated version of the content if nothing is given and it does not have an seo description # Params: # +override+:: override the content with the data provided def get_meta_description(overide = nil) # if override has content, use this content to create the meta description if !overide.nil? return "\n" else # if seo description is not blank then use that if !@content.post_seo_description.blank? return "\n" elsif Setting.get('seo_autogenerate_descriptions') == 'Y' # if worst comes to worst use the page content description = truncate(prep_content(@content), :length => 100, :separator => ' ').gsub(/\r?\n|\r/, "") return "\n" end end return '' end # returns the page title meta tag. It will return the post content title if nothing is given via override and it does not have an seo title # Params: # +override+:: override the content with the data provided def get_page_title(overide = nil) # if override has content, use this content to create the meta title if !overide.blank? websiteTitle = Setting.get('seo_site_title') title = "#{overide} | #{websiteTitle}" @seo_title = "