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

Rules - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Rules
blob: 55a330e7c023f210b58f8877978e853bdc742d44 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env ruby

TITLE_FILTER_REGEXP = /(#\s|#{BadgesFilter::BADGES_MARKDOWN_PATTERN})/

preprocess do
  badges_filter = BadgesFilter.new

  @items.each do |item|
    if item.identifier.to_s.end_with?(".md") && !item.binary?
      # If there isn't already a 'redirect_to' defined in the yaml frontmatter,
      # use the text to assume the redirect URL.
      unless item[:redirect_to]
        if item.raw_content =~ /^This document was moved to \[.*\]\(.*\)/m
          # Capture the intended page so the redirect page can redirect to it.
          item[:redirect_to] = item.raw_content.match(/^This document was moved to \[.*\]\((.*)\)/m)[1]
          # Correct the URL.
          item[:redirect_to] = item[:redirect_to].gsub!(/\.md/, '.html')
        end
      else
        # If the provided relative URL is in Markdown, correct it to HTML.
        unless item[:redirect_to].to_s.match(/.html$/)
          item[:redirect_to] = item[:redirect_to].gsub!(/\.md/, '.html')
        end
      end

      # We need to do some transformations for the title
      # Let's extract and keep it first:
      raw_title = item.raw_content.match(/^[#] .*$/).to_s

      # If we don't have a title in frontmatter, reuse the one we just fetch
      item[:title] ||= raw_title.gsub(TITLE_FILTER_REGEXP, '')

      # Run badges filter with title fragment
      item[:title_badge] = badges_filter.run_from_markdown(raw_title.match(BadgesFilter::BADGES_MARKDOWN_PATTERN).to_s)
    end
  end
end

compile '/404.*' do
  filter :erb
  layout '/404.*'
  write '/404.html'
end

compile '/archives/index.*' do
  filter :erb
  layout '/archives.*'
  write '/archives/index.html'
end

compile '/**/*.html' do
  layout '/default.*'
end

compile '/**/*.md' do
  if item[:redirect_to].nil?

    # If 'toc' is absent in a file's yaml frontmatter, show ToC.
    # Set to 'toc: false' to disable it.
    include_toc = item[:toc].nil? ? true : false

    # Use GitlabKramdown with Rouge.
    # https://gitlab.com/brodock/gitlab_kramdown
    filter :gitlab_kramdown,
      input: 'GitlabKramdown',
      syntax_highlighter: 'rouge',
      default_lang: 'Plain Text',
      hard_wrap: false,
      auto_ids: true,
      toc_levels: 2..5,
      with_toc: include_toc

    filter :colorize_syntax,
      default_colorizer: :rouge

    # GitLab price / tiers specific badges
    filter :badges

    filter :md_to_html_ext
    filter :admonition

    if item[:layout].nil?
      layout '/default.*'
    else
      layout "/#{item[:layout]}.*"
    end
  else
    layout '/redirect.*'
  end
end

compile '/**/*.scss' do
  filter :erb
  filter :sass,
    syntax: :scss,
    style: :compressed
  write item.identifier.without_ext + '-v' + rep.item[:version].to_s + '.css'
end

compile '/index.*' do
  filter :erb
  layout '/home.*'
  write '/index.html'
end

compile '/sitemap.*' do
  filter :erb
  write '/sitemap.xml'
end

compile '/robots.*' do
  filter :erb
  write '/robots.txt'
end

route '/**/*.{html,md}' do
  if item.identifier =~ '/index.*'
    '/index.html'
  else
    item.identifier.without_ext + '.html'
  end
end

compile '/**/*' do
  unless item.identifier.ext == 'scss'
    write item.identifier.to_s
  end
end

# Leave yaml files out
ignore '/_data/*.yaml'

layout '/**/*', :erb

# Leave the favicon alone.
passthrough '/favicon.ico'