1
0

go.rb 1.8 KB

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