@11in/cloudinary 中文文档教程
Cloudinary
这提供了一些用于生成 Cloudinary URL 的简码和过滤器。 它主要只是 Cloudinary Node SDK 的包装器,尽管它会尝试进行一些强制操作以从各种输入中获取有效的公共 ID。
Usage
使用 npm 或 yarn 安装插件:
$ npm -i @11in/cloudinary --save
将其添加到您的 eleventy.config.js
:
module.exports = function (conf) {
conf.namespace('cl_', () => {
conf.addPlugin(cloudinary, {
name: "your-cloud-name",
})
});
}
您也可以设置一个名为
CLOUDINARY_URL
的环境变量。 它位于您的 Cloudinary 仪表板上,看起来像这样:CLOUDINARY_URL=cloudinary://api-key:api-secret@your-cloud-name
使用简码 & 过滤器:
{% cl_img { path: 'image.jpg', transforms: [{ width: 670 }] } %}
{{ 'image.jpg' | cl_url({width: 670}) }}
Cloudinary 相当擅长从您可能从 Cloudinary(或者说,Forestry)获得的各种 URL 中提取您的资产 ID。 因此,您也可以这样做:
{% cl_img { path: '/v1610229506/directory/2021/01/image.jpg', transforms: [{ width: 670 }] } %}
{{ 'https://res.cloudinary.com/your-cloud-name/image/upload/v1613447983/image.jpg' | cl_url({width: 670}) }}
有关详细信息,请参阅完整文档。
Cloudinary
This provides some shortcodes and filters for generating Cloudinary URLs. It's mostly just a wrapper around the Cloudinary Node SDK, although it will attempt some coercion to get valid public IDs from various kinds of input.
Usage
Install the plugin with npm or yarn:
$ npm -i @11in/cloudinary --save
Add it to your eleventy.config.js
:
module.exports = function (conf) {
conf.namespace('cl_', () => {
conf.addPlugin(cloudinary, {
name: "your-cloud-name",
})
});
}
You can alternatively set an environment variable called
CLOUDINARY_URL
. It's found on your Cloudinary dashboard, and looks something like this:CLOUDINARY_URL=cloudinary://api-key:api-secret@your-cloud-name
Use the shortcodes & filters:
{% cl_img { path: 'image.jpg', transforms: [{ width: 670 }] } %}
{{ 'image.jpg' | cl_url({width: 670}) }}
Cloudinary is fairly good at extracting your asset ids from various URLs you might get out of Cloudinary (or, say, Forestry). So you can also do something like this:
{% cl_img { path: '/v1610229506/directory/2021/01/image.jpg', transforms: [{ width: 670 }] } %}
{{ 'https://res.cloudinary.com/your-cloud-name/image/upload/v1613447983/image.jpg' | cl_url({width: 670}) }}
For more information, see the full documentation.