Sommerregen / grav-plugin-external-links

This plugin adds small icons to external and mailto links, informing users the link will take them to a new site or open their email client.
Other
16 stars 14 forks source link

Feature Request: Detect links to pages that have redirect in frontmatter #20

Closed karfau closed 6 years ago

karfau commented 7 years ago

Do you think it makes sense to detect the redirect field in the frontmatter of a linked page, to also mark them as external?

The most trivial example I have is a page that can be linked from everywhere by just saying [/facebook](my facebook page) that redirects to the facebook page of the site owner. And it is easy to change all the links in one go by just editing the redirect filed of that page. But I also have other pages that redirect to stuff, and it is kind of cumbersome to handle this in the templates all the time, as grav does know that this page redirects to something else. (Maybe there is even a clever way to ask Grav to resolve the final URL of a route, as there are also aliases and redirects configured in different ways.)

A more simple approach could also be to have the opposite of the excludes list: list of patterns that should always be treated as external. It might be easier to implement and provides some flexibility, but of course needs some duplication in configuration to work.

Any feedback welcome, maybe also an easier way to have such global alias be recognized by the plugin.

Best Christian

Sommerregen commented 7 years ago

Hi @karfau,

although I really see the benefits of your feature request, I think it is a very special and less common use case. In Grav there exists no good way to redirect things. There is only a global settings for redirect route. If there would be some standardized way, I would opt for your request.

Having a simple include option is something that is feasible and general enough and, as you said, it is easier to implement. That's why I'll mark this issue as enhancement here. Feel free to provide a PR. I would be happy to merge it :smile:.

Kind regards, Benny

karfau commented 7 years ago

Hey Benny,

can you provide some more details to me, what you are meaning with

In Grav there exists no good way to redirect things

The docs about redirect look pretty straight forward to me. (There might be other/more things to consider, but they are not important for me to be part of this feature request.)

If you just wanted to say "I don't want the plugin to go into the detection way" that's crisp, understandable and acceptable for me.

I might be willing to provide branches/PR s for multiple approaches, if needed for deciding if the change required for that is that bad.

Best Christian

Sommerregen commented 7 years ago

Hi Christian,

Oh, you are right. I totally forgot that this method of redirects is officially supported. I thought it was a custom way to handle redirects. Alright, then there should be definitely a check for it plus an additional option to toggle the feature on or off.

Basically, it needs a check somewhere here ExternalLinks.php#L130, that finds the internal page, if the link is not external $grav['pages']->find(...) and checks its header for a redirect value.

In addition, as I already have said, I also like the idea of having an include option. Thus, both ideas will be great contributions to this plugin. If you need any help, please let me know.

Benny