【问题标题】:Hugo Docsy image path referencing with multiple languagesHugo Docsy 多语言图片路径引用
【发布时间】:2020-09-16 08:39:37
【问题描述】:

我是主题为Docsy 的静态站点生成器Hugo,但我很难提供正确的路径以便Hugo 可以找到我的图像?

我读到 Hugo 的内容组织将在 Page Bundle 或项目的 static 目录中搜索图像。 See Hugo Directory Structure: static.

我正在为我的项目中的图像使用 Page Bundle 组织。
我的图像的路径是: My_Hugo_Docsy_Project/content/en/docs/My_Page_Bundle/assets/image_file.jpg

我正在使用常规降价来包含图像,但这不起作用:

![Image1](/assets/image_file.jpg)

我相信 Docsy 的多语言功能(国际化)导致了挂起,它按语言嵌套了内容目录结构。

【问题讨论】:

    标签: internationalization markdown hugo docsy


    【解决方案1】:

    Docsy's default config.toml, sets contentDir = "content/en".

    Setting contentDir effectively changes the "site root" 用于页面捆绑资源,如图像。 “站点根”目录是 Hugo 开始寻找 image_file.jpg 的地方。

    #Hugo root directory when contentDir = "content/en"
    `My_Hugo_Docsy_Project/content/en/
    
    #Hugo root directory when contentDir = “content”
    My_Hugo_Docsy_Project/content
    

    所以markdown中的图片路径是:

    ![Image1](/docs/My_Page_Bundle/assets/image_file.jpg)

    【讨论】:

    • 一目了然,我看不出该配置对您有何影响。您正在使用页面包,因此您应该能够使用相对路径引用图像,例如assets/image_file.jpg。注意删除的前导斜杠。只是一种预感,没有经过测试。
    • 测试了您建议的标记 assets/image_file.jpg 没有前导“/”它导致 jpg 损坏。我绝对没有预料到“contentDir”正在调整 Page Bundled 资源的“站点根目录”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    相关资源
    最近更新 更多