對於任何人的方便,我在我的項目採用了理查德的解決方案,並創建了一個簡單的Ruby腳本,取代在靜態HTML錯誤/維護頁面鏈接資產。這是非常狡猾的,不是一個耙子任務,所以它儘可能快。無論如何它沒有Rails depenency,除了它必須從rails根目錄運行。
#!/usr/bin/env ruby
require 'yaml'
GLOBS = %w(public/errors_source/*.html)
MANIFEST = "public/assets/manifest.yml"
manifest = YAML::load(File.open(MANIFEST))
GLOBS.each do |glob|
Dir.glob(glob).each do |file|
next unless File.file?(file)
contents = File.read(file)
manifest.each do |asset, compiled_asset|
contents.gsub!(asset, "/assets/#{compiled_asset}")
end
File.open(file.gsub('errors_source/',''), 'w') do |outfile|
outfile.write(contents)
end
end
end
腳本預計靜態HTML錯誤/維護網頁住errors_source
目錄,並將它們複製(替換爲他們的哈希版本的資產)的軌道根目錄下。
然後樣品維護頁面可能看起來像這樣(請注意CSS資產鏈接和標識圖像 - 這些資產只需與主樑的代碼共享):
<html>
<head>
...
<link href="application.css" media="screen" rel="stylesheet" type="text/css"/>
</head>
<body>
...
<a href="/"><img src="logo.png" width="161" height="61"/></a>
...
</body>
</html>