make external links open in new tab

This commit is contained in:
timurgordon
2022-08-25 14:09:11 +03:00
parent 18a96f0adc
commit 22a94bfe70
4 changed files with 4374 additions and 9 deletions

View File

@@ -39,7 +39,7 @@ render_emoji = false
# Whether external links are to be opened in a new tab
# If this is true, a `rel="noopener"` will always automatically be added for security reasons
external_links_target_blank = false
# external_links_target_blank = false
# Whether to set rel="nofollow" for all external links
external_links_no_follow = true

File diff suppressed because one or more lines are too long

View File

@@ -22,6 +22,19 @@
// Insert Twitter Pixel ID and Standard Event data below
twq('init', 'o745b');
twq('track', 'PageView');
// makes all links outside of hostname open in new tab
// from: https://stackoverflow.com/a/4425214
var links = document.links;
console.log(links)
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname) {
links[i].target = '_blank';
}
}
</script>
<!-- End Twitter universal website tag code -->

View File

@@ -10,8 +10,10 @@ Parameters:
-->
<!-- This fixes link paths in prod -->
{% if page %}
{% if "](" in body %}
{% set body_arr = body | split(pat="](") %}
{% set body = body_arr[0] %}
{% for i in body_arr %}
@@ -33,10 +35,12 @@ Parameters:
{% endif %}
<!-- This fixes image paths in local -->
<!-- makes external links in row open in new tabs-->
{% set body = body | markdown | replace(from='href="', to='target="_blank" href="') | safe %}
{% set base_url = get_url(path="")%}
{% set body = body | markdown | replace(from='target="_blank" href="' ~ base_url , to='href="' ~ base_url) | safe %}
<!-- Splits body to columns -->
{% set columns = body | safe | markdown | split(pat="|||") %}
{% set row_class = "relative pt-6 p-4 flex flex-col sm:grid sm:grid-cols-2 sm:gap-10 xl:flex xl:flex-row"%}
@@ -109,9 +113,11 @@ Parameters:
{% set row_class = row_class ~ "w-screen -mx-8 sm:-mx-12 md:-mx-16 lg:-mx-20" %}
{% endif %}
{% set url = body | split(pat="href=") | slice(start=1) | first | split(pat=">") | first | trim_start_matches(pat='"') %}
<div class="{{row_class}}" style="{{styles}}" id="{{row_id}}">
{% for column in columns%}
{% for column in columns %}
<!-- Hides empty columns if displayed vertically in small screen -->
{% if column | as_str | length < 10 %}