【发布时间】:2015-05-13 17:33:22
【问题描述】:
与这篇文章类似:SVG Fonts with Rails Asset Pipeline and S3 Hosting,我也有同样的问题。
我有以下 /assets/stylesheets/ace-fonts.less 文件
@font-face {
font-family: 'Icarus';
src: font-url('Lato-Reg-webfont.eot');
src: font-url('Lato-Reg-webfont.eot?#iefix') format("embedded-opentype"),
font-url('Lato-Reg-webfont.woff') format("woff"),
font-url('Lato-Reg-webfont.ttf') format("truetype"),
font-url('Lato-Reg-webfont.svg#LatoReg') format("svg") ;
font-weight: normal;
font-style: normal;
}
我正在使用 less-rails Gem (https://github.com/metaskills/less-rails)。
我的/environments/production.rb 中有这个:
config.action_controller.asset_host = "//#{ENV['AWS_S3_BUCKET']}.s3.amazonaws.com"
当我部署时,自定义字体的 URL 未正确呈现,如下所示。缺少存储桶名称。
@font-face{
font-family:'Icarus';
src:url(//.s3.amazonaws.com/assets/Lato-Reg-webfont-f6c86163de8607e667ad9b51218ab21c.eot);
src:url(//.s3.amazonaws.com/assets/Lato-Reg-webfont.eot?#iefix) format("embedded-opentype"),
url(//.s3.amazonaws.com/assets/Lato-Reg-webfont-0ab907b50400c2e1577aa82531bb5a27.woff) format("woff"),
url(//.s3.amazonaws.com/assets/Lato-Reg-webfont-fe3f3ba10b31ca6404e975e2cf4f3621.ttf) format("truetype"),
url(//.s3.amazonaws.com/assets/Lato-Reg-webfont.svg#LatoReg) format("svg");
font-weight:normal;
font-style:normal
}
但是,字体已正确上传到 S3。此外,image_tag 等其他助手也在处理图像。
我正在使用https://github.com/rumblelabs/asset_sync Gem,asset_sync.rb 文件如下所示:
if defined?(AssetSync)
AssetSync.configure do |config|
config.fog_provider = 'AWS'
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
# To use AWS reduced redundancy storage.
# config.aws_reduced_redundancy = true
config.fog_directory = ENV['AWS_S3_BUCKET']
# Invalidate a file on a cdn after uploading files
# config.cdn_distribution_id = "12345"
# config.invalidate = ['file1.js']
# Increase upload performance by configuring your region
config.fog_region = 'us-west-2'
# Don't delete files from the store, 'keep', 'delete', 'ignore'
config.existing_remote_files = "delete"
# Automatically replace files with their equivalent gzip compressed version
config.gzip_compression = true
# Use the Rails generated 'manifest.yml' file to produce the list of files to
# upload instead of searching the assets directory.
#config.manifest = true
# Fail silently. Useful for environments such as Heroku
config.fail_silently = true
end
end
【问题讨论】: