简体   繁体   English

使用Bloggy gem在Rails站点中的Jekyll博客:在每个构建中,如何在博客中使用Rails CSS?

[英]Jekyll blog in Rails site using Bloggy gem: how do I use the Rails css for the blog, on each build?

I've got a Rails site with a Jekyll blog incorporated, using the Bloggy gem. 我有一个使用Bloggy宝石整合了Jekyll博客的Rails网站。

I'd like a similar look for the main site and the blog, so I want to use the css in app/assets/stylesheets, but those files are in css.scss format. 我希望主站点和博客具有相似的外观,因此我想在app / assets / stylesheets中使用css,但是这些文件采用css.scss格式。 Jekyll (in a Bloggy setup) looks for css in config/jekyll/css, and seems to only want .css files; Jekyll(在Bloggy设置中)在config / jekyll / css中查找css,并且似乎只需要.css文件。 symlinking the Rails css directory into the Jekyll hierarchy doesn't seem to to work. 将Rails css目录符号链接到Jekyll层次结构中似乎无效。

Is there a way to take advantage of the asset pipeline so that when I run jekyll:build, SCSS files from the Rails app are made into CSS files, placed in the appropriate jekyll directory, and bundled with the latest Jekyll build as it's placed into the /public/blog folder? 有没有一种方法可以利用资产管道,因此当我运行jekyll:build时,Rails应用程序中的SCSS文件被制成CSS文件,放置在适当的jekyll目录中,并与最新的Jekyll构建文件捆绑在一起/ public / blog文件夹?

Thanks! 谢谢!

Ended up getting through this by: 最终通过以下方法解决了这个问题:

  • Using the jekyll-sass gem to allow automatic transformation of the Rails app's .css.scss into .css.css files. 使用jekyll-sass gem可以将Rails应用程序的.css.scss自动转换为.css.css文件。 By symlinking the Rails app/assets/stylesheets directory into Bloggy's config/jekyll/css, this put files with the right content but wrong extensions in the correct place. 通过将Rails app / assets / stylesheets目录符号链接到Bloggy的config / jekyll / css中,可以将内容正确但扩展名错误的文件放置在正确的位置。
  • Writing a rake task to make the .css.css files into .css files. 编写rake任务,以将.css.css文件转换为.css文件。

     desc 'Make .css.css files into .css files' task :css_css do Dir.glob('public/blog/css/*.css.css').each do |file| puts `mv #{file} #{file.gsub(/\\.css\\.css$/, '.css')}` end end 

Not the prettiest solution, but it works. 不是最漂亮的解决方案,但它可以工作。

@Matthew.. You have a nice solution.. For this part I did some stuffs manually. @Matthew ..您有一个不错的解决方案。.对于这一部分,我手动进行了一些操作。 Like I added config/jekyll/css files as .css extension rather than .css.scss so when we run "rake generate" for bloggy the right format files are created on the folder public/blog/ rather css.scss. 就像我将config / jekyll / css文件添加为.css扩展名而不是.css.scss一样,因此当我们为博客运行“ rake generate”时,将在文件夹public / blog /而不是css.scss上创建正确的格式文件。

I have made the changes in my bloggy portfolio theme project repository. 我已经在博客投资组合主题项目存储库中进行了更改。 If you are planning to use my version of code, I have did some changes like added robots.txt, sitemap, and integrated bootstrap to the project. 如果您打算使用我的代码版本,则可以进行一些更改,例如向项目添加robots.txt,站点地图和集成的引导程序。 I have also removed all database connections from the rails project since it was showing errors while deploying into heroku. 我还从rails项目中删除了所有数据库连接,因为它在部署到heroku时显示错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM