You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2021/09/07 10:25:41 UTC

[brooklyn-docs] branch master updated (28eeca8 -> bb534ab)

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-docs.git.


    from 28eeca8  tweak tour, update/remove broken external links
     new addd078  remove spurious link warnings in jekyll
     new 966238a  fix image relative link regex
     new bb534ab  apply link rewriting to links imported as children

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 _plugins/jekyll_relative_links.rb | 42 +++++++++++++++++++++++++++++----------
 _plugins/page_structure.rb        |  7 ++++++-
 _plugins/read.rb                  |  8 ++++----
 3 files changed, 41 insertions(+), 16 deletions(-)

[brooklyn-docs] 02/03: fix image relative link regex

Posted by he...@apache.org.
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

commit 966238ae4b8a2789538a6caa23370761efdd60f9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Sat Sep 4 01:52:14 2021 +0100

    fix image relative link regex
---
 _plugins/jekyll_relative_links.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/_plugins/jekyll_relative_links.rb b/_plugins/jekyll_relative_links.rb
index b70ea8d..22691d4 100644
--- a/_plugins/jekyll_relative_links.rb
+++ b/_plugins/jekyll_relative_links.rb
@@ -151,7 +151,7 @@ module JekyllRelativeLinks
 
       else
         url = url_for_path(pathWithText[1], src) if pathWithText
-        url = url + pathWithText[2] if url
+        url = url + pathWithText[3] if url
         url = path unless url
       end
       url

[brooklyn-docs] 01/03: remove spurious link warnings in jekyll

Posted by he...@apache.org.
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

commit addd0789d8bed2259d1ff7305500b852a8cda949
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Sat Sep 4 01:16:41 2021 +0100

    remove spurious link warnings in jekyll
---
 _plugins/jekyll_relative_links.rb | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/_plugins/jekyll_relative_links.rb b/_plugins/jekyll_relative_links.rb
index 5af7dd1..b70ea8d 100644
--- a/_plugins/jekyll_relative_links.rb
+++ b/_plugins/jekyll_relative_links.rb
@@ -55,6 +55,10 @@ module JekyllRelativeLinks
     safe true
     priority :lowest
 
+    # warnings can be misleading e.g. if the link is in an excluded liquid tag; but might be useful in places
+    # for most things, use eg htmlproofer on the output site
+    @warn = false
+
     def initialize(config)
       @config = config
     end
@@ -65,6 +69,10 @@ module JekyllRelativeLinks
       @context = context
     end
 
+    def warn_missing_links(warn)
+      @warn = warn
+    end
+
     def generate(site)
       return if disabled?
 
@@ -139,7 +147,7 @@ module JekyllRelativeLinks
         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
+        puts "WARN: unresolved link in #{src}:  #{path}" unless url if @warn
 
       else
         url = url_for_path(pathWithText[1], src) if pathWithText

[brooklyn-docs] 03/03: apply link rewriting to links imported as children

Posted by he...@apache.org.
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

commit bb534ab630c4983a625d4a2d8bba44b8b05bc476
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Sat Sep 4 03:06:56 2021 +0100

    apply link rewriting to links imported as children
---
 _plugins/jekyll_relative_links.rb | 30 +++++++++++++++++++++---------
 _plugins/page_structure.rb        |  7 ++++++-
 _plugins/read.rb                  |  8 ++++----
 3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/_plugins/jekyll_relative_links.rb b/_plugins/jekyll_relative_links.rb
index 22691d4..5e915e5 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 AMP output):
+# distributed under the MIT License as follows (note this is only used to build the docs, not included with any Brooklyn output):
 
 # MIT License
 #
@@ -43,7 +43,7 @@ module JekyllRelativeLinks
     FRAGMENT_REGEX = %r!(#.+?|)?!.freeze
     TITLE_REGEX = %r{(\s+"(?:\\"|[^"])*(?<!\\)"|\s+"(?:\\'|[^'])*(?<!\\)')?}.freeze
     FRAG_AND_TITLE_REGEX = %r!#{FRAGMENT_REGEX}#{TITLE_REGEX}!.freeze
-    INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]+?)#{FRAG_AND_TITLE_REGEX}\)!.freeze
+    INLINE_LINK_REGEX = %r!\[#{LINK_TEXT_REGEX}\]\(([^\)]*?)#{FRAG_AND_TITLE_REGEX}\)!.freeze
     REFERENCE_LINK_REGEX = %r!^\s*?\[#{LINK_TEXT_REGEX}\]: (.+?)#{FRAG_AND_TITLE_REGEX}\s*?$!.freeze
     LINK_REGEX = %r!(#{INLINE_LINK_REGEX}|#{REFERENCE_LINK_REGEX})!.freeze
     CONVERTER_CLASS = Jekyll::Converters::Markdown
@@ -91,26 +91,38 @@ module JekyllRelativeLinks
       end
     end
 
+
     def replace_relative_links!(document)
-      url_base = File.dirname(document.relative_path)
       return document if document.content.nil?
 
-      document.content = document.content.dup.gsub(LINK_REGEX) do |original|
+      document.content = replace_relative_links_in_content(document.content, document.relative_path)
+
+      replace_relative_links_excerpt!(document)
+    rescue ArgumentError => e
+      raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
+    end
+
+    def replace_relative_links_in_content(content, relative_to_path)
+      url_base = File.dirname(relative_to_path)
+
+      content.dup.gsub(LINK_REGEX) do |original|
         link = link_parts(Regexp.last_match)
+
+        if (link.path == "" && link.fragment == "" && link.text && link.text.start_with?("http"))
+          link.path = link.text
+          return replacement_text(link)
+        end
+
         next original unless replaceable_link?(link.path)
 
         path = path_from_root(link.path, url_base)
-        url  = url_for_path(path, document.relative_path)
+        url  = url_for_path(path, relative_to_path)
 
         next original unless url
 
         link.path = url
         replacement_text(link)
       end
-
-      replace_relative_links_excerpt!(document)
-    rescue ArgumentError => e
-      raise e unless e.to_s.start_with?("invalid byte sequence in UTF-8")
     end
 
     def url_for_path_absolute(path)
diff --git a/_plugins/page_structure.rb b/_plugins/page_structure.rb
index f372534..5897dff 100644
--- a/_plugins/page_structure.rb
+++ b/_plugins/page_structure.rb
@@ -214,9 +214,14 @@ module PageStructureUtils
         # render the included content with the current page renderer
         info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page => page } }
         path_for_cache = "include_page-#{context['page']}"
+
+        relative_link_parser = JekyllRelativeLinks::Generator.new(nil)
+        relative_link_parser.prepare_for_site(site)
+        $content = relative_link_parser.replace_relative_links_in_content($content, page.relative_path)
+
         page.render_liquid($content, site.site_payload, info, path_for_cache)
       end
     end
 end
 
-Liquid::Template.register_tag('child_content', PageStructureUtils::IncludePageContentTag)
\ No newline at end of file
+Liquid::Template.register_tag('child_content', PageStructureUtils::IncludePageContentTag)
diff --git a/_plugins/read.rb b/_plugins/read.rb
index f35672f..df0a26a 100644
--- a/_plugins/read.rb
+++ b/_plugins/read.rb
@@ -45,7 +45,7 @@ module JekyllRead
 
       # is there a better way to trim a leading / ?
       file = file.relative_path_from(Pathname.new("/")) unless file.relative?
-      raise "No such file #{file} in read call" unless file.exist?
+      raise "No such file #{file} in read call (from #{context.dig('page','path')})" unless file.exist?
       file
     end
 
@@ -56,9 +56,9 @@ module JekyllRead
       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)
+      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