Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions modules/blox-tailwind/layouts/_partials/badges/altmetric.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{/*
Altmetric badge embed

Usage:
{{ partial "badges/altmetric" (dict "page" $page "is_list" $is_list) }}

Config flags:
params.features.altmetric.enable: true|false

Front matter options (any of following):
altmetric: true | "<altmetric_id>" | hugoblox.ids.altmetric
doi / hugoblox.ids.doi
arxiv_number | arxiv | eprint | hugoblox.ids.arxiv
pmid | isbn
*/}}

{{ $enabled := site.Params.features.altmetric.enable | default true }}
{{ if not $enabled }}{{- return -}}{{ end }}

{{ $page := .page }}

{{/* Gather identifiers */}}
{{ $alt_val := $page.Params.altmetric }}
{{ $alt_str := printf "%v" $alt_val }}
{{ $has_explicit_alt_id := and $alt_val (ne (lower $alt_str) "true") }}
{{ $enabled_by_param := or (eq (lower $alt_str) "true") (eq $alt_val true) }}

{{ $doi := $page.Params.doi | default "" }}
{{ $arxiv := or ($page.Params.arxiv_number | default "") ($page.Params.arxiv | default "") ($page.Params.eprint | default "") }}
{{ $pmid := $page.Params.pmid | default "" }}
{{ $isbn := $page.Params.isbn | default "" }}

{{/* Support new HugoBlox IDs schema if present */}}
{{ $hb_ids := index $page.Params "hugoblox" "ids" }}
{{ with $hb_ids }}
{{ if and (not $doi) (index . "doi") }}
{{ $doi = index . "doi" }}
{{ end }}
{{ if and (not $arxiv) (index . "arxiv") }}
{{ $arxiv = index . "arxiv" }}
{{ end }}
{{ if and (not $pmid) (index . "pmid") }}
{{ $pmid = index . "pmid" }}
{{ end }}
{{ if and (not $isbn) (index . "isbn") }}
{{ $isbn = index . "isbn" }}
{{ end }}
{{ end }}

{{/* Render only if enabled via altmetric param (true or explicit id) */}}
{{ if or $has_explicit_alt_id $enabled_by_param }}
<span class="inline-flex items-center align-middle whitespace-nowrap leading-none" style="vertical-align: middle;">
<span class="altmetric-embed" data-badge-type="2" data-badge-popover="bottom"
{{ if $has_explicit_alt_id }}data-altmetric-id="{{ $alt_str }}"{{ else }}
{{ if $arxiv }}data-arxiv-id="{{ $arxiv }}"{{ else if $doi }}data-doi="{{ $doi }}"{{ else if $pmid }}data-pmid="{{ $pmid }}"{{ else if $isbn }}data-isbn="{{ $isbn }}"{{ end }}
{{ end }}
></span>
<script>
if (!window._altmetric_embed_loaded) {
var s = document.createElement('script');
s.src = 'https://d1bxh8uas1mnw7.cloudfront.net/assets/embed.js';
s.async = true;
document.head.appendChild(s);
window._altmetric_embed_loaded = true;
}
</script>
</span>

{{ end }}
65 changes: 65 additions & 0 deletions modules/blox-tailwind/layouts/_partials/badges/dimensions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{/*
Dimensions badge embed

Usage:
{{ partial "badges/dimensions" (dict "page" $page "is_list" $is_list) }}

Config flags:
params.features.dimensions.enable: true|false

Front matter options:
dimensions: true | "<dimensions_id>"
doi / hugoblox.ids.doi (fallback)
pmid / hugoblox.ids.pmid (fallback)
*/}}

{{ $enabled := site.Params.features.dimensions.enable | default true }}
{{ if not $enabled }}{{- return -}}{{ end }}

{{ $page := .page }}

{{ $dim_val := $page.Params.dimensions }}
{{ $dim_str := printf "%v" $dim_val }}
{{ $has_explicit_dim_id := and $dim_val (ne (lower $dim_str) "true") (ne (lower $dim_str) "false") }}

