Sha256: a315ea91fd21a62ca1acd5ad8446ec94aca2ee5ed96ee0e65daf74e9e47a260b

Contents?: true

Size: 809 Bytes

Versions: 19

Compression:

Stored size: 809 Bytes

Contents

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

    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

19 entries across 19 versions & 2 rubygems

Version Path
govuk_tech_docs-1.9.0.pre.rc2 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.9.0.pre.gfe lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.8.3 lib/govuk_tech_docs/redirects.rb
dss_tech_docs-0.1.2 lib/govuk_tech_docs/redirects.rb
dss_tech_docs-0.1.1 lib/govuk_tech_docs/redirects.rb
dss_tech_docs-0.1.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.8.2 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.8.1 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.8.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.7.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.6.3 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.6.2 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.6.1 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.6.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.5.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.4.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.3.1 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.3.0 lib/govuk_tech_docs/redirects.rb
govuk_tech_docs-1.2.0 lib/govuk_tech_docs/redirects.rb