Skip to content

Commit 6986299

Browse files
committed
can this be solved with a plugin?
1 parent cff2bff commit 6986299

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

_includes/head-custom.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

_plugins/modify_root_links.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Jekyll::Hooks.register :pages, :pre_render do |page, payload|
2+
INLINE_LINK_REGEX = %r!(\[(?:[^\[\]\\]|\\.|\g<1>)*\])\(\s*(/[^)\s]*)([^)]*?)\)!.freeze
3+
REFERENCE_LINK_REGEX = %r!^\s*(\[(?:[^\[\]\\]*|\\.)+\]:) (/\S+)(.*)$!.freeze
4+
LINK_REGEX = %r!#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX}!.freeze
5+
6+
site = payload["site"]
7+
baseurl = site.baseurl
8+
page.content = page.content.gsub(LINK_REGEX) do |original|
9+
matches = Regexp.last_match
10+
inline_text = matches[1] # [foo]
11+
inline_url = matches[2] # /bar
12+
inline_title = matches[3] # "baz"
13+
ref_tag = matches[4] # [f]:
14+
ref_url = matches[5] # /bar
15+
ref_title = matches[6] # "baz"
16+
17+
if inline_text
18+
"#{inline_text}(/#{baseurl}#{inline_url}#{inline_title})"
19+
else
20+
"#{ref_tag} /#{baseurl}#{ref_url}#{ref_title}"
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)