{{ $doi := $page.Params.doi | default "" }}
{{ $pmid := $page.Params.pmid | default "" }}

{{/* Support new HugoBlox IDs schema if present */}}
{{ $hb_ids := index $page.Params "hugoblox" "ids" }}
{{ with $hb_ids }}
{{ if and (not $doi) (index . "doi") }}
{{ $doi = index . "doi" }}
{{ end }}
{{ if and (not $pmid) (index . "pmid") }}
{{ $pmid = index . "pmid" }}
{{ end }}
{{ end }}

{{/* Determine explicit off switch */}}
{{ $has_param := isset $page.Params "dimensions" }}
{{ $is_disabled := and $has_param (or (eq (lower $dim_str) "false") (eq $dim_val false)) }}

{{/* Render if: not disabled AND (explicit id OR enabled via param OR DOI/PMID available) */}}
{{ $enabled_by_param := or (eq (lower $dim_str) "true") (eq $dim_val true) }}
{{ if and (not $is_disabled) (or $has_explicit_dim_id (or $enabled_by_param (or $doi $pmid))) }}
<span class="inline-flex items-center align-middle whitespace-nowrap leading-none" style="vertical-align: middle;">
<span class="__dimensions_badge_embed__"
{{ if $has_explicit_dim_id }}data-id="{{ $dim_str }}"{{ else }}
{{ if $doi }}data-doi="{{ $doi }}"{{ else if $pmid }}data-pmid="{{ $pmid }}"{{ end }}
{{ end }}
data-style="small_rectangle" data-legend="hover-bottom" style="margin-bottom: 3px;">
</span>
<script>
if (!window.__dimensions_embed_script_loaded__) {
var s = document.createElement('script');
s.src = 'https://badge.dimensions.ai/badge.js';
s.async = true;
s.setAttribute('charset', 'utf-8');
document.head.appendChild(s);
window.__dimensions_embed_script_loaded__ = true;
}
</script>
</span>

{{ end }}
106 changes: 106 additions & 0 deletions modules/blox-tailwind/layouts/_partials/badges/inspire.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{{/*
InspireHEP citation count link

Usage:
{{ partial "badges/inspire" (dict "page" $page "is_list" $is_list) }}

Controlled by site param:
params.features.inspirehep.enable: true|false
*/}}

{{ $enabled := site.Params.features.inspirehep.enable | default false }}
{{ if $enabled }}

{{ $page := .page }}
{{ $doi := $page.Params.doi | default "" }}
{{ $arxiv := $page.Params.arxiv_number | default "" }}
{{ $inspire_id := $page.Params.inspirehep_id | default "" }}
{{/* Support new HugoBlox IDs schema if present */}}
{{ $hb_ids := index $page.Params "hugoblox" "ids" }}
{{ with $hb_ids }}
{{ if and (not $doi) (index . "doi") }}
{{ $doi = index . "doi" }}
{{ end }}
{{ if and (not $arxiv) (index . "arxiv") }}
{{ $arxiv = index . "arxiv" }}
{{ end }}
{{ if and (not $inspire_id) (or (index . "inspirehep") (index . "inspirehep_id") (index . "inspire")) }}
{{ $inspire_id = (or (index . "inspirehep") (index . "inspirehep_id") (index . "inspire")) }}
{{ end }}
{{ end }}

{{ $q := "" }}
{{ if and $inspire_id (ne (printf "%v" $inspire_id) "") }}
{{/* Use explicit Inspire control number if provided */}}
{{ else if $doi }}
{{/* Prefer DOI when available */}}
{{ $q = printf "doi:%s" $doi }}
{{ else if $arxiv }}
{{ $q = printf "arxiv_eprints.value:%s" $arxiv }}
{{ end }}

