Welcome to mirror list, hosted at ThFree Co, Russian Federation.

symlinks_converter.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 48b6a73233a3802a52d847330ebb8f642e1353a6 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Gitlab
  class SymlinksConverter
    EXTENSIONS = %w[png jpg gif svg].freeze

    def initialize(config, items)
      @config = config
      @items = items
    end

    def self.run(config, items)
      new(config, items).run
    end

    def run
      return unless Nanoc::Helpers::Generic.omnibus?

      items.each do |item|
        id = item.identifier

        next unless id.to_s.start_with?('/ee/')
        next unless EXTENSIONS.include?(id.ext)

        file_path = File.join(config.fetch(:content_dir), id.to_s)
        real_path = Pathname.new(file_path).realpath.to_s
        symlink = File.join(config.output_dir, id.to_s)

        # Replace a file with a symlink
        File.delete(symlink) && File.symlink(real_path, symlink) if File.exist?(symlink)
      end
    end

    private

    attr_reader :config, :items
  end
end