Warning: Undefined array key "pmwiki" in /home/kongdmdu/pmichaud/pmwiki/pub/skins/vector/vector.php on line 14

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/kongdmdu/pmichaud/pmwiki/pub/skins/vector/vector.php on line 14

Warning: Undefined array key "pagename" in /home/kongdmdu/pmichaud/pmwiki/pub/skins/vector/vector.php on line 225

Warning: Undefined array key "pagename" in /home/kongdmdu/pmichaud/pmwiki/pub/skins/vector/vector.php on line 253
ExternalLinksFavicons - Cookbook - PmWiki

External Links Favicons

Summary: Display favicons before links to external websites
Version: 20201203
Prerequisites: A recent browser with JavaScript enabled.
Status: Beta
Maintainer: Petko
License: GPL
Categories: Links Images CSS PHP74
Users: (view / edit)

Display favicons before links to external websites

Description

This recipe places the favicons of external websites before their links. It is enabled on this page and can be tested:

* Read about something on [[https://en.wikipedia.org|Wikipedia]].
* Listen/watch interesting talks on [[https://www.ted.com|TED]].
* Watch some videos on [[https://www.youtube.com|YouTube]].
* Read the scientific and technical news on https://slashdot.org.
* Explore some [[https://virtour.fr/tours/|virtual tours in the Paris region]].
* This domain doesn't have a favicon so it displays a generic icon: https://www.example.com.

Installation

1. Place extlink-favicons.js in your pmwiki/pub directory.

2. Place the following code in local/config.php:

$HTMLFooterFmt['ext-favicons'] = 
  '<script src="$FarmPubDirUrl/extlink-favicons.js" id="extlink-favicons"
  data-selector="a.urllink" data-provider="google"></script>';

Configuration

You can change the query selector for the external links by changing the data-selector="..." attribute above, for example if your external links have custom classes, or to restrict the favicons to some area. For example, to only enable favicons in the main page area and not in the sidebars, headers and footers, you may do something like:

  data-selector="#wikitext a.urllink"

To use the recipe with Cookbook:LinkIcons, set the data-selector to "a.external":

  data-selector="a.external"

You can change the provider of the icons by changing the data-provider="..." attribute above. The recipe has 3 providers, google (default), duckduckgo (meta search engine) and yandex (a Russian search engine):

  data-provider="yandex"

or you can use a different provider $1 will become the linked domain name:

  data-provider="https://some-favicon-caching-service.com/favicons?domain=$1"

  data-provider="https://some-favicon-caching-service.com/$1.png"

Internationalization

Not applicable.

Usage

Nothing special to do, all external links will be styled automatically. See examples in the Description section above.

Notes

To do / some day / maybe

If there is interest & funding: add more providers; implement sprite-based favicons to have a single request for all favicons -- Yandex allows it; cache locally the external favicons.

Other comments/ideas welcome.

Change log / Release notes

See also

Cookbook /
ExternalLinks  Configure external links to open in a new window, have a "tooltip title", or use other CSS classes (Stable)
Favicon  Add a Favicon to your website (Mature)
PmWiki /
Links  Multiple mechanisms for creating links

Contributors

Recipe written and maintained by Petko.

Comments

See discussion at ExternalLinksFavicons-Talk

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.