如何在 jekyll 生成的站点中设置 asset_host?
How do I set up asset_host in a jekyll generated site?
我有一个 rails 4 应用程序正确使用 config.action_controller.asset_host = "xxxxxxx.cdn.com" 渲染资产 urls 指向到 CDN。
该应用程序还有一个使用 jekyllrb 的文档站点。现在我也希望能够从 CDN 引用资产,但到目前为止运气不好。
我找不到有关如何为文档站点设置 CDN 主机的文档。
我正在尝试这样的事情:
<img type="image/svg+xml" src="{{ '/docs/images/' | append: page.logo_image | asset_url}}">
但运气不好,我只得到图像 url 但没有 cdn 的东西。我找到的都是 Shoppify 链接(我想也可以使用 Liquid)
欢迎任何提示!
谢谢
找到这个:
Jekyll configuration for CloudFront To make it easy to serve my assets
from CloudFront, I set up a custom Liquid filter:
module Jekyll
module AssetFilter
def cdn(input)
"#{@context.registers[:site].config['cdn']}/#{input}"
end
end
end
Liquid::Template.register_filter(Jekyll::AssetFilter)
Save this in _plugins/cdn.rb
off the root of your Jekyll site’s directory.
Then I added a CDN entry to my _config.yml
file. If I comment this line out, my
assets will be served off of S3 (or localhost if I’m running Jekyll locally).
cdn: http://cdn.maxmasnick.com
Whenever I want an asset to be served by the CDN, I pass it through this Liquid filter. For example, in my layout file I have:
<link rel="stylesheet" href="{{ "assets/css/frameless.css" | cdn }}" />
来源:
http://www.maxmasnick.com/2012/01/21/jekyll_s3_cloudfront/
我有一个 rails 4 应用程序正确使用 config.action_controller.asset_host = "xxxxxxx.cdn.com" 渲染资产 urls 指向到 CDN。
该应用程序还有一个使用 jekyllrb 的文档站点。现在我也希望能够从 CDN 引用资产,但到目前为止运气不好。
我找不到有关如何为文档站点设置 CDN 主机的文档。
我正在尝试这样的事情:
<img type="image/svg+xml" src="{{ '/docs/images/' | append: page.logo_image | asset_url}}">
但运气不好,我只得到图像 url 但没有 cdn 的东西。我找到的都是 Shoppify 链接(我想也可以使用 Liquid)
欢迎任何提示!
谢谢
找到这个:
Jekyll configuration for CloudFront To make it easy to serve my assets from CloudFront, I set up a custom Liquid filter:
module Jekyll
module AssetFilter
def cdn(input)
"#{@context.registers[:site].config['cdn']}/#{input}"
end
end
end
Liquid::Template.register_filter(Jekyll::AssetFilter)
Save this in
_plugins/cdn.rb
off the root of your Jekyll site’s directory.Then I added a CDN entry to my
_config.yml
file. If I comment this line out, my assets will be served off of S3 (or localhost if I’m running Jekyll locally).cdn: http://cdn.maxmasnick.com
Whenever I want an asset to be served by the CDN, I pass it through this Liquid filter. For example, in my layout file I have:
<link rel="stylesheet" href="{{ "assets/css/frameless.css" | cdn }}" />
来源: http://www.maxmasnick.com/2012/01/21/jekyll_s3_cloudfront/