如何获取 url 的 wicket 图像以在开放图元标记中使用它
How to get url of wicket image to use it in open graph meta tags
在我的站点中我有图片:
add(new Image("logoImg", new DynamicImageResource() {
private static final long serialVersionUID = 1L;
@Override
protected byte[] getImageData(IResource.Attributes attributes) {
return tournamentDto.getLogo();
}
}));
如何生成此图像的 url 以在 meta 中使用它:
@Override
public void renderHead(IHeaderResponse response) {
response.render(forMetaTag("og:image", "??"));
super.renderHead(response);
}
public static final String META_TAG = "meta";
public static MetaDataHeaderItem forMetaTag(String name, String content) {
MetaDataHeaderItem headerItem = new MetaDataHeaderItem(META_TAG);
headerItem.addTagAttribute("property", Model.of(name));
headerItem.addTagAttribute("content", Model.of(content));
return headerItem;
}
@Override
public void renderHead(IHeaderResponse response) {
CharSequence imageUrl = urlFor(get("logoImg"));
response.render(forMetaTag("og:image", imageUrl));
super.renderHead(response);
}
// the Component must implement IRequestListener
private CharSequence urlFor(Component component) {
PageAndComponentProvider provider =
new PageAndComponentProvider(component.getPage(), component);
return urlFor(new ListenerRequestHandler(provider));
}
在我的站点中我有图片:
add(new Image("logoImg", new DynamicImageResource() {
private static final long serialVersionUID = 1L;
@Override
protected byte[] getImageData(IResource.Attributes attributes) {
return tournamentDto.getLogo();
}
}));
如何生成此图像的 url 以在 meta 中使用它:
@Override
public void renderHead(IHeaderResponse response) {
response.render(forMetaTag("og:image", "??"));
super.renderHead(response);
}
public static final String META_TAG = "meta";
public static MetaDataHeaderItem forMetaTag(String name, String content) {
MetaDataHeaderItem headerItem = new MetaDataHeaderItem(META_TAG);
headerItem.addTagAttribute("property", Model.of(name));
headerItem.addTagAttribute("content", Model.of(content));
return headerItem;
}
@Override
public void renderHead(IHeaderResponse response) {
CharSequence imageUrl = urlFor(get("logoImg"));
response.render(forMetaTag("og:image", imageUrl));
super.renderHead(response);
}
// the Component must implement IRequestListener
private CharSequence urlFor(Component component) {
PageAndComponentProvider provider =
new PageAndComponentProvider(component.getPage(), component);
return urlFor(new ListenerRequestHandler(provider));
}