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

84 lines
2.2 KiB

  1. require "pathname"
  2. BUILD_DIR = Pathname("build")
  3. LOCALE_DIR = Pathname("trans")
  4. TRANS_DIR = Pathname("translate")
  5. PSEUDO_LANG = "ach"
  6. CROWDIN_SNIPPET = <<EOS
  7. <script type="text/javascript">
  8. var _jipt = [];
  9. _jipt.push(['project', 'joinplume']);
  10. _jipt.push(['escape', function() {
  11. window.location.href = 'https://joinplu.me';
  12. }]);
  13. </script>
  14. <script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
  15. EOS
  16. class Pathname
  17. alias to_str to_s
  18. end
  19. task :default => [:build_trans, :build_site]
  20. desc "Build site"
  21. task :build_site => [:build_base, "crowdin:download"] do
  22. Pathname.glob("#{LOCALE_DIR}/**/*.html").select(&:file?).each do |path|
  23. content = path.read
  24. content.sub! /<script type="text\/javascript" src="\/\/cdn.crowdin.com\/jipt\/jipt.js"><\/script>/, ""
  25. dest = Pathname(path.to_path.sub(LOCALE_DIR, BUILD_DIR))
  26. next if dest.file?
  27. $stderr.puts "copy #{path} -> #{dest}"
  28. dest.parent.mkpath
  29. dest.write content
  30. end
  31. end
  32. task :build_base do
  33. sh "middleman", "build"
  34. end
  35. desc "Build site for translate.joinplu.me"
  36. task :build_trans => "crowdin:download_pseudo" do
  37. sh "middleman", "build", "--build-dir", TRANS_DIR
  38. (LOCALE_DIR/PSEUDO_LANG).glob("**/*.html").each do |html|
  39. doc = html.read
  40. doc.sub! "<head>", "<head>" + CROWDIN_SNIPPET
  41. dest = Pathname(html.to_path.sub(LOCALE_DIR/PSEUDO_LANG, TRANS_DIR))
  42. dest.write doc
  43. end
  44. end
  45. task :build_trans_src do
  46. sh "middleman", "build", "--build-dir", LOCALE_DIR
  47. end
  48. desc "Deploy joinplue.me"
  49. task :deploy => :build_site do
  50. sh "netlify", "deploy", "--site", "12885026-8536-4072-b216-04d71e8f84be", "--dir", BUILD_DIR, "--prod"
  51. end
  52. desc "Deploy translate.joinplu.me"
  53. task :deploy_trans => :build_trans do
  54. sh "netlify", "deploy", "--site", "0812f781-8b3a-481d-b4fb-bc5cb5254f19", "--dir", TRANS_DIR, "--prod"
  55. end
  56. namespace :crowdin do
  57. desc "Download translations"
  58. task :download => :build_trans_src do
  59. sh "crowdin", "download"
  60. end
  61. desc "Upload translation sources"
  62. task :upload => :build_trans_src do
  63. sh "crowdin", "upload", "sources"
  64. end
  65. task :download_pseudo do
  66. sh "crowdin", "download", "--pseudo"
  67. end
  68. end