File: redirectable.rb

package info (click to toggle)
ruby-jekyll-redirect-from 0.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 284 kB
  • sloc: ruby: 659; sh: 17; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 799 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module JekyllRedirectFrom
  # Module which can be mixed in to documents (and pages) to provide
  # redirect_to and redirect_from helpers
  module Redirectable
    # Returns a string representing the relative path or URL
    # to which the document should be redirected
    def redirect_to
      if to_liquid["redirect_to"].is_a?(Array)
        to_liquid["redirect_to"].compact.first
      else
        to_liquid["redirect_to"]
      end
    end

    # Returns an array representing the relative paths to other
    # documents which should be redirected to this document
    def redirect_from
      if to_liquid["redirect_from"].is_a?(Array)
        to_liquid["redirect_from"].compact
      else
        [to_liquid["redirect_from"]].compact
      end
    end
  end
end