keithmifsud / jekyll-target-blank Goto Github PK
View Code? Open in Web Editor NEWAutomatically opens external links in a new browser for Jekyll Pages, Posts and Docs.
License: MIT License
Automatically opens external links in a new browser for Jekyll Pages, Posts and Docs.
License: MIT License
It would be great if in _config.yml
the user could add:
target-blank:
exclude:
- "/index.html"
- "/somepage"
- "/some-other-page"
So that the pages written can be excluded by the plugin.
Thank you very much!
Best,
T
Thanks you for your plug-in!
I would like to use it but some of the URL I use have Kanji's.
Do you think you'll upgrade in a future?
My Jekyll site compiles fine without the jekyll-target-blank pluging, but when I add it to my Gemfile, I get the following:
LoadError: cannot load such file -- google/protobuf_c
/Users/ian/.gems/gems/google-protobuf-3.23.0-x86_64-darwin/lib/google/protobuf.rb:51:in `require'
/Users/ian/.gems/gems/google-protobuf-3.23.0-x86_64-darwin/lib/google/protobuf.rb:51:in `rescue in <top (required)>'
/Users/ian/.gems/gems/google-protobuf-3.23.0-x86_64-darwin/lib/google/protobuf.rb:48:in `<top (required)>'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/ext/sass/embedded_sass_pb.rb:4:in `require'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/ext/sass/embedded_sass_pb.rb:4:in `<top (required)>'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/lib/sass/embedded.rb:4:in `require_relative'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/lib/sass/embedded.rb:4:in `<top (required)>'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/lib/sass-embedded.rb:4:in `require_relative'
/Users/ian/.gems/gems/sass-embedded-1.58.3-x86_64-darwin/lib/sass-embedded.rb:4:in `<top (required)>'
/Users/ian/.gems/gems/jekyll-sass-converter-3.0.0/lib/jekyll/converters/scss.rb:8:in `require'
/Users/ian/.gems/gems/jekyll-sass-converter-3.0.0/lib/jekyll/converters/scss.rb:8:in `<top (required)>'
/Users/ian/.gems/gems/jekyll-sass-converter-3.0.0/lib/jekyll-sass-converter.rb:4:in `require'
/Users/ian/.gems/gems/jekyll-sass-converter-3.0.0/lib/jekyll-sass-converter.rb:4:in `<top (required)>'
/Users/ian/.gems/gems/jekyll-4.3.2/lib/jekyll.rb:195:in `require'
/Users/ian/.gems/gems/jekyll-4.3.2/lib/jekyll.rb:195:in `<top (required)>'
/Users/ian/.gems/gems/jekyll-4.3.2/exe/jekyll:8:in `require'
/Users/ian/.gems/gems/jekyll-4.3.2/exe/jekyll:8:in `<top (required)>'
/Users/ian/.gems/bin/jekyll:23:in `load'
/Users/ian/.gems/bin/jekyll:23:in `<top (required)>'
My Gemfile looks like this:
source "https://rubygems.org"
gem "jekyll", "~> 4.3.2"
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.15.1"
gem "jekyll-sitemap", "~> 1.4.0"
gem "jekyll-paginate-v2", "~> 3.0.0"
gem "jekyll-target-blank", "~> 2.0.2"
end
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]
Moreover,
bundle info google-protobuf_c
The dependency http_parser.rb (~> 0.6.0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for java. To add those platforms to the bundle, run `bundle lock --add-platform java`.
Could not find gem 'google-protobuf_c'.
When I write the <a>
tags in HTML, often times I need to specify different and custom rel
attributes. It would be great if we could select in _config.yml
if the plugin should work only with Markdown links or in all the website, regardless if the link is in md or HTML.
Something like this could be implemented in _config.yml
:
target-blank:
md-only: true # or “false” (default value)
This feature could be game-changing!
Thank you very much for your work, @keithmifsud!
Best,
T
Great plugin! Thanks for creating it.
Please, add a setting to skip manually set attributes.
For example, sometimes I publish sponsored links written in markdown as:
[some text](https://www.sposnsor.com/){:rel="sponsored"}
jekyll-target-blank would remove rel="sponsored"
and add the default target="_blank" rel="noopener"
. This is not a desirable behavior. It should be target="_blank" rel="sponsored noopener"
instead.
Sorry, I do not know how to develop a jekyll plugin, so I cannot PR this feature.
Hello.
How to exclude certain addresses from the plugin processing?
like this:
Exclude:
true
site:
example.com
Hi there!
Trying to add this to my site here: https://github.com/giacomolaw/blog
However, as you can see from this link, the URLs do not open in new tabs: https://giacomolaw.me/blog/...
What am I doing wrong?
Thanks!
@keithmifsud Thanks for creating this plugin! It works well when a URL is hard-coded in document. But I couldn't make it work if the URL comes from a variable within site data. For example:
[Google](https://google.com)
[Google]({{ site.data.google.url }})
<a href="{{ site.data.google.url }}">Google</a>
Only the first URL is rendered with target="_blank"
Do you have any advice? Thanks again!
@buren to resubmit the PR to the pre-release branch.
A user can state in the Jeyll's _config.yml
file the following options:
target-blank:
noopener: false
noreferrer: false
Both options will be true by default.
It should not add noopener
value to the rel
attribute when so stated in _config.yml
noreferrer
It should not add noreferrer
value to the rel
attribute when so stated in _config.yml
noopener
It should not add any rel
attributes when so stated in _config.yml
Refactor Specs if needed.
Refactor main class(es).
Add any missing comments if needed.
Refactor for code style guides.
Update documentation in Readme.md
file to reflect these options.
Submit PR to pre-release branch.
Merge with the above mentioned branch once all tests are passing.
The entire body gets encapsulated in the header tag for my website. Not sure why.
Development Tasks:
_layouts
as I believe the issue occurs on the first included layout.I get this while trying to run it locally.
Any clues? I am using jekyll-target-blank 2.0.0 and jekyll 3.8.5.
I would like the user to be able to add an optional CSS class to the external links. This should be set in the config file like so:
target-blank:
add_css_classes: some-class
or multiple classes:
target-blank:
add_css_classes: some-class another-class
Test that ONE specified CSS class can be added to link without any current CSS classes.
Test that ONE specified CSS class can be added to link with ONE current CSS class.
Test that ONE specified CSS class can be added to link without more than one current CSS classes.
Test that THREE specified CSS classes can be added to link without any current CSS classes.
Test that THREE specified CSS classes can be added to link with ONE current CSS class.
Test that THREE specified CSS classes can be added to link without more than one current CSS classes.
Refactor config attribute from add_css_class
to add_css_classes
Refactor tests.
Refactor main class or classes.
process_anchor_tags(html)
method.Comment the code.
Refactor for code style and guides.
Document the new feature in Readme.md
file.
Merge to the pre release branch.
jekyll-target-blank version: 2.0.0
jekyll version: 4.1.0
OS: MacOS 10.15.4
I’m sure I installed the gem correctly, but it’s not working. What could be interfering?
I added it in "Gemfile" file (next to other plugins with same configuration, which are working correctly) and I added it in "_config.yml" plugin:
list.
then I ran:
bundle install
then
bundle update
then
bundle exec jekyll serve --trace --watch
Then I opened my localhost and clicked on a test link I wrote as [example](http://example.com)
. It opens succesfully, but in the same page. It is parsed as <a href="http://example.com">example</a>
by running bundle info jekyll-target-blank
I get this:
* jekyll-target-blank (2.0.0)
Summary: Target Blank automatically changes the external links to open in a new browser.
Homepage: https://github.com/keithmifsud/jekyll-target-blank
Path: /Library/Ruby/Gems/2.6.0/gems/jekyll-target-blank-2.0.0
What can I do?
Please, this plugin would be vital for me and I’d love it if only it worked.
Thanks a lot in advance!
Hello
current version will not work with latest Ruby 2.6.3 as Nokogiri version 1.8.5 is required.
Thought I let you know...
Keep up the good work!
Thanks for the handy plugin 👍
If would love to have a feature where I am able to configure that the attribute rel="noopener noreferrer"
should be added to all links with target="blank"
. So my goal is to add the rel
attribute where needed and not to specify the target
attribute for all external link.
This way you are able to control which links are opened in a new tab and these links are secured automatically because the plugin adds the rel
attribute with the configured values.
In the documentation for jekyll-target-blank, you might want to add a note that "url="https://some.site.name/" must exist within the site's "_config.yml" file, otherwise it crashes when trying to compile with bundle (null value).
Hi Keith,
latest version doesn't work with Jekyll v4, which seems to be a rubocop issue...
Built a local version requiring rubocop-jekyll instead and it seems to work just fine.
Would be absolutely fantastic if you could do the same.
Cheers!
According to the documentation, it is possible to set jekyll-target-blank up so that no external links are assigned target=blank without a css tag, but what about the reverse: all external links EXCEPT those with a specific css tag? Sorry if I missed this and it is supported!
sorry, there is any update with this PR?
I would like to update nokogiri on my Jekyll installation to fix this:
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-11068Thanks
Hi @cristianocasella I will now release v1.2 for the security issue and then 2.0 for Jekyll 4 which will include the security fix.
Originally posted by @keithmifsud in #35 (comment)
Hello
would you mind updating dependencies to the latest Jekyll?
The current release does not work with Jekyll 4, unfortunately.
Keep up the great work & thanks a bunch!
The plugin is not working on https://machinetranslate.org, even though we apparently set it up correctly.
Thanks in advance for any help
For example, see https://machinetranslate.org/wmt22
Expected: <a href="https://statmt.org/wmt22/" target="_blank" rel="noopener noreferrer">statmt.org/wmt22/</a>
Actual: <a href="https://statmt.org/wmt22/">statmt.org/wmt22/</a>
AFAICT, we're setting up jekyll-target-blank correctly:
https://github.com/machinetranslate/machinetranslate.org/search?q=jekyll-target-blank
Gemfile:
group :jekyll_plugins do ... gem 'jekyll-target-blank' ... end
_config.yml:
url: https://machinetranslate.org ... plugins: ... - jekyll-target-blank ...
Here's our setup:
Are we setting up jekyll-target-blank correctly?
Is there a known issue with Just The Docs?
Or maybe one of the other plugins or our CSS is interfering?
As seen in About rel=noopener, all modern browsers now implicitly set both rel="noopener"
and rel="noreferrer"
by default.
Therefore, it should be nice to remove the automatic addition of rel="noopener noreferrer"
and leave target="_blank"
only.
The user should be able to ad noopener
and noreferrer
from their _config.yml
.
Hi
is there any way of excluding an external link?
Thanks a bunch!
Hello. I noticed that after this module's 2.0.0 version gem was released, my Jekyll builds started to fail on this error. When I run it with --trace
it points to this gem with the following error message.
✗ bundle exec jekyll build -d public --trace
Configuration file: /home/user/git/gitlab/myname.gitlab.io/_config.yml
Source: /home/user/git/gitlab/myname.gitlab.io
Destination: public
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
/home/user/git/gitlab/myname.gitlab.io/vendor/bundle/ruby/2.3.0/gems/jekyll-target-blank-2.0.0/lib/jekyll-target-blank.rb:195:in `external?': undefined method `match?' for "/":String (NoMethodError)
Did you mean? match
from /home/user/git/gitlab/myname.gitlab.io/vendor/bundle/ruby/2.3.0/gems/jekyll-target-blank-2.0.0/lib/jekyll-target-blank.rb:92:in `processable_link?'
from /home/user/git/gitlab/myname.gitlab.io/vendor/bundle/ruby/2.3.0/gems/jekyll-target-blank-2.0.0/lib/jekyll-target-blank.rb:78:in `block in process_anchor_tags'
Is this line jekyll-target-blank#L195 parsable by ruby 2.3.x ?
The previous versions 1.2 and 1.1.1 seemed to work as expected.
This issue was moved from kenchan0130#10.
I'm going to be adding a site where 95% of the links are external and 5% of the links are trusted so I don't want to set nofollow.
target-blank:
rel_nofollow_skip_domains: ["example.com", "github.com"]
<a href="http://example.com" target="_blank">Example</a>
<a href="https://example.com" target="_blank">Example</a>
<a href="https://www.example.com" target="_blank">Example</a>
<a href="http://foo.github.com" target="_blank">GitHub</a>
<a href="https://www.github.com" target="_blank">GitHub</a>
<a href="https://foo.bar.github.com" target="_blank">GitHub</a>
<a href="https://somewhere.com" target="_blank" rel="nofollow">Somewhere</a>
I would like the user to be able to add other attributes such as rel="nofollow"
. This should be set in _config.yml
and should be optional.
Since we already have two values for the rel
attribute set by default, a user should be able to set a string or an array of other rel
attribute values:
target-blank:
rel: nofollow
or more than one:
target-blank:
rel: nofollow tag
Develop the feature using TDD - of course!
Test that adding rel: nofollow
in _config.yml
outputs the default rel
attributes plus the nofollow
.
Test that adding rel: nofollow tag
in _config.yml
outputs the default rel
attributes plus the nofollow tag
.
Test that adding rel: nofollow
and noopener: false
in _config.yml
outputs the default rel
attributes plus the nofollow
without the noopener
value.
Test that having both noopener: false
and noreferrer: false
in _cofig.yml
while having rel: nofollow
does not output the default rel attributes but only the additional one.
Just in case I didn't explain this well or the reader didn't get it:
Having noopener: false
in _config.yml
while having rel: noopener
still includes the noopener
value.
nofollow
is set as a rel
property.Reafctor Spec class.
Reafctor Main class.
Document the feature in the Readme.md
file.
Submit a PR to the pre-release
branch
Fix any Travis Build issues.
Mewrge with the pre-release
branch.
Building Jekyll sites throws an error if any URL contains non ASCII characters.
The User can input an entry in the Jekyll's config file to state which links should open in a new browser by specifying a CSS class name. Like so:
target-blank:
css_class: ext-link
If a css_class
is specified, only links containing that class name will open in a new browser unless overwritten by another tag of course 😄
Refactor the main class by using the initialised @config
instance variable.
Refactor tests by removing unit tests to private methods.
Enforce standards using rubocop
Comment the code.
Update the Readme.md
file to reflect this feature.
Merge into the pre-release branch.
Hi!
This plugin is exactly what I'm looking for, but it doesn't seem to be compatible with Github pages? If I'm wrong, please neglect this issue report.
Put it in my Gemfile, and it apparently installed there okay:
Installing racc 1.6.0 with native extensions
Fetching nokogiri 1.13.1 (x86_64-darwin)
Fetching nokogiri 1.13.1 (arm64-darwin)
Installing nokogiri 1.13.1 (x86_64-darwin)
Installing nokogiri 1.13.1 (arm64-darwin)
Fetching jekyll-target-blank 2.0.0
Installing jekyll-target-blank 2.0.0
Bundle complete! 9 Gemfile dependencies, 55 gems now installed.
Bundled gems are installed into `./.vendor/bundle`
Run Jekyll serve, and it blows up. The relevant error from the stack trace is:
dlopen(/Users/wook/projects/munged-org/.vendor/bundle/ruby/2.6.0/gems/nokogiri-1.13.1-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle, 0x0009):
tried: '/Users/wook/projects/munged-org/.vendor/bundle/ruby/2.6.0/gems/nokogiri-1.13.1-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle'
(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64h')), '/usr/lib/nokogiri.bundle' (no such file)
- /Users/wook/projects/munged-org/.vendor/bundle/ruby/2.6.0/gems/nokogiri-1.13.1-arm64-darwin/lib/nokogiri/2.6/nokogiri.bundle (LoadError)
As it says, I have a intel MacBook Pro. Not sure why it's calling the arm64 executable.
If I delete the arm64 nokogiri gem, then it seems to work. But any use of bundle install or bundle update puts it right back in place, which is kinda annoying. I've not found a way to exclude that gem in the Gemfile. No idea how to force it to use the right one, if that's even possible.
I'd like to extend this plugin by adding some custom liquid tags.
... more to come...
Add option open internal links in a new browser.
Hi, your plugin looks like exactly what I've been looking for! However, I (and I know a lot of other people) are using a link structure that looks something like this for external links: mydomain.com/go/whatever or mydomain.com/out/whatever
This is for link tracking purposes.
The issue is that those links look like internal to your plugin, even though in reality they are external. Short of adding a custom class to all the links (which negates the purpose of your plugin) I don't think there's a way to define these as external, currently.
I took a quick look at your code to see if it would be easy to fix myself, but my Ruby skills are unfortunately very basic. Is this something that would be relatively straight forward to add?
Hi, I'm using the minimal-mistakes template and I don't know if it's something specific to that, but jekyll-target-blank
didn't work by just adding it to the end of the Gemfile
; instead, I had to add it to the group :jekyll_plugins
section. I spent 30 minutes figuring this out so I thought it would be useful to open an issue so that it's noted.
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-paginate"
gem "jekyll-sitemap"
gem "jekyll-gist"
gem "jekyll-feed"
gem "jemoji"
gem "jekyll-include-cache"
gem "jekyll-algolia"
gem "jekyll-target-blank"
end
gem "commonmarker", "~> 0.23.4"
gem "racc", "~> 1.6"
gem "unf_ext", "~> 0.0.8"
gem "minimal-mistakes-jekyll"
gem "webrick", "~> 1.7"
Maybe README.md
should write something like this?
Add the following to your site's Gemfile (into the
group :jekyll_plugins
section if you have one):gem 'jekyll-target-blank'
Hi everyone. When this plugin is used, it causes some HTML named character entities to become unparsed, i.e. they're rendered as the raw entity string instead of the correct character. For example, …
is literally displayed as …
instead of "...". They render correctly when this plugin is removed.
It appears that it only breaks for HTML 5.0 named character entities (reference list), but pre-5.0 entities still work. Additionally, the equivalent hexadecimal and decimal entities (e.g. …
and …
) work even for the 5.0 characters.
As HTML 5.0 introduces new characters not present in previous standards, and it is good practice to use the named entity for ease of code maintenance, I believe this issue should be resolved.
jekyll-target-blank: v2.0.2 (standard config, no additional options in _config.yml
)
jekyll: v4.3.2
Other plugins: jekyll-autoprefixer, jekyll-minifier
Browser: Chrome 119, Safari 17
OS: macOS 14 Sonoma
rel=...
attribute.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.