1
0

go.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module Docs
  2. class Go < UrlScraper
  3. self.type = 'go'
  4. self.release = '1.21.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. # podman run --net host --rm -it docker.io/golang:1.21.5
  12. #podman# go install golang.org/x/tools/cmd/godoc@latest
  13. #podman# rm -r /usr/local/go/test/
  14. #podman# godoc -http 0.0.0.0:6060 -v
  15. self.base_url = 'http://localhost:6060/pkg/'
  16. html_filters.push 'clean_local_urls'
  17. html_filters.push 'go/clean_html', 'go/entries'
  18. text_filters.replace 'attribution', 'go/attribution'
  19. options[:trailing_slash] = true
  20. options[:container] = '#page .container'
  21. options[:skip] = %w(runtime/msan/)
  22. options[:skip_patterns] = [/\/\//]
  23. options[:fix_urls] = ->(url) do
  24. url.sub '/pkg//', '/pkg/'
  25. end
  26. options[:attribution] = <<-HTML
  27. &copy; Google, Inc.<br>
  28. Licensed under the Creative Commons Attribution License 3.0.
  29. HTML
  30. def get_latest_version(opts)
  31. doc = fetch_doc('https://go.dev/dl/', opts)
  32. doc.at_css('.download[href]')['href'][/go1[0-9.]+[0-9]/][2..]
  33. end
  34. private
  35. def parse(response) # Hook here because Nokogori removes whitespace from textareas
  36. response.body.gsub! %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
  37. super
  38. end
  39. end
  40. end