Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support defining LINKS that open in the same window #185

Conversation

@haplo
Copy link
Contributor

haplo commented Oct 19, 2019

Currently all LINKS open in a new window (target="_blank"), but in some cases it's desirable to open them in the same window. For example I use it for linking to categories and tags:

LINKS = (
    ('Categories', SITEURL+'/categories#categories', False),
    ('Tags', SITEURL+'/tags#tags', False),
)

Old format and experience is still supported, this is backwards-compatible.

Currently all LINKS open in a new window (target="_blank"), but in
some cases it's desirable to open them in the same window. For example
I use it for linking to categories and tags:

LINKS = (
    ('Categories', SITEURL+'/categories#categories', False),
    ('Tags', SITEURL+'/tags#tags', False),
)

Old format and experience is still supported, this is
backwards-compatible.
@alexandrevicenzi

This comment has been minimized.

Copy link
Owner

alexandrevicenzi commented Oct 19, 2019

I don't really like another parameter.

What do you think about if we are under the same URL domain we do not open as a new tab?
What if we only open in a new one if we are actually leaving the website?

This sounds better to me and could be configurable by a setting, default to false.

@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Oct 19, 2019

That sounds like a great idea, I'm +1. Do you know of a good way to extract the domain name from the link in the template?

This is an improvement over commit 90e3ee3 so it's not necessary to
change the structure of the LINKS setting, just set relative links and
they will be open in the same window, same as the `MAIN_MENU`.
@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Oct 19, 2019

I figured out a way of opening external links (those that begin with http) in a new window, and relative links (anything else) in the same window.

@alexandrevicenzi

This comment has been minimized.

Copy link
Owner

alexandrevicenzi commented Oct 19, 2019

@haplo you can check if it is a relative link (starts with /) or if starts with SITE_URL.

@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Oct 19, 2019

You are right, better to target only internal links. I have implemented the new logic and tested it, please take a look.

@alexandrevicenzi

This comment has been minimized.

Copy link
Owner

alexandrevicenzi commented Oct 24, 2019

So, I came in a conclusion that perhaps this looks better:

LINKS = (('url', 'name'))
LINKS_IN_NEW_TAB = 'external'

LINKS_IN_NEW_TAB defaults to True in the template if not set.

Options are:

  • 'all' / True / None (= not set) - open all links in new tab
  • 'external' / 'external-only' - opens only external links in new tab, relative keep the same page
  • False, 0, or other strings - does not open anything in new tab
@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Oct 26, 2019

I like it, I think it's the right amount of flexibility. I'll work on these changes.

This setting can be modified to open all LINKS in the same window,
open all LINKS in a new window or only only external links in new
windows.
@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Oct 27, 2019

@alexandrevicenzi It's done. I learned about Jinja2 macros along the way. :)

templates/base.html Outdated Show resolved Hide resolved
haplo added a commit to haplo/blog.fidelramos.net that referenced this pull request Oct 27, 2019
This was a change I implemented for the Flex theme:
alexandrevicenzi/Flex#185
templates/base.html Outdated Show resolved Hide resolved
docs/pelicanconf.py Outdated Show resolved Hide resolved
templates/base.html Outdated Show resolved Hide resolved
haplo added 2 commits Oct 30, 2019
It was added in commit 2455759
templates/base.html Outdated Show resolved Hide resolved
templates/base.html Outdated Show resolved Hide resolved
templates/base.html Outdated Show resolved Hide resolved
@alexandrevicenzi alexandrevicenzi merged commit d97d5a5 into alexandrevicenzi:master Nov 1, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@alexandrevicenzi

This comment has been minimized.

Copy link
Owner

alexandrevicenzi commented Nov 1, 2019

@haplo have you included this new config in the wiki?

@alexandrevicenzi alexandrevicenzi added this to the 2.3.0 milestone Nov 1, 2019
@haplo haplo deleted the haplo:support-opening-links-in-same-window branch Nov 1, 2019
@haplo

This comment has been minimized.

Copy link
Contributor Author

haplo commented Nov 1, 2019

@haplo have you included this new config in the wiki?

Thanks for the heads up. I just added it to https://github.com/alexandrevicenzi/Flex/wiki/Configuration-example and https://github.com/alexandrevicenzi/Flex/wiki/Custom-Settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.