gpt4 book ai didi

node.js - 带有标题的图片库,在 keystonejs 上使用 CloudinaryImage

转载 作者:太空宇宙 更新时间:2023-11-03 22:00:33 25 4
gpt4 key购买 nike

我正在使用 keystonejs 和 CloudinaryImages 创建图像库。

{ type: Types.CloudinaryImages }

我需要能够为图像添加标题。

我还读过这篇文章: https://github.com/keystonejs/keystone/pull/604

但我不知道这个选项是否已经到位。

有什么想法吗?谢谢。

最佳答案

我遇到了类似的问题,我希望能够为图像提供自己的描述和其他属性,同时也将其包含在带有图库描述的图库中。

这可能超出您的要求,但这是一个图像模型:

var keystone = require('keystone'),
Types = keystone.Field.Types;

/**
* Image Model
* ==================
*/

var Image = new keystone.List('Image', {
map: { name: 'name' },
autokey: { path: 'slug', from: 'name', unique: true }
});

Image.add({
name: { type: String, required: true },
image: { type: Types.CloudinaryImage, autoCleanup: true, required: true, initial: false },
description: { type: Types.Textarea, height: 150 },
});

Image.relationship({ ref: 'Gallery', path: 'heroImage' });
Image.relationship({ ref: 'Gallery', path: 'images' });

Image.register();

包含这些图像的图库如下所示:

var keystone = require('keystone'),
Types = keystone.Field.Types;

/**
* Gallery Model
* =============
*/

var Gallery = new keystone.List('Gallery', {
map: { name: 'name' },
autokey: { path: 'slug', from: 'name', unique: true }
});

Gallery.add({
name: { type: String, required: true},
published: {type: Types.Select, options: 'yes, no', default: 'no', index: true, emptyOption: false},
publishedDate: { type: Types.Date, index: true, dependsOn: { published: 'yes' } },
description: { type: Types.Textarea, height: 150 },
heroImage : { type: Types.Relationship, ref: 'Image' },
images : { type: Types.Relationship, ref: 'Image', many: true }
});

Gallery.defaultColumns = 'title, published|20%, publishedDate|20%';
Gallery.register();

您将需要创建模板 View 和路由来处理此问题,但这并不需要太多工作 - 这些只是模型 - 如果您希望我发布我为此使用的路由,请告诉我,我使用 Handlebars 来表达我的观点,因此可能没有那么有帮助。

关于node.js - 带有标题的图片库,在 keystonejs 上使用 CloudinaryImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26802529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com