{%- comment -%} 该组件可以生成一个 `img` 标签或者一个 `div style="background-..."`。
{%- endcomment -%} {%-assign is_global_asset = is_global_asset | default: false -%} {%- if bg -%} {%- comment -%} 背景图像 {%- endcomment -%} {%-assign tag_name = tag_name | default: 'div' -%} {%-assign self_closing = self_closing | default: false -%} {%- comment -%} 我们自己渲染属性并过滤掉“style”。 {%- endcomment -%} {%-assign attr_list = attrs | to_attrs: list: true -%} {%- capture additional_attrs -%} {%- comment -%} 包括来自上下文的属性。 {%- endcomment -%} {%- for attr in attr_list -%} {%- except attr[0] == 'style' -%} {{- ' ' -}} {{- attr[0] -}} {%- if attr[1].size > 0 -%} ="{{- attr[1] -}}" {%- endif -%} {%- endunless -%} {%- endfor -%} {{- ' ' -}} style=" {%- comment -%} 渲染背景样式。 如果我们没有获得图像,则使用 src。 {%- endcomment -%} {%- 分配 has_bg_image = false -%} {%- 分配 has_bg_size = false -%} {%- 分配 has_bg_position_x = false -%} {%- 分配 has_bg_position_y = false -%} {%- 分配 has_bg_repeat = false -%} {%- for prop in bg -%} {%- case prop[0] -%} {%- 当 'image' -%} {%- 分配 has_bg_image = true -%} {%- 当 'size' -%} {%- 分配 has_bg_size = true -%} {%- 当 'position' -%} {%- 分配 has_bg_position_x = true -%} {%- 分配 has_bg_position_y = true -%} {%- 当 'position-x' -%} {%- 分配 has_bg_position_x = true -%} {%- 当'position-y' -%} {%- 分配 has_bg_position_y = true -%} {%- 当'repeat' -%} {%- 分配 has_bg_repeat = true -%} {%- endcase -%} background-{{- prop[0] -}}: {{- prop[1] -}}; {%- endfor -%} {%- 除非 has_bg_image -%} background-image: url('{{- src | asset_url: global: is_global_asset -}}'); {%- endunless -%} {%- 除非 has_bg_size -%} background-size: cover; {%- endunless -%} {%- 除非 has_bg_position_x -%} background-position-x: center; {%- endunless -%} {%- 除非 has_bg_position_y -%} background-position-y: center; {%- endunless -%} {%- except has_bg_repeat -%} background-repeat: no-repeat; {%- endunless -%} {%- comment -%} 从 style 属性添加任何样式。 {%- endcomment -%} {{- attrs.style -}} " {%- endcapture -%} {%- comment -%} 删除 attrs 以便我们不会渲染它们两次。 {%- comment -%} 从 `tag_name` 中删除前导和尾随空格。 {%- endcomment -%} {%-assign tag_name = tag_name | strip -%} {%- comment -%} 处理 `tag_name: ''` 情况。 {%- endcomment -%} {%- if tag_name and tag_name.size < 1 -%} {%-assign tag_name = false -%} {%- endif -%} {%- if tag_name -%} <{{ tag_name }} {{- attrs | to_attrs -}} {{- additional_attrs -}} {%- if self_closing == true -%} {{- ' /' -}} {%- endif -%} > {%- endif -%} {%- 除非 self_closing == true -%} {%- ifslot -%} {%- slot -%} {%- else -%} {{- inner_html -}} {%- endifslot -%} {%- if tag_name -%} {%-endif-%} {%-endunless-%}
{%- 捕获 id_attr -%} {{- item.id -}} {%- endcapture -%} {%- 如果 id_attr.size > 0 -%} {%- 捕获 id_attr -%} id="{{ item.id }}" {%- endcapture -%} {%- endif -%} {%- 分配 attrs = item.attrs | merge_props: class: 'card card--post' -%} {%- 如果 link == false 或 item.link == nil 或 item.link.size < 1 或 item.link_text == nil 或 item.link_text.size < 1 -%} {% else %} {% endif %} {%- 除非 img == false 或 item.img == nil -%} {%- 分配 _img = item.img -%} {%- 分配 img_attrs = _img.attrs | merge_props: class: 'card__image' -%} {%- 包括'atom/img', alt: _img.alt, src: _img.src, srcset: _img.srcset, size: _img.sizes, attrs: img_attrs, bg: _img.bg -%} {%- endunless -%} {{ item.title}} {%- 除非 author == false 或 item.author == nil 或 item.author.size < 3 -%} {{ item.author }} {%- endunless -%} {%- 除非 date == false 或 item.date == nil 或 item.date.size < 3 -%} {{ item.date }} {%- endunless -%} {%- 除非 summary == false 或 item.summary == nil 或 item.summary.size < 1 -%} {{ item.summary}} {%- endunless -%} {%- 除非 link == false 或 item.link == nil 或 item.link.size < 1 或 item.link_text == nil 或 item.link_text.size < 1 -%} {{ item.link_text}} {%- 结束 -%} {%- 如果 link == false 或 item.link == nil 或 item.link.size < 1 或 item.link_text == nil 或 item.link_text.size < 1 -%} {% 其他 %} {% endif %}
*所有信息如有变更。 图片可能包含模型。 个别结果无法保证,可能会有所不同。