Skip non-pages for external links detection
This commit is contained in:
		
							parent
							
								
									fb1ec4a2dc
								
							
						
					
					
						commit
						9487676bd8
					
				| @ -1,9 +1,21 @@ | |||||||
|  | # If the configuration sets `open_external_links_in_new_tab` to a truthy value, | ||||||
|  | # add 'target=_blank' to anchor tags that don't have `internal-link` class | ||||||
|  | 
 | ||||||
| # frozen_string_literal: true | # frozen_string_literal: true | ||||||
| require 'nokogiri' | require 'nokogiri' | ||||||
| 
 | 
 | ||||||
| # If the configuration sets `open_external_links_in_new_tab` to a truthy value, | Jekyll::Hooks.register [:notes], :post_convert do |doc| | ||||||
| # add 'target=_blank' to anchor tags that don't have `internal-link` class |   convert_links(doc) | ||||||
| Jekyll::Hooks.register [:pages, :notes], :post_convert do |doc| | end | ||||||
|  | 
 | ||||||
|  | Jekyll::Hooks.register [:pages], :post_convert do |doc| | ||||||
|  |   # jekyll considers anything at the root as a page, | ||||||
|  |   # we only want to consider actual pages | ||||||
|  |   next unless doc.path.start_with?('_pages/') | ||||||
|  |   convert_links(doc) | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | def convert_links(doc) | ||||||
|   open_external_links_in_new_tab = !!doc.site.config["open_external_links_in_new_tab"] |   open_external_links_in_new_tab = !!doc.site.config["open_external_links_in_new_tab"] | ||||||
| 
 | 
 | ||||||
|   if open_external_links_in_new_tab |   if open_external_links_in_new_tab | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Maxime Vaillancourt
						Maxime Vaillancourt