LouisBarranqueiro / hexo-theme-tranquilpeak

:lipstick: A gorgeous responsive theme for Hexo blog framework
https://louisbarranqueiro.github.io/hexo-theme-tranquilpeak/
GNU General Public License v3.0
1.86k stars 484 forks source link

Open external link in new tab from Sidebar #87

Closed kaedea closed 9 years ago

kaedea commented 9 years ago

Now open external links from sidebar will not open in new tab. The setting of HEXO's config.yml works only in post concent. Please consider to add this feature. Me myself use JS to support this in the following code, but I think this is not so good.

$(document).ready(function() {
   $('a').each(function() {
      var a = new RegExp('/' + window.location.host + '/');
      if (!a.test(this.href)) {
      $(this).attr("target","_blank");
      }
   });
});
···
chawyehsu commented 9 years ago

I consider not everyone would need this feature. :smiley:

LouisBarranqueiro commented 9 years ago

I agree with @h404bi. I think that open an external link in a new tab is the right default behavior. But your script do the job for all links of the page. I don't really understand what do you want exactly? Why do you talk about the sidebar if your script affects all links?

kaedea commented 9 years ago

I am not asking to add my script. I need this feature to open an external link in a new tab. And this script works for me (relative link will not open in new tab). But i think using JS is not better rather than using CSS. I ask for help how to use css to support this feature.

chawyehsu commented 9 years ago

Ok, I misunderstood Please consider to add this feature.... I guess you want to let those external links such as GitHub, Twitter to be opened in a new tab, right? If yes, actually the theme has the implementation, see /layout/partial/sidebar.ejs#L19.

LouisBarranqueiro commented 9 years ago

As @h404bi said, the theme has already this behavior for external links in sidebar. Don't really understand what do you want :D

kaedea commented 9 years ago

I am using release 1.3.0, setting the following code for external link of my github page. It will not working, opening github in the current tab.

 author_links:
         github:
             title: global.github
             url: https://github.com/kaedea
             icon: github
        # stack_overflow:
        #     title: global.stack_overflow
        #     url: http://stackoverflow.com/users
        #     icon: stack-overflow
        # twitter:
        #     title: global.twitter
        #     url: https://twitter.com/
        #     icon: twitter
        # facebook:
        #     title: global.facebook
        #     url: https://facebook.com/
        #     icon: facebook
        # google_plus:
        #     title: global.google_plus
        #     url: https://plus.google.com/
        #     icon: google-plus
        # linked_in:
        #     title: global.linked_in
        #     url: https://www.linkedin.com/profile/
        #     icon: linkedin
         mail:
             title: global.mail
             url: mailto:kidhaibara@gmail.com
             icon: envelope-o
chawyehsu commented 9 years ago

Have you tried the original theme(i.e. without change anything), May be you can make a new hexo directory for testing the theme, just use the original theme files. If it works, then you can reconfigure your changes.

LouisBarranqueiro commented 9 years ago

You have opened an other issue about 1.3.0 bug about author location and biography but you hadn't the right configuration file from tranquilpeak 1.3.0. Please be sure to have the right version with all files. It works perfectly with.

kaedea commented 9 years ago

to LouisBarranqueiro

I did use the release 1.3.0. The issuse about author location and biography I mistaked is becasue the docs of 1.3.0 said that I could configure this in the theme _config.yml.

I will try to download 1.3.0 again and only set the external link in sidebar to make sure whether it work or not.

LouisBarranqueiro commented 9 years ago

It works, and just checked 2min ago. :)

kaedea commented 9 years ago

Does not work for me. enter image description here

I download this version. enter image description here

Just add this link. enter image description here

hexo version info:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.1.1"
  },
  "dependencies": {
    "hexo": "^3.1.0",
    "hexo-deployer-git": "0.0.4",
    "hexo-generator-archive": "^0.1.2",
    "hexo-generator-category": "^0.1.2",
    "hexo-generator-feed": "^1.0.3",
    "hexo-generator-index": "^0.1.2",
    "hexo-generator-tag": "^0.1.1",
    "hexo-renderer-ejs": "^0.1.0",
    "hexo-renderer-marked": "^0.2.4",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.2"
  }
}
LouisBarranqueiro commented 9 years ago

look your settings of google chrome

kaedea commented 9 years ago

I have used several Browser and get the same problem, using the default setting of the browser. I look into the html code and found target="_blank" in the external link in the post area, while found nothing in the link in the sidebar.

in the sidebar enter image description here

in the post enter image description here

Do you have target="_blank" in your sidebar's exteral link?

LouisBarranqueiro commented 9 years ago

Strange! :D look this with 1.3.0 built version capture d ecran 2015-08-28 a 14 38 21

kaedea commented 9 years ago

Is that possible that the hexo version make these diff?

LouisBarranqueiro commented 9 years ago

I don't think so

chawyehsu commented 9 years ago

@kaedea absolutely not, I see you use hexo 3.1.1, me too.

chawyehsu commented 9 years ago

Please try to make a new hexo directory(hexo init test1) for testing the theme, and see whether it works.

MattieTK commented 9 years ago

@kaedea sorry for the obvious question, but are you making the edit inside the hexo _config.yaml or using the other _config.yaml inside the theme's directory?

Because you need to use the latter. This confused me initially also.

LouisBarranqueiro commented 9 years ago

@kaedea is it fixed?

kaedea commented 9 years ago

I repeat this in another computer and it works. I am trying to find the diff. Please close this issue. Sorry to offer useless info.

LouisBarranqueiro commented 9 years ago

ok good to know :) If you got the answer, write a comment to know what was the problem :)