You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

normalize-translations.rb 1.4 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. puts "Normalizing toc..."
  2. # frontmatterSourceRegex = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
  3. # frontmatterTargetRegex = %r!\A(\* \* \*\s*\n.*?\n?)^((\* \* \*|\.\.\.)\s*$\n?)!m
  4. frontmatterSourceRegex = /^---.*?---/m
  5. frontmatterTargetRegex = /^\* \* \*.*?\* \* \*/m
  6. tocRegex = /\[\]\(#toc-(.*?)\)\{#toc-.*?\}/
  7. langsDir = File.join('.', 'lang')
  8. langs = Dir.entries(langsDir).reject {|lang| lang == 'en' || lang == "." || lang == ".."}
  9. # Build up a hashmap with all of the source front-matters
  10. # { relativePath => frontMatter }
  11. englishFiles = Dir.glob(File.join(langsDir, 'en', '**', '*.*'))
  12. english = {}
  13. englishFiles.each {|file|
  14. path = file.sub(File.join(langsDir, 'en'), '')
  15. contents = IO.read file
  16. contents = contents.unicode_normalize
  17. result = contents.match frontmatterSourceRegex
  18. english[path] = result
  19. }
  20. langs.each {|lang|
  21. files = Dir.glob(File.join(langsDir, lang, '**', '*.*'))
  22. files.each {|file|
  23. # puts "- Replacing #{file}"
  24. path = file.sub(File.join(langsDir, lang), '')
  25. contents = IO.read file
  26. frontmatter = english[path]
  27. result = contents
  28. result = result.unicode_normalize
  29. result = result.gsub /\r\n?/, "\n"
  30. result = result + "\n"
  31. result = result.gsub(tocRegex, '<a class="toc" id="toc-\1" href="#toc-\1"></a>')
  32. result = result.gsub(frontmatterTargetRegex) {|c| frontmatter } if frontmatter
  33. File.write(file, result)
  34. }
  35. }

js yarn包管理组件依赖分析

Contributors (1)