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

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Rules
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2018-12-07 17:59:05 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2018-12-07 17:59:05 +0300
commit84f6ba6f041f15f79425fd90883c695a42b08446 (patch)
treeece39cba0e5d4651d5b6e5f5e97cb4f411d73f95 /Rules
parent6c70446545af15f2ac73e59ac26f9d2070174c20 (diff)
Check first if there's a 'redirect_url' in the yaml frontmatter
If there's a redirect_to, there's no need to further parse the page. If there's not a redirect_to, parse the page content and substitute .md with .html only if it exists.
Diffstat (limited to 'Rules')
-rw-r--r--Rules20
1 files changed, 12 insertions, 8 deletions
diff --git a/Rules b/Rules
index 42c20996..286454b4 100644
--- a/Rules
+++ b/Rules
@@ -7,19 +7,23 @@ preprocess do
@items.each do |item|
if item.identifier.to_s.end_with?(".md") && !item.binary?
+ # Check if there is a 'redirect_to' defined in the yaml frontmatter.
+ if item[:redirect_to]
+ # If the provided URL is in Markdown, correct it to HTML.
+ if item[:redirect_to].to_s.match(/.md$/)
+ item[:redirect_to] = item[:redirect_to].gsub!(/\.md/, '.html')
+ end
# 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]
+ else
+ # If the pattern 'This document was moved to [here](link)' is found.
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.
- if item[:redirect_to].to_s.match(/.md$/)
- item[:redirect_to] = item[:redirect_to].gsub!(/\.md/, '.html')
+ # If the provided URL is in Markdown, correct it to HTML.
+ if item[:redirect_to].to_s.match(/.md$/)
+ item[:redirect_to] = item[:redirect_to].gsub!(/\.md/, '.html')
+ end
end
end