Skip to content

Instantly share code, notes, and snippets.

@topher6345
Created November 30, 2014 02:32
Show Gist options
  • Save topher6345/e497efed7f4d1a39b48f to your computer and use it in GitHub Desktop.
Save topher6345/e497efed7f4d1a39b48f to your computer and use it in GitHub Desktop.
Inline CSS in Built Jekyll Project.
Dir[File.join('_site', '**', '*')].reject { |p| File.directory? p }
.reject { |filename| !filename[/\.html/] }
.each do |file|
main_css = File.read('_site/css/main.css')
old_contents = File.read(file)
new_contents = old_contents.gsub(
"<link href='css/main.css' rel='stylesheet'>",
"<style>#{main_css}</style>"
)
File.open(file, 'w') { |newfile| newfile.write(new_contents) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment