Sha256: 584e8480a59e3c346816236b12aac481584c5fc22c9c7394e90aa649ff1031ac

Contents?: true

Size: 901 Bytes

Versions: 1

Compression:

Stored size: 901 Bytes

Contents

require "jekyll/alt_urls/version"

module Jekyll
  class AltUrls < Generator
    def generate(site)
      original_pages = site.pages.dup
      generate_alt_urls(site, site.posts)
      generate_alt_urls(site, original_pages)
    end

    def generate_alt_urls(site, list)
      list.each do |item|
        if has_alt_urls?(item)
          alt_urls(item).flatten.each do |alt_url|
            redirect_page = RedirectPage.new(site, site.source, File.dirname(alt_url), File.basename(alt_url))
            redirect_page.generate_redirect_content(item.url)
            site.pages << redirect_page
          end
        end
      end
    end

    def has_alt_urls?(page_or_post)
      page_or_post.data.has_key?('alt_urls') &&
        !alt_urls(page_or_post).nil? &&
        alt_urls(page_or_post).is_a?(Array)
    end

    def alt_urls(page_or_post)
      page_or_post.data['alt_urls']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-alt-urls-0.1.0 lib/jekyll/alt_urls.rb