{{ if and $inspire_id (ne (printf "%v" $inspire_id) "") }}
{{ $api := printf "https://inspirehep.net/api/literature/%v?fields=citation_count,control_number" $inspire_id }}
{{ $data := dict }}
{{ with (resources.GetRemote $api) }}
{{ with ( . | transform.Unmarshal ) }}
{{ $data = . }}
{{ end }}
{{ end }}
{{ $meta := index $data "metadata" }}
{{ $count := index $meta "citation_count" }}
{{ $count_num := or $count 0 }}
{{ $count_str := printf "%d" (int $count_num) }}
{{/* Use the provided ID for the link to avoid float formatting */}}
{{ $cn_str := printf "%v" $inspire_id }}
{{ if $cn_str }}
{{ $inspire_url := printf "https://inspirehep.net/literature/%s" $cn_str }}
{{ $badge := site.Params.features.inspirehep.badge | default true }}
{{ if $badge }}
<a class="inline-flex items-center align-middle whitespace-nowrap leading-none" href="{{ $inspire_url }}" aria-label="InspireHEP link" target="_blank" rel="noopener" role="button" style="vertical-align: middle;">
<img src="https://img.shields.io/badge/inspire-{{ $count_str }}-001628?logo=inspire&logoColor=001628&labelColor=beige" alt="{{ $count_str }} InspireHEP citations">
</a>
{{ else }}
<a class="hb-attachment-link {{ if .is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $inspire_url }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "link" "attributes" "style=\"height: 1em\" class='inline-block'") }}
Inspire citations: {{ $count_str }}
{{ partial "functions/get_icon" (dict "name" "arrow-top-right-on-square" "attributes" "style=\"height: 1em;\" class=\"inline-flex h-4 w-4 ml-1 align-text-top\"") }}
</a>
{{ end }}
{{ end }}
{{ else if $q }}
{{ $api := printf "https://inspirehep.net/api/literature?q=%s&size=1&fields=control_number,citation_count" ($q | urlquery) }}
{{ $data := dict }}
{{ with (resources.GetRemote $api) }}
{{ with ( . | transform.Unmarshal ) }}
{{ $data = . }}
{{ end }}
{{ end }}

{{ $hits := index $data "hits" "hits" }}
{{ if and $hits (gt (len $hits) 0) }}
{{ $meta := index $hits 0 "metadata" }}
{{ $count := index $meta "citation_count" }}
{{ $count_num := or $count 0 }}
{{ $count_str := printf "%d" (int $count_num) }}
{{ $cn := index $meta "control_number" }}
{{ $cn_str := printf "%d" (int $cn) }}
{{ if $cn_str }}
{{ $inspire_url := printf "https://inspirehep.net/literature/%s" $cn_str }}
{{ $badge := site.Params.features.inspirehep.badge | default true }}
{{ if $badge }}
<a class="inline-flex items-center align-middle whitespace-nowrap leading-none" href="{{ $inspire_url }}" aria-label="InspireHEP link" target="_blank" rel="noopener" role="button" style="vertical-align: middle;">
<img src="https://img.shields.io/badge/inspire-{{ $count_str }}-001628?logo=inspire&logoColor=001628&labelColor=beige" alt="{{ $count_str }} InspireHEP citations">
</a>
{{ else }}
<a class="hb-attachment-link {{ if .is_list }}hb-attachment-small{{else}}hb-attachment-large{{end}}" href="{{ $inspire_url }}" target="_blank" rel="noopener">
{{ partial "functions/get_icon" (dict "name" "link" "attributes" "style=\"height: 1em\" class='inline-block'") }}
Inspire citations: {{ $count_str }}
{{ partial "functions/get_icon" (dict "name" "arrow-top-right-on-square" "attributes" "style=\"height: 1em;\" class=\"inline-flex h-4 w-4 ml-1 align-text-top\"") }}
</a>
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{/* Full-width wrapper so the list can reflow on mobile. */}}
<div class="mt-16 sm:mt-20 w-full">
<div class="flex w-full max-w-3xl mx-auto flex-col space-y-10 sm:space-y-16">
Loading