Files
.gitea
assets
content
data
layouts
static
admin
config
links
previews
shortcodes
audio.js
card.js
components.js
download.js
gallery.js
image.js
index.js
slider.js
youtube.js
icons.js
index.html
data
media
schulchronik
favicon.ico
.gitignore
.mailmap
LICENSE
config.yml
gcg-website/static/admin/shortcodes/image.js

65 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-01-02 21:58:00 +01:00
import { Card, Image, Label } from "./components.js";
import { md5 } from "../previews/page-previews/components/index.js";
const ImageShortcode = {
2023-05-29 16:22:34 +02:00
label: "Bild",
openTag: "{{< ",
closeTag: " >}}",
separator: " ",
toProps: (args) => {
if (args.length > 0) {
return {
src:
args
.find((arg) => arg.startsWith("src="))
?.split("=")[1]
.replaceAll('"', "") ?? "",
};
}
2023-05-29 16:22:34 +02:00
return { src: "" };
},
toArgs: ({ src }) => {
return [`src=\"${src}\"`];
},
control: ({ src, onChange, controlProps }) => {
const { collection, field, entry } = controlProps;
2023-05-29 16:22:34 +02:00
const handleChange = ({ path }) => {
onChange({ src: path });
};
2023-05-29 16:22:34 +02:00
const handleOpenMediaLibrary = useMediaInsert(
src,
{ collection, field },
handleChange
);
const assetSource = useMediaAsset(src, collection, field, entry);
2024-01-02 21:58:00 +01:00
return Card([
Label("Bild"),
2023-05-29 16:22:34 +02:00
Image({
assetSource,
handleOpenMediaLibrary,
2024-01-02 21:58:00 +01:00
}),
]);
2023-05-29 16:22:34 +02:00
},
preview: ({ src }) => {
return h(
"div",
{ className: "col-lg-3 col-md-4 col-sm-6" },
h(
"a",
{ className: "vb-gallery", "data-gall": md5(src) },
h("img", {
className: "img-thumbnail w-100 h-100",
style: { objectFit: "cover" },
src,
})
)
);
},
};
export default ImageShortcode;