如果我使用Glob Collections,我该如何获取高高的SRC的完整路径?
问题:
我正在使用短码在/technical-seo/using-science-philosophy-organize-semantic-web.md
Isle.jpg“,” Google Photos - Aisle 5,Faversham Sainsbury的“”,“ 320,640,1024”,“ IMG响应”%}
`TemplateContentRenderError` was thrown
[11ty] > (./technical-seo/using-science-philosophy-organize-semantic-web.md)
EleventyShortcodeError: Error with Nunjucks shortcode `image`
`Template render error` was thrown
[11ty] > ENOENT: no such file or directory, open '/home/denverpr/repositories/yada-11ty-themesgrocery-isle.jpg'
是每个Glob Collection中的一个图像文件夹。我需要包括收集路径。真正的路径是/home/denverpr/repositories/yada-11ty-themes/technical-seo/images/grocery-isle.jpg
我的当前结构:我的当前结构:
├── technical-seo
├── create-jump-to-links-serp.md
├── ecommerce-site-structure-for-semantic-search.md
├── images
│ ├── grocery-isle.jpg
│ ├── optimize-local-seo.jpg
│ ├── science-semantic-web.png
│ ├── serp-jump-to-links-1.png
│ ├── serp-jump-to-links-2.png
│ ├── serp-jump-to-links-3.png
│ └── serp-jump-to-links.png
├── index.njk
├── optimizing-local-search.md
├── technical-seo.11data.js
└── using-science-philosophy-organize-semantic-web.md
我的ever> ever> ever> ever> ever>代码:
module.exports = function(src, alt, widths, sizes, classattr) {
// src input same as 'normal' site-relative path for convenience, so add base path:
src = path.dirname(__dirname) + src;
Problem:
I'm using the shortcode in /technical-seo/using-science-philosophy-organize-semantic-web.md
{% image "grocery-isle.jpg", "Google Photos – Aisle 5, Faversham Sainsbury’s", "320, 640, 1024", "img-responsive" %}
`TemplateContentRenderError` was thrown
[11ty] > (./technical-seo/using-science-philosophy-organize-semantic-web.md)
EleventyShortcodeError: Error with Nunjucks shortcode `image`
`Template render error` was thrown
[11ty] > ENOENT: no such file or directory, open '/home/denverpr/repositories/yada-11ty-themesgrocery-isle.jpg'
It's an image folder in each glob collection. I need the collection path to be included. The true path is /home/denverpr/repositories/yada-11ty-themes/technical-seo/images/grocery-isle.jpg
My current structure:
├── technical-seo
├── create-jump-to-links-serp.md
├── ecommerce-site-structure-for-semantic-search.md
├── images
│ ├── grocery-isle.jpg
│ ├── optimize-local-seo.jpg
│ ├── science-semantic-web.png
│ ├── serp-jump-to-links-1.png
│ ├── serp-jump-to-links-2.png
│ ├── serp-jump-to-links-3.png
│ └── serp-jump-to-links.png
├── index.njk
├── optimizing-local-search.md
├── technical-seo.11data.js
└── using-science-philosophy-organize-semantic-web.md
My eleventy-img
code:
module.exports = function(src, alt, widths, sizes, classattr) {
// src input same as 'normal' site-relative path for convenience, so add base path:
src = path.dirname(__dirname) + src;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在错误消息中,它表明它正在
/home/denverpr/repositories/yada-11ty-themesgrocery-isle.jpg
中查找图像,但没有找到任何内容,考虑到该图像是位于/home/denverpr/repositories/yada-11ty-themes/technical-seo/images/grocery-isle.jpg
。您还可以看到为什么生成不正确的路径。
src
将是/home/denverpr/repositories/yada-11ty-themes
(目录名)+grocery-isle.jpg
。要解决此问题,您可以使用图像的完整路径更新图像短代码,或者将正确的路径添加到图像代码中。最佳方法将取决于您的具体情况。
方法 1 - 更新短代码(并修复生成的路径):
方法 2 - 修复图像代码中的路径:
In the error message, it shows that it's looking for the image at
/home/denverpr/repositories/yada-11ty-themesgrocery-isle.jpg
but not finding anything, which makes sense given that the image is located at/home/denverpr/repositories/yada-11ty-themes/technical-seo/images/grocery-isle.jpg
.You can also see why that incorrect path is generated.
src
will be/home/denverpr/repositories/yada-11ty-themes
(the dirname thing) +grocery-isle.jpg
.To fix this, you can either update the image shortcode with the full path to the image, or add in the correct path to your image code. The best approach will depend on your specific situation.
Approach 1 - update shortcode (and also fix the generated path):
Approach 2 - fix path in image code: