This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-docs.git
The following commit(s) were added to refs/heads/master by this push:
new 39cb211 add base url in more places, and warn if links not found
new 48a531e Merge remote-tracking branch 'apache-git/master'
39cb211 is described below
commit 39cb2116c39949a4713fe754889d70e18a28ce02
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Sep 3 14:42:44 2021 +0100
add base url in more places, and warn if links not found
was skipping links that were being `{% read ... %}`
---
_plugins/jekyll_relative_links.rb | 25 +++++++++++++++++++------
_plugins/read.rb | 5 +++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/_plugins/jekyll_relative_links.rb
b/_plugins/jekyll_relative_links.rb
index 820a73c..5af7dd1 100644
--- a/_plugins/jekyll_relative_links.rb
+++ b/_plugins/jekyll_relative_links.rb
@@ -7,7 +7,7 @@
# - speculatively map .html to .md when doing the lookup
# - make url_for_path public, and have way to inject site and initialize
context outside of normal generator usage
-# distributed under the MIT License as follows (note this is only used to
build the docs, not included with any brooklyn output):
+# distributed under the MIT License as follows (note this is only used to
build the docs, not included with any AMP output):
# MIT License
#
@@ -92,7 +92,7 @@ module JekyllRelativeLinks
next original unless replaceable_link?(link.path)
path = path_from_root(link.path, url_base)
- url = url_for_path(path)
+ url = url_for_path(path, document.relative_path)
next original unless url
@@ -126,13 +126,26 @@ module JekyllRelativeLinks
private
- def url_for_path(path)
+ def url_for_path(path, src)
path.sub!(%r!\A/!, "")
# puts "lookup #{path} / #{path.sub(%r!\.html!.freeze, ".md")}"
url = url_for_path_internal(path)
- # also try html and / mapped to md - useful if using a baseurl
- url = url_for_path_internal(path.sub(%r!\.html!.freeze, ".md")) unless
url
- url = url_for_path_internal(path.sub(%r!/\z!.freeze, "") + "/index.md")
unless url
+
+ pathWithText = %r!^(.*\.(png|jpg|gif|svg))( .*)\z!.freeze.match(path)
+ # don't match images
+ if (!pathWithText)
+ # try to find it with .html suffix or if path to folder with or
without / or if extension omitted
+ url = url_for_path_internal(path.sub(%r!\.html!.freeze, ".md")) unless
url
+ url = url_for_path_internal(path.sub(%r!/\z!.freeze, "") +
"/index.md") unless url
+ url = url_for_path_internal(path.sub(%r!\z!.freeze, "") + "/index.md")
unless url
+ url = url_for_path_internal(path.sub(%r!\z!.freeze, ".md")) unless url
+ puts "WARN: unresolved link in #{src}: #{path}" if !url
+
+ else
+ url = url_for_path(pathWithText[1], src) if pathWithText
+ url = url + pathWithText[2] if url
+ url = path unless url
+ end
url
end
diff --git a/_plugins/read.rb b/_plugins/read.rb
index c7d9f54..f35672f 100644
--- a/_plugins/read.rb
+++ b/_plugins/read.rb
@@ -55,6 +55,11 @@ module JekyllRead
# support vars and paths relative to a file being readj'd
jekyllSite = context.registers[:site]
targetPage = Jekyll::Page.new(jekyllSite, jekyllSite.source,
File.dirname(file), File.basename(file))
+
+ @relative_link_parser = JekyllRelativeLinks::Generator.new(nil)
+ @relative_link_parser.prepare_for_site(jekyllSite)
+ @relative_link_parser.replace_relative_links!(targetPage)
+
targetPage.render(jekyllSite.layouts, jekyllSite.site_payload)
targetPage.output
end