@paroicms/site-generator-plugin
Version:
ParoiCMS Site Generator Plugin
41 lines (40 loc) • 1.47 kB
JavaScript
import { getJtRegularDocumentType, getPossibleJtLabelingFieldTypes, } from "./jt-site-schema-helpers.js";
import { indent } from "./template-helpers.js";
export function templateOfDocumentCard(ctx, docVariableName, { parentType } = {}) {
const { siteSchema } = ctx;
const possibleTypes = parentType
? (parentType.regularChildren ?? []).map((childName) => getJtRegularDocumentType(siteSchema, childName))
: undefined;
const labelingFields = getPossibleJtLabelingFieldTypes(siteSchema, possibleTypes);
const labelingTemplates = labelingFields.map((field) => {
const fieldName = ` ${docVariableName}.field.${field.name}`;
return `{% if ${fieldName} %}
<ul class="FlexWrap">
{% for labelDoc in ${fieldName} %}
<li class="Label">{{ labelDoc.title }}</li>
{% endfor %}
</ul>
{% endif %}`;
});
return `<a href="{{ ${docVariableName}.url }}">
<article>
{% if ${docVariableName}.defaultImage %}
<div>
{% set im = image(${docVariableName}.defaultImage, resize: "120x120") %}
<img
src="{{ im.url }}"
width="{{ im.width }}"
height="{{ im.height }}"
loading="lazy"
alt=""
>
</div>
{% endif %}
<div>
<h3>{{ ${docVariableName}.title }}</h3>
<p>{{ ${docVariableName}.excerpt | makeExcerpt: 40 }}</p>
${indent(labelingTemplates.join("\n"), 3, { skipFirst: true })}
</div>
</article>
</a>`;
}