Skip to content

Commit 1835eb4

Browse files
committed
修改自动链接的判断逻辑
1 parent 2b44de1 commit 1835eb4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

_plugins/auto-link.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
next unless doc.output_ext == ".html"
66

77
site = doc.site
8-
baseurl = site.config["baseurl"].to_s
98
liquid_context = Liquid::Context.new({}, {}, { site: site })
109

1110
process_uri = lambda do |path|
1211
uri = Addressable::URI.parse(path)
13-
if uri&.path && !uri.path&.start_with?(baseurl)
12+
if uri&.path
1413
uri.path = Liquid::Template.parse("{% link #{uri.path[1..]} %}").render!(liquid_context)
1514
end
1615
uri.to_s
1716
end
1817

1918
fragment = Nokogiri::HTML::DocumentFragment.parse(doc.content)
20-
fragment.css("[src^=\"/\"]").each do |item|
19+
fragment.css("[src^=\"/assets/\"],[src^=\"/\"][src$=\".md\"],[src^=\"/\"][src*=\".md#\"]").each do |item|
2120
if item["src"]
2221
item["src"] = process_uri.call(item["src"])
2322
end
2423
end
25-
fragment.css("[href^=\"/\"]").each do |item|
24+
fragment.css("[href^=\"/assets/\"],[href^=\"/\"][href$=\".md\"],[href^=\"/\"][href*=\".md#\"]").each do |item|
2625
if item["href"]
2726
item["href"] = process_uri.call(item["href"])
2827
end

0 commit comments

Comments
 (0)