diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2018-12-07 17:59:05 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2018-12-07 17:59:05 +0300 |
commit | 84f6ba6f041f15f79425fd90883c695a42b08446 (patch) | |
tree | ece39cba0e5d4651d5b6e5f5e97cb4f411d73f95 /Rules | |
parent | 6c70446545af15f2ac73e59ac26f9d2070174c20 (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-- | Rules | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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 |