generated from polymech/site-template
35 lines
754 B
JavaScript
35 lines
754 B
JavaScript
// @ts-check
|
|
import getAttributesString from "./getAttributesString.js";
|
|
|
|
export default function getLinkElement({
|
|
images = [],
|
|
preload = "",
|
|
imagesizes = "",
|
|
linkAttributes,
|
|
}) {
|
|
const imagesrcset =
|
|
preload &&
|
|
images[images.length - 1]?.sources.find(
|
|
({ format: fmt }) => fmt === preload
|
|
)?.srcset;
|
|
|
|
const attributesString = getAttributesString({
|
|
element: "link",
|
|
attributes: linkAttributes,
|
|
excludeArray: ["as", "rel", "imagesizes", "imagesrcset"],
|
|
});
|
|
|
|
const linkElement =
|
|
preload && images.length
|
|
? `<link
|
|
${attributesString}
|
|
as="image"
|
|
rel="preload"
|
|
imagesizes="${imagesizes}"
|
|
imagesrcset="${imagesrcset}"
|
|
/>`
|
|
: "";
|
|
|
|
return linkElement;
|
|
}
|