How to Get Absolute Path on Jekyll Bootstrap Page

I tried adding the facebook sharing link to the jekyll boot page, however when adding the href that FB will use in the share that I used {{ HOME_PATH }} . This turns out to be the relative path /, however (which FB does not understand). Does anyone know how to get the absolute path without the need for hard coding?

The code that gives /

 <a name="fb_share" type="button" share_url="{{ HOME_PATH }}">Share this event on Facebook</a> 
+6
source share
1 answer

Unfortunately, not through Jekyll. Jekyll is a static site generator, when it starts, it generates the entire site as HTML / CSS / etc pages, without dynamic server-side content.

However, there are solutions: hard-code url, but only in one place, so it is easy to change; or, use javascript to set it appropriately on the client side.

Pure Jekyll / Liquid

Add a line like

 host: example.com 

to _config.yml , and then refer to it as

 <a name="fb_share" type="button" share_url="http://{{ site.host }}/blah">Share this event on Facebook</a> 

Javascript

If you use jQuery, put this somewhere in your startup scripts (obviously, you can do it without jQuery, but this illustrates the technique):

 $('[name=fb_share]').each(function() { var $this = $(this); $this.attr('share_url', $this.attr('share_url').replace('HOME_PATH', document.location.host)); } 

and have a page like

 <a name="fb_share" type="button" share_url="http://HOME_PATH/blah">Share this event on Facebook</a> 

(A JS solution may require some trickery (e.g. Facebook JS download delay) depending on when / how the scripts provided by Facebook are executed.)

+6
source

Source: https://habr.com/ru/post/912900/


All Articles