mirror of
https://gitee.com/huanghongxun/HMCL-docs.git
synced 2025-12-02 00:32:40 +08:00
修改自动链接的判断逻辑 (#335)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cfaa4daa81
commit
52065c9268
@ -5,24 +5,23 @@ Jekyll::Hooks.register [:pages, :documents], :post_convert do |doc|
|
|||||||
next unless doc.output_ext == ".html"
|
next unless doc.output_ext == ".html"
|
||||||
|
|
||||||
site = doc.site
|
site = doc.site
|
||||||
baseurl = site.config["baseurl"].to_s
|
|
||||||
liquid_context = Liquid::Context.new({}, {}, { site: site })
|
liquid_context = Liquid::Context.new({}, {}, { site: site })
|
||||||
|
|
||||||
process_uri = lambda do |path|
|
process_uri = lambda do |path|
|
||||||
uri = Addressable::URI.parse(path)
|
uri = Addressable::URI.parse(path)
|
||||||
if uri&.path && !uri.path&.start_with?(baseurl)
|
if uri&.path
|
||||||
uri.path = Liquid::Template.parse("{% link #{uri.path[1..]} %}").render!(liquid_context)
|
uri.path = Liquid::Template.parse("{% link #{uri.path[1..]} %}").render!(liquid_context)
|
||||||
end
|
end
|
||||||
uri.to_s
|
uri.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
fragment = Nokogiri::HTML::DocumentFragment.parse(doc.content)
|
fragment = Nokogiri::HTML::DocumentFragment.parse(doc.content)
|
||||||
fragment.css("[src^=\"/\"]").each do |item|
|
fragment.css("[src^=\"/assets/\"],[src^=\"/\"][src$=\".md\"],[src^=\"/\"][src*=\".md#\"]").each do |item|
|
||||||
if item["src"]
|
if item["src"]
|
||||||
item["src"] = process_uri.call(item["src"])
|
item["src"] = process_uri.call(item["src"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fragment.css("[href^=\"/\"]").each do |item|
|
fragment.css("[href^=\"/assets/\"],[href^=\"/\"][href$=\".md\"],[href^=\"/\"][href*=\".md#\"]").each do |item|
|
||||||
if item["href"]
|
if item["href"]
|
||||||
item["href"] = process_uri.call(item["href"])
|
item["href"] = process_uri.call(item["href"])
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user