Install all Update all Uninstall all
@@ -13,31 +13,15 @@ app.templates.offlinePage = (docs) -> """
- Documentation
- Size
- Status
- Action
+ 文档
+ 大小
+ 状态
+ 操作
#{docs}
-
Note: your browser may delete DevDocs's offline data if your computer is running low on disk space and you haven't used the app in a while. Load this page before going offline to make sure the data is still there.
-
Questions & Answers
-
- How does this work?
- Each page is cached as a key-value pair in IndexedDB (downloaded from a single file).
- The app also uses AppCache and localStorage to cache the assets and index files.
- Can I close the tab/browser?
- #{canICloseTheTab()}
- What if I don't update a documentation?
- You'll see outdated content and some pages will be missing or broken, because the rest of the app (including data for the search and sidebar) uses a different caching mechanism that's updated automatically.
- I found a bug, where do I report it?
- In the issue tracker . Thanks!
- How do I uninstall/reset the app?
- Click here .
- Why aren't all documentations listed above?
- You have to enable them first.
-
+
"""
canICloseTheTab = ->
diff --git a/assets/javascripts/templates/pages/root_tmpl.coffee.erb b/assets/javascripts/templates/pages/root_tmpl.coffee.erb
index 7adce7fd2a..4f713c3490 100644
--- a/assets/javascripts/templates/pages/root_tmpl.coffee.erb
+++ b/assets/javascripts/templates/pages/root_tmpl.coffee.erb
@@ -1,25 +1,10 @@
-app.templates.splash = """
DevDocs
"""
+app.templates.splash = """
DocHub
"""
<% if App.development? %>
app.templates.intro = """
-
Stop showing this message
-
Hi there!
-
Thanks for downloading DevDocs. Here are a few things you should know:
-
- Your local version of DevDocs won't self-update. Unless you're modifying the code,
- I recommend using the hosted version at devdocs.io .
- Run thor docs:list to see all available documentations.
- Run thor docs:download <name> to download documentations.
- Run thor docs:download --installed to update all downloaded documentations.
- To be notified about new versions, don't forget to watch the repository on GitHub.
- The issue tracker is the preferred channel for bug reports and
- feature requests. For everything else, use Gitter .
- Contributions are welcome. See the guidelines .
- DevDocs is licensed under the terms of the Mozilla Public License v2.0. For more information,
- see the COPYRIGHT and
- LICENSE files.
-
+
DocHub
+
API Docs Powered by devdocs
Happy coding!
"""
diff --git a/assets/javascripts/templates/sidebar_tmpl.coffee b/assets/javascripts/templates/sidebar_tmpl.coffee
index 46797e5658..e4112f0200 100644
--- a/assets/javascripts/templates/sidebar_tmpl.coffee
+++ b/assets/javascripts/templates/sidebar_tmpl.coffee
@@ -60,9 +60,7 @@ templates.sidebarDisabledList = (html) ->
templates.sidebarDisabledVersionedDoc = (doc, versions) ->
"""
#{arrow}#{doc.name} #{versions}
"""
-templates.docPickerHeader = """
Documentation Enable
"""
+templates.docPickerHeader = """
文档 使用
"""
templates.docPickerNote = """
-
Tip: for faster and better search results, select only the docs you need.
-
Vote for new documentation
- """
+ """
diff --git a/lib/app.rb b/lib/app.rb
index 32cac31ba5..a12d8207a8 100644
--- a/lib/app.rb
+++ b/lib/app.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
# frozen_string_literal: true
require 'bundler/setup'
@@ -15,7 +16,7 @@ class App < Sinatra::Application
use Rack::SslEnforcer, only_environments: ['production', 'test'], hsts: true, force_secure_cookies: false
set :sentry_dsn, ENV['SENTRY_DSN']
- set :protection, except: [:frame_options, :xss_header]
+ set :protection, except: [:frame_options, :xss_header, :json_csrf]
set :root, Pathname.new(File.expand_path('../..', __FILE__))
set :sprockets, Sprockets::Environment.new(root)
@@ -149,6 +150,7 @@ def unsupported_browser?
end
def docs
+ puts @docs
@docs ||= begin
cookie = memoized_cookies['docs']
@@ -169,6 +171,29 @@ def find_doc(slug)
end
end
+
+ def doc_index_entries(slug, name)
+ # file = File.join(settings.root, 'public', settings.docs_prefix, slug, 'index.json')
+ # file = File.read(file)
+
+ # puts JSON.parse(file)['entries']
+ entries = @doc_indexes[slug]['entries'].select { |entry|
+ entry['type'] == name
+ }
+ puts entries
+ entries
+ end
+
+ def doc_index_types(slug)
+ @doc_indexes ||= {}
+ @doc_indexes[slug] ||= begin
+ file = File.join(settings.root, 'public', settings.docs_prefix, slug, 'index.json')
+ file = File.read(file)
+ JSON.parse(file)
+ end
+ @doc_indexes[slug]['types']
+ end
+
def user_has_docs?(slug)
docs.include?(slug) || begin
slug = "#{slug}~"
@@ -188,6 +213,14 @@ def doc_index_page?
@doc && (request.path == "/#{@doc['slug']}/" || request.path == "/#{@doc['slug_without_version']}/")
end
+ def current_doc
+ puts @path
+ if @doc && @path != '/'
+ file = File.join(settings.root, 'public', settings.docs_prefix, @doc['slug'] + @path + ".html")
+ return File.read(file).force_encoding('utf-8')
+ end
+ end
+
def query_string_for_redirection
request.query_string.empty? ? nil : "?#{request.query_string}"
end
@@ -227,6 +260,7 @@ def redirect_via_js(path) # courtesy of HTML5 App Cache
def supports_js_redirection?
browser.modern? && !memoized_cookies.empty?
+ false
end
end
@@ -353,6 +387,7 @@ def supports_js_redirection?
}
get %r{/([\w~\.%]+)(\-[\w\-]+)?(/.*)?} do |doc, type, rest|
+ puts doc, type, rest
doc.sub! '%7E', '~'
if DOC_REDIRECTS.key?(doc)
@@ -390,6 +425,8 @@ def supports_js_redirection?
end
return 404 unless @doc = find_doc(doc)
+ @path = rest.split('#')[0] if rest
+ puts @doc
if rest.nil?
redirect "/#{doc}#{type}/#{query_string_for_redirection}"
diff --git a/lib/docs.rb b/lib/docs.rb
index 3f07374df4..d9d71988ea 100644
--- a/lib/docs.rb
+++ b/lib/docs.rb
@@ -31,6 +31,13 @@ module Docs
class DocNotFound < NameError; end
class SetupError < StandardError; end
+ trap 'TTIN' do
+ Thread.list.each do |thread|
+ puts "Thread TID-#{thread.object_id.to_s(36)}"
+ puts thread.backtrace.join("n")
+ end
+ end
+
def self.all
Dir["#{root_path}/docs/scrapers/**/*.rb"].
map { |file| File.basename(file, '.rb') }.
diff --git a/lib/docs/core/entry_index.rb b/lib/docs/core/entry_index.rb
index c909c6b66b..4b05c4beb7 100644
--- a/lib/docs/core/entry_index.rb
+++ b/lib/docs/core/entry_index.rb
@@ -50,6 +50,7 @@ def entries_as_json
end
def types_as_json
+ puts @types.values
@types.values.sort! { |a, b| sort_fn(a.name, b.name) }.map(&:as_json)
end
diff --git a/lib/docs/core/models/type.rb b/lib/docs/core/models/type.rb
index 41d115ecfe..87f77c64fe 100644
--- a/lib/docs/core/models/type.rb
+++ b/lib/docs/core/models/type.rb
@@ -8,7 +8,8 @@ def initialize(*args)
end
def slug
- name.parameterize
+ #name.parameterize
+ name
end
def as_json
diff --git a/lib/docs/core/scrapers/url_scraper.rb b/lib/docs/core/scrapers/url_scraper.rb
index 1daa1c0526..1ac5e33ad1 100644
--- a/lib/docs/core/scrapers/url_scraper.rb
+++ b/lib/docs/core/scrapers/url_scraper.rb
@@ -41,6 +41,7 @@ def request_all(urls, &block)
def request_options
options = { params: self.class.params, headers: self.class.headers }
options[:accept_encoding] = 'gzip' if self.class.force_gzip
+ options[:ssl_verifypeer ] = false
options
end
diff --git a/lib/docs/filters/core/normalize_urls.rb b/lib/docs/filters/core/normalize_urls.rb
index cd1888a84c..711e1359fc 100644
--- a/lib/docs/filters/core/normalize_urls.rb
+++ b/lib/docs/filters/core/normalize_urls.rb
@@ -40,6 +40,7 @@ def to_absolute_url(str)
end
def fix_url(url)
+ #puts url
if context[:redirections]
url = URL.parse(url)
path = url.path.downcase
@@ -54,8 +55,11 @@ def fix_url(url)
url = URL.parse(url)
path = subpath_to(url)
+ #puts path
+
if context[:replace_paths].key?(path)
url.path = url.path.sub %r[#{path}\z], context[:replace_paths][path]
+ #puts url
return url
end
end
diff --git a/lib/docs/scrapers/http.rb b/lib/docs/scrapers/http.rb
index 60f15f7592..1de13850d6 100644
--- a/lib/docs/scrapers/http.rb
+++ b/lib/docs/scrapers/http.rb
@@ -3,7 +3,7 @@ class Http < Mdn
include MultipleBaseUrls
self.name = 'HTTP'
- self.base_urls = ['https://developer.mozilla.org/en-US/docs/Web/HTTP', 'https://tools.ietf.org/html/']
+ self.base_urls = ['https://developer.mozilla.org/zh-CN/docs/Web/HTTP', 'https://tools.ietf.org/html/']
html_filters.push 'http/clean_html', 'http/entries', 'title'
@@ -26,7 +26,7 @@ class Http < Mdn
end
def initial_urls
- %w(https://developer.mozilla.org/en-US/docs/Web/HTTP
+ %w(https://developer.mozilla.org/zh-CN/docs/Web/HTTP
https://tools.ietf.org/html/rfc2616
https://tools.ietf.org/html/rfc4918
https://tools.ietf.org/html/rfc7230
diff --git a/lib/docs/scrapers/mdn/css.rb b/lib/docs/scrapers/mdn/css.rb
index 4c44f1f132..87d546ebdc 100644
--- a/lib/docs/scrapers/mdn/css.rb
+++ b/lib/docs/scrapers/mdn/css.rb
@@ -1,7 +1,7 @@
module Docs
class Css < Mdn
self.name = 'CSS'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/CSS'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/CSS'
self.root_path = '/Reference'
html_filters.push 'css/clean_html', 'css/entries', 'title'
@@ -26,7 +26,7 @@ class Css < Mdn
}
options[:fix_urls] = ->(url) do
- url.sub! %r{https://developer\.mozilla\.org/en\-US/docs/CSS/([\w\-@:])}, "#{Css.base_url}/\\1"
+ url.sub! %r{https://developer\.mozilla\.org/zh\-CN/docs/CSS/([\w\-@:])}, "#{Css.base_url}/\\1"
url.sub! '%3A', ':'
url.sub! '%40', '@'
url
diff --git a/lib/docs/scrapers/mdn/dom.rb b/lib/docs/scrapers/mdn/dom.rb
index bbf95b2010..e2e60fcf24 100644
--- a/lib/docs/scrapers/mdn/dom.rb
+++ b/lib/docs/scrapers/mdn/dom.rb
@@ -4,7 +4,7 @@ class Dom < Mdn
prepend FixRedirectionsBehavior
self.name = 'DOM'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/API'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/API/Document_Object_Model'
html_filters.push 'dom/clean_html', 'dom/entries', 'title'
@@ -69,8 +69,8 @@ class Dom < Mdn
options[:fix_urls] = ->(url) do
return if url.include?('_') || url.include?('?')
- url.sub! 'https://developer.mozilla.org/en-US/docs/DOM/', "#{Dom.base_url}/"
- url.sub! 'https://developer.mozilla.org/en/DOM/', "#{Dom.base_url}/"
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/DOM/', "#{Dom.base_url}/"
+ url.sub! 'https://developer.mozilla.org/zh/DOM/', "#{Dom.base_url}/"
url.sub! 'https://developer.mozilla.org/Web/API/', "#{Dom.base_url}/"
url.sub! "#{Dom.base_url}/Console", "#{Dom.base_url}/console"
url.sub! "#{Dom.base_url}/Document\/", "#{Dom.base_url}/document\/"
diff --git a/lib/docs/scrapers/mdn/dom_events.rb b/lib/docs/scrapers/mdn/dom_events.rb
index fcbdc08fc1..cbec014ac6 100644
--- a/lib/docs/scrapers/mdn/dom_events.rb
+++ b/lib/docs/scrapers/mdn/dom_events.rb
@@ -4,7 +4,7 @@ class DomEvents < Mdn
self.name = 'DOM Events'
self.slug = 'dom_events'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/Events'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/Events'
html_filters.insert_after 'clean_html', 'dom_events/clean_html'
html_filters.push 'dom_events/entries', 'title'
@@ -15,9 +15,9 @@ class DomEvents < Mdn
options[:skip_patterns] = [/\A\/moz/i]
options[:fix_urls] = ->(url) do
- url.sub! 'https://developer.mozilla.org/en-US/Mozilla_event_reference', DomEvents.base_url
- url.sub! 'https://developer.mozilla.org/en-US/docs/Mozilla_event_reference', DomEvents.base_url
- url.sub! 'https://developer.mozilla.org/en-US/docs/Web/Reference/Events', DomEvents.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/Mozilla_event_reference', DomEvents.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/Mozilla_event_reference', DomEvents.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/Web/Reference/Events', DomEvents.base_url
url
end
end
diff --git a/lib/docs/scrapers/mdn/html.rb b/lib/docs/scrapers/mdn/html.rb
index 4b28cefd0a..6502e2a3cd 100644
--- a/lib/docs/scrapers/mdn/html.rb
+++ b/lib/docs/scrapers/mdn/html.rb
@@ -3,7 +3,7 @@ class Html < Mdn
prepend FixInternalUrlsBehavior
self.name = 'HTML'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/HTML'
html_filters.push 'html/clean_html', 'html/entries', 'title'
@@ -35,7 +35,7 @@ class Html < Mdn
'/Global_attributes/data-%2A' => '/Global_attributes/data-*' }
options[:fix_urls] = ->(url) do
- url.sub! 'https://developer.mozilla.org/en-US/docs/HTML/', "#{Html.base_url}/" unless url.include?('Content_categories')
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/HTML/', "#{Html.base_url}/" unless url.include?('Content_categories')
url
end
end
diff --git a/lib/docs/scrapers/mdn/javascript.rb b/lib/docs/scrapers/mdn/javascript.rb
index 935df61c45..221a4d3dd6 100644
--- a/lib/docs/scrapers/mdn/javascript.rb
+++ b/lib/docs/scrapers/mdn/javascript.rb
@@ -4,7 +4,7 @@ class Javascript < Mdn
prepend FixRedirectionsBehavior
self.name = 'JavaScript'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference'
html_filters.push 'javascript/clean_html', 'javascript/entries', 'title'
@@ -35,7 +35,7 @@ class Javascript < Mdn
}
options[:fix_urls] = ->(url) do
- url.sub! 'https://developer.mozilla.org/en-US/docs/JavaScript/Reference', Javascript.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/JavaScript/Reference', Javascript.base_url
url.sub! 'https://developer.mozilla.org/en/JavaScript/Reference', Javascript.base_url
url.sub! 'https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference', Javascript.base_url
url.sub! 'https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference', Javascript.base_url
diff --git a/lib/docs/scrapers/mdn/svg.rb b/lib/docs/scrapers/mdn/svg.rb
index db9de7a181..090daedae6 100644
--- a/lib/docs/scrapers/mdn/svg.rb
+++ b/lib/docs/scrapers/mdn/svg.rb
@@ -4,7 +4,7 @@ class Svg < Mdn
prepend FixRedirectionsBehavior
self.name = 'SVG'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/SVG'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web/SVG'
html_filters.push 'svg/clean_html', 'svg/entries', 'title'
@@ -23,8 +23,8 @@ class Svg < Mdn
options[:skip] = %w(/Compatibility_sources /FAQ)
options[:fix_urls] = ->(url) do
- url.sub! 'https://developer.mozilla.org/en-US/Web/SVG', Svg.base_url
- url.sub! 'https://developer.mozilla.org/en-US/docs/SVG', Svg.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/Web/SVG', Svg.base_url
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/SVG', Svg.base_url
url.sub! 'https://developer.mozilla.org/en/SVG', Svg.base_url
url
end
diff --git a/lib/docs/scrapers/mdn/xslt_xpath.rb b/lib/docs/scrapers/mdn/xslt_xpath.rb
index 5d812dd40d..11ba01a538 100644
--- a/lib/docs/scrapers/mdn/xslt_xpath.rb
+++ b/lib/docs/scrapers/mdn/xslt_xpath.rb
@@ -2,7 +2,7 @@ module Docs
class XsltXpath < Mdn
self.name = 'XSLT & XPath'
self.slug = 'xslt_xpath'
- self.base_url = 'https://developer.mozilla.org/en-US/docs/Web'
+ self.base_url = 'https://developer.mozilla.org/zh-CN/docs/Web'
self.root_path = '/XSLT'
self.initial_paths = %w(/XPath)
@@ -15,8 +15,8 @@ class XsltXpath < Mdn
options[:fix_urls] = ->(url) do
url.sub! 'https://developer.mozilla.org/en/XPath', "#{XsltXpath.base_url}/XPath"
url.sub! 'https://developer.mozilla.org/en/XSLT', "#{XsltXpath.base_url}/XSLT"
- url.sub! 'https://developer.mozilla.org/en-US/docs/XPath', "#{XsltXpath.base_url}/XPath"
- url.sub! 'https://developer.mozilla.org/en-US/docs/XSLT', "#{XsltXpath.base_url}/XSLT"
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/XPath', "#{XsltXpath.base_url}/XPath"
+ url.sub! 'https://developer.mozilla.org/zh-CN/docs/XSLT', "#{XsltXpath.base_url}/XSLT"
url
end
end
diff --git a/lib/docs/scrapers/node.rb b/lib/docs/scrapers/node.rb
index 66c6a45684..f8f68b03ac 100644
--- a/lib/docs/scrapers/node.rb
+++ b/lib/docs/scrapers/node.rb
@@ -34,7 +34,7 @@ class Node < UrlScraper
version '8 LTS' do
self.release = '8.12.0'
- self.base_url = 'https://nodejs.org/dist/latest-v8.x/docs/api/'
+ self.base_url = 'https://www.nodeapp.cn/'
end
version '6 LTS' do
diff --git a/lib/docs/scrapers/vue.rb b/lib/docs/scrapers/vue.rb
index f92991f294..fb752e0892 100644
--- a/lib/docs/scrapers/vue.rb
+++ b/lib/docs/scrapers/vue.rb
@@ -21,7 +21,7 @@ class Vue < UrlScraper
version '2' do
self.release = '2.5.16'
- self.base_url = 'https://vuejs.org/v2/'
+ self.base_url = 'https://cn.vuejs.org/v2/'
self.root_path = 'guide/index.html'
self.initial_paths = %w(api/)
end
diff --git a/lib/docs/scrapers/webpack.rb b/lib/docs/scrapers/webpack.rb
index 255c1bb4b2..59f0682c9c 100644
--- a/lib/docs/scrapers/webpack.rb
+++ b/lib/docs/scrapers/webpack.rb
@@ -5,7 +5,7 @@ class Webpack < UrlScraper
version do
self.release = '4.16.5'
- self.base_url = 'https://webpack.js.org/'
+ self.base_url = 'https://www.webpackjs.com/'
self.root_path = 'guides/'
self.initial_paths = %w(
concepts/
@@ -16,7 +16,7 @@ class Webpack < UrlScraper
plugins/
)
self.links = {
- home: 'https://webpack.js.org/',
+ home: 'https://www.webpackjs.com/',
code: 'https://github.com/webpack/webpack'
}
diff --git a/public/docs/docs.json b/public/docs/docs.json
index 0637a088a0..c117bf51f0 100644
--- a/public/docs/docs.json
+++ b/public/docs/docs.json
@@ -1 +1,57 @@
-[]
\ No newline at end of file
+[
+ {
+ "name": "CSS",
+ "slug": "css",
+ "type": "mdn",
+ "mtime": 1546485844,
+ "db_size": 10771175
+ },
+ {
+ "name": "DOM",
+ "slug": "dom",
+ "type": "mdn",
+ "mtime": 1543157862,
+ "db_size": 33998524
+ },
+ {
+ "name": "DOM Events",
+ "slug": "dom_events",
+ "type": "mdn",
+ "mtime": 1543099589,
+ "db_size": 1752500
+ },
+ {
+ "name": "HTML",
+ "slug": "html",
+ "type": "mdn",
+ "mtime": 1546485271,
+ "db_size": 3353838
+ },
+ {
+ "name": "HTTP",
+ "slug": "http",
+ "type": "mdn",
+ "mtime": 1543099392,
+ "db_size": 4731727
+ },
+ {
+ "name": "JavaScript",
+ "slug": "javascript",
+ "type": "mdn",
+ "mtime": 1543098529,
+ "db_size": 6462141
+ },
+ {
+ "name": "Vue.js",
+ "slug": "vue~2",
+ "type": "vue",
+ "links": {
+ "home": "https://vuejs.org/",
+ "code": "https://github.com/vuejs/vue"
+ },
+ "version": "2",
+ "release": "2.5.16",
+ "mtime": 1546490036,
+ "db_size": 831805
+ }
+]
\ No newline at end of file
diff --git a/views/app.erb b/views/app.erb
index 7cffabd092..5001536c4c 100644
--- a/views/app.erb
+++ b/views/app.erb
@@ -19,25 +19,35 @@
-
+
+ <%= current_doc() %>
+