Skip to content

全てのページのサンプルコードの言語指定を拡張記法に置き換える #480

Closed

Description

@saki7

#473 が決まったのでまずは現在の記事を全て機械的に置き換える

Activity

  1. saki7 commented on Nov 10, 2017

    @saki7
    ContributorAuthor

    これができたら cpprefjp/site_generator#48

  2. faithandbrave commented on Nov 27, 2017

    @faithandbrave
    Member

    やります。

  3. faithandbrave commented on Nov 27, 2017

    @faithandbrave
    Member

    スクリプトを書いて置き換えました。

    def enumerate_recursive_dir(path)
      Dir::foreach(path) {|f|
        next if f == '.' or  f == '..'
        if path =~ /\/$/
          f = path + f
        else
          f = path + '/' + f
        end
        if FileTest::directory?(f)
          enumerate_recursive_dir(f) {|nested_file|
            yield nested_file
          }
        else
          yield f
        end
      }
    end
    
    def find_example_codes(data)
      codes = []
      now_pos = 0
      while true do
        start_pos = data.index("```cpp", now_pos)
        if start_pos == nil then
          break
        end
    
        end_pos = data.index("```", start_pos + 3)
        codes << data[start_pos, end_pos - start_pos]
        now_pos = end_pos
      end
      return codes
    end
    
    enumerate_recursive_dir('site') {|md_path|
      if File.extname(md_path) != ".md"
        next
      end
    
      data = File.open(md_path).read
      new_data = data.clone
      find_example_codes(data).each {|code|
        if code.index("#include") && code.index("int main(") then
          new_code = code.gsub("```cpp", "```cpp example")
          new_data.gsub!(code, new_code)
        end
      }
    
      if data != new_data then
        File.write(md_path, new_data)
      end
    }
  4. saki7 commented on Nov 27, 2017

    @saki7
    ContributorAuthor

    @faithandbrave 対応ありがとうございます。今後このようにスクリプトを利用した大規模な変更を行う場合は、ブランチを切ってself-PRしていただけると助かります。確信は無いのですが恐らくこの変更が原因で全ページのコード実行機能が動かなくなってしまっているので、一時的にrevertしたい時にPRだとやりやすいです。

    これは想像ですがバックエンドでは問題なくてkunaiの問題だと思うので、調査しますが少し時間はかかります。

  5. faithandbrave commented on Nov 27, 2017

    @faithandbrave
    Member

    あれー、すいません。exampleを付けるのは検証済みだと思っていたので、確認なしでpushしてしまいました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions