diff options
author | Marcia Ramos <virtua.creative@gmail.com> | 2018-01-26 16:54:44 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2018-01-26 16:54:44 +0300 |
commit | 4bd5e85edd5d14eb7c5d7b4fdcc7df834e10816b (patch) | |
tree | d44026c1bd14e0d85c0f7e8f2c71c0a095b04a24 /Rules | |
parent | 8e5b850331a3c0fd1ad3b371582a3a3062c160b0 (diff) |
New layout for redirects
Diffstat (limited to 'Rules')
-rw-r--r-- | Rules | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -3,12 +3,20 @@ preprocess do @items.each do |item| if item.identifier.to_s.end_with?(".md") && !item.binary? - # If the page is a redirect, make it a redirect. - if item.raw_content =~ /^This document was moved to \[.*\]\(.*\)/m - # Capture the intended page so the redirect page can redirect to it. - item[:redirect] = item.raw_content.match(/^This document was moved to \[.*\]\((.*)\)/m)[1] - # Correct the URL. - item[:redirect] = item[:redirect].gsub!(/\.md/, '.html') + # 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 unless item[:title] @@ -31,7 +39,7 @@ compile '/**/*.html' do end compile '/**/*.md' do - if item[:redirect].nil? + if item[:redirect_to].nil? # If 'toc' is absent in a file's yaml frontmatter, show ToC. # Set to 'toc: false' to disable it. |