Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
saki7 opened this issue Nov 10, 2017 · 5 comments
Assignees

Comments

@saki7
Copy link
Contributor

saki7 commented Nov 10, 2017

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

@saki7
Copy link
Contributor Author

saki7 commented Nov 10, 2017

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

@faithandbrave
Copy link
Member

やります。

@faithandbrave faithandbrave self-assigned this Nov 27, 2017
@faithandbrave
Copy link
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
}

@saki7
Copy link
Contributor Author

saki7 commented Nov 27, 2017

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

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

@faithandbrave
Copy link
Member

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

saki7 added a commit to cpprefjp/kunai that referenced this issue Nov 27, 2017
e-kwsm added a commit that referenced this issue Dec 4, 2017
* コンパイルエラーになるのは意図したとおり
* #480, #487
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants