Jekyll LF/CRLF问题与git [英] Jekyll LF/CRLF issue with git

查看:134
本文介绍了Jekyll LF/CRLF问题与git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jekyll文件夹,其中仅使用git跟踪生产部分(_site).当我运行命令使用jekyll serve -w为本地站点提供服务时,文件将更改为LF或CRLF,具体取决于我正在使用的计算机:Windows的CRLF,Mac的LF.这真的很烦人,因为每次切换操作系统时,我都会提交_site中的所有文件.

I have a Jekyll folder in which only the production part (_site) is tracked with git. When I run the command to serve the local site with jekyll serve -w, the files will be changed to LF or CRLF depending on the machine I'm working on: CRLF for Windows, LF for Mac. This is really annoying because all my files inside _site will be commited everytime I switch my OS.

我尝试使用autocrlf = false在git config文件中修复此问题,但是由于这些文件是Jekyll更高级别生成的,因此似乎完全没有影响.

I've tried to fix this in the git config file with autocrlf = false, but since the files are generated at a higher level by Jekyll it seems to have no impact at all.

是否可以告诉Jekyll以LF或CRLF的特定格式生成所有文件?

Is there a way to tell Jekyll to generate all the files in a specific format, either LF or CRLF ?

推荐答案

三个明显的解决方案:

要将CR或CRLF全局替换为LF,最简单的方法是在将文件写入目标位置时执行此操作.

To globally replace CR or CRLF by LF, the easiest way is to do it when files are written to destination.

此插件重载Jekyll:Convertible.write方法:

This plugin overload the Jekyll:Convertible.write method :

module Jekyll
  module Convertible
    def write(dest)
      ### begin overloading
      # Replaces CR and CRLF by LF
      self.output = self.output.gsub(/\r\n?/, "\n")
      ### end overloading

      path = destination(dest)
      FileUtils.mkdir_p(File.dirname(path))
      File.open(path, 'wb') do |f|
        f.write(output)
      end
    end
  end
end

将其保存在_plugins/crlf.rb中,它将在 jekyll构建时自动运行.

Save this in _plugins/crlf.rb and it will automatically run at jekyll build time.

配置代码编辑器以使用LF.如果不能,请更改编辑器.

Configure your code editor to use LF. If you can't, change editor.

这篇关于Jekyll LF/CRLF问题与git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