go.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. module Docs
  2. class Go < UrlScraper
  3. self.type = 'go'
  4. self.release = '1.17.5'
  5. self.base_url = 'https://golang.org/pkg/'
  6. self.links = {
  7. home: 'https://golang.org/',
  8. code: 'https://go.googlesource.com/go'
  9. }
  10. # Run godoc locally, since https://golang.org/pkg/ redirects to https://pkg.go.dev/std with rate limiting / scraping protection.
  11. # curl -LO https://golang.org/dl/go1.17.5.windows-amd64.zip
  12. # go install golang.org/x/tools/cmd/godoc@latest
  13. # go/bin/godoc -zip=go1.17.5.windows-amd64.zip -goroot=/go
  14. self.base_url = 'http://localhost:6060/pkg/'
  15. html_filters.push 'clean_local_urls'
  16. html_filters.push 'go/clean_html', 'go/entries'
  17. text_filters.replace 'attribution', 'go/attribution'
  18. options[:trailing_slash] = true
  19. options[:container] = '#page .container'
  20. options[:skip] = %w(runtime/msan/)
  21. options[:skip_patterns] = [/\/\//]
  22. options[:fix_urls] = ->(url) do
  23. url.sub '/pkg//', '/pkg/'
  24. end
  25. options[:attribution] = <<-HTML
  26. &copy; Google, Inc.<br>
  27. Licensed under the Creative Commons Attribution License 3.0.
  28. HTML
  29. def get_latest_version(opts)
  30. doc = fetch_doc('https://go.dev/dl/', opts)
  31. doc.at_css('.download[href]')['href'][/go1[0-9.]+[0-9]/][2..]
  32. end
  33. private
  34. def parse(response) # Hook here because Nokogori removes whitespace from textareas
  35. response.body.gsub! %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
  36. super
  37. end
  38. end
  39. end