{% comment %}
    
    Item PDF embed from objectid or external link.
    This include adds a PDF embed to the page using html5 "object" element.

    E.G. --> {% include feature/pdf.html objectid="demo_002" %}

    It requires an "objectid" with the include, which is used to find the object details. Alternatively, a URL to an external pdf can be used in "objectid".
    By default no height is necessary as it uses 1x1 Bootstrap ratio style, https://getbootstrap.com/docs/5.1/helpers/ratio/

    Options: 
    - "objectid" = several options below (required)
        1. an objectid of a PDF item in this collection, e.g. "demo_004"
        2. an external link to a PDF file hosted elsewhere, e.g. "https://www.lib.uidaho.edu/digital/pdfs/cloudtypes.pdf"   
        3. a relative link to a PDF file somewhere else in this repository, e.g. "/assets/pdfs/sometrees.pdf"
    - "caption" = by default the figure include automatically adds the title of the item from your metadata. The caption option allows you to manually add a different caption, or give the value false for none. (optional)
    - "width" = will use responsive sizing to set the % size on desktop (will be 100% on mobile), choose from "25", "50", "75", or "100" (optional)
    - "height" = set embed object height in px (rather than responsive size), e.g. "800px" (optional)
    - "ratio" = use Bootstrap embed ratio options "21x9", "16x9", "4x3", or "1x1" to customize the responsive aspect ratio if not using height. 1x1 is default. (optional)

    Note: if you have issues make sure the item is a PDF file!

{%- endcomment -%}
{% if include.objectid contains "/" %}
{%- capture src -%}{{ include.objectid | relative_url }}{%- endcapture -%}
{%- capture pdf_link -%}{{ src }}{%- endcapture -%}
{%- capture pdf_caption -%}{{ include.caption }}{%- endcapture -%}
{% else %}
{%- assign item = site.data[site.metadata] | where: "objectid", include.objectid | first -%}
{%- capture src -%}{{ item.object_location | relative_url }}{% endcapture %}
{%- capture pdf_link -%}{{ '/items/' | relative_url }}{% if item.parentid %}{{ item.parentid }}.html#{{ item.objectid }}{% else %}{{ item.objectid }}.html{% endif %}{%- endcapture -%}
{%- capture pdf_caption -%}{% if include.caption %}{{ include.caption }}{% else %}{{ item.title }}{% endif %}{%- endcapture -%}
{% endif %}
<div class="feature-include">
    <figure class="figure border rounded p-1 feature-w-{{ include.width | default: '100' }}">
        <div class="{% unless include.height %}ratio ratio-{{ include.ratio | default: '1x1' }}{% endunless %}">
            <object aria-label="pdf embed of {{ pdf_caption | escape }}" {% if include.height %}width="100%" height="{{ include.height }}"{% endif %} data="{{ src }}">
                <p>The PDF is not rendering in your browser. Please <a href="{{ src }}">download the PDF</a> to view.</p>
            </object>
        </div>
        {% unless include.caption == false %}<figcaption class="figure-caption text-center"><a href="{{ pdf_link }}">{{ pdf_caption }}</a></figcaption>{% endunless %}
    </figure>
</div>