Sha256: 42be3e7cc41ea68bf41c278bfc1f4a6649c5ced02ad0505e5d8ec5d3c27a90d3

Contents?: true

Size: 816 Bytes

Versions: 11

Compression:

Stored size: 816 Bytes

Contents

module GovukTechDocs
  class Redirects
    LEADING_SLASH = %r[\A\/].freeze

    def initialize(context)
      @context = context
    end

    def redirects
      all_redirects = redirects_from_config + redirects_from_frontmatter

      all_redirects.map do |from, to|
        # Middleman needs paths without leading slashes
        [from.sub(LEADING_SLASH, ''), to: to.sub(LEADING_SLASH, '')]
      end
    end

  private

    attr_reader :context

    def redirects_from_config
      context.config[:tech_docs][:redirects].to_a
    end

    def redirects_from_frontmatter
      reds = []
      context.sitemap.resources.each do |page|
        next unless page.data.old_paths

        page.data.old_paths.each do |old_path|
          reds << [old_path, page.path]
        end
      end

      reds
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
govuk_tech_docs-2.0.7 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.6 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.5 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.4 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.3 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.2 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.1 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.0.pre.test.pre.release.pre.525 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.0.pre.test.pre.release.pre.524 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.0.test.pre.release.521 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-2.0.0 lib/govuk_tech_docs/redirects.rb