[devdocsgjs/main: 1399/1867] Restore old URLs to TypeScript documentation
- From: Andy Holmes <andyholmes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devdocsgjs/main: 1399/1867] Restore old URLs to TypeScript documentation
- Date: Fri, 19 Nov 2021 23:47:58 +0000 (UTC)
commit 25a697ee5d34488411b77e88474db0ef8c23ab87
Author: Phil Scherer <pnscher evoforge org>
Date: Sat Dec 19 01:48:04 2020 -0500
Restore old URLs to TypeScript documentation
lib/docs/filters/typescript/clean_html.rb | 35 ++++++++++++++++---------------
lib/docs/filters/typescript/entries.rb | 24 ++++++++-------------
lib/docs/scrapers/typescript.rb | 29 ++++++++++++-------------
3 files changed, 40 insertions(+), 48 deletions(-)
---
diff --git a/lib/docs/filters/typescript/clean_html.rb b/lib/docs/filters/typescript/clean_html.rb
index b0a62a51..4b9d72fe 100644
--- a/lib/docs/filters/typescript/clean_html.rb
+++ b/lib/docs/filters/typescript/clean_html.rb
@@ -2,15 +2,14 @@ module Docs
class Typescript
class CleanHtmlFilter < Filter
- def call
- if slug.include?('index')
- root
- elsif slug == ('tsconfig/')
- tsconfig
- else
- other
- end
+ LANGUAGE_REPLACE = {
+ 'cmd' => 'shell',
+ 'sh' => 'shell',
+ 'tsx' => 'typescript+html'
+ }
+ def call
+ root_page? ? root : other
doc
end
@@ -24,23 +23,25 @@ module Docs
end
def other
- @doc = at_css('article > .whitespace > .markdown')
+ if base_url.path == '/docs/handbook/'
+ @doc = at_css('article > .whitespace > .markdown')
+ else # tsconfig page
+ @doc = at_css('.markdown > div')
- css('.anchor').remove
+ at_css('h2').remove
+ end
+
+ css('.anchor', 'a:contains("Try")', 'h2 a', 'h3 a', 'svg', '#full-option-list').remove
- css('a:contains("Try")').remove
css('pre').each do |node|
+ language = node.at_css('.language-id') ? node.at_css('.language-id').content : 'typescript'
+ node.css('.language-id').remove
node.content = node.content
- node['data-language'] = 'typescript'
+ node['data-language'] = LANGUAGE_REPLACE[language] || language
node.remove_attribute('class')
end
end
- def tsconfig
- css('h2 a', 'h3 a').remove
- css('svg').remove
- end
-
end
end
end
diff --git a/lib/docs/filters/typescript/entries.rb b/lib/docs/filters/typescript/entries.rb
index 98d42a78..842afbea 100644
--- a/lib/docs/filters/typescript/entries.rb
+++ b/lib/docs/filters/typescript/entries.rb
@@ -11,25 +11,19 @@ module Docs
end
def additional_entries
- entries = []
-
- css('h2').each do |node|
-
- if slug == 'tsconfig/'
- node.css('a').remove
- end
+ base_url.path == '/' ? tsconfig_entries : handbook_entries
+ end
- entries << [node.content, node['id'], name]
+ def tsconfig_entries
+ css('h3 > code').each_with_object [] do |node, entries|
+ entries << [node.content, node.parent['id']]
end
+ end
- if slug == 'tsconfig/'
- css('h3').each do |node|
- node.css('a').remove
- entries << [node.content, node['id'], name]
- end
+ def handbook_entries
+ css('h2').each_with_object [] do |node, entries|
+ entries << [node.content, node['id']]
end
-
- entries
end
end
diff --git a/lib/docs/scrapers/typescript.rb b/lib/docs/scrapers/typescript.rb
index 9da3c021..df5dc22e 100644
--- a/lib/docs/scrapers/typescript.rb
+++ b/lib/docs/scrapers/typescript.rb
@@ -1,14 +1,20 @@
module Docs
class Typescript < UrlScraper
+ include MultipleBaseUrls
+
self.name = 'TypeScript'
self.type = 'simple'
self.release = '4.1.3'
- self.base_url = 'https://www.typescriptlang.org/'
- self.root_path = 'docs/handbook/index.html'
- self.initial_paths = [
- 'tsconfig/'
+ self.base_urls = [
+ 'https://www.typescriptlang.org/docs/handbook/',
+ 'https://www.typescriptlang.org/'
]
+ def initial_urls
+ [ 'https://www.typescriptlang.org/docs/handbook/',
+ 'https://www.typescriptlang.org/tsconfig' ]
+ end
+
self.links = {
home: 'https://www.typescriptlang.org',
code: 'https://github.com/Microsoft/TypeScript'
@@ -19,24 +25,15 @@ module Docs
options[:container] = 'main'
options[:skip] = [
- 'docs/handbook/react-&-webpack.html'
+ 'react-&-webpack.html'
]
options[:skip_patterns] = [
/2/,
- /release-notes/
+ /release-notes/,
+ /play\//
]
- options[:only_patterns] = [
- /docs\/handbook\//,
- /tsconfig\//
- ]
-
- options[:fix_urls] = -> (url) do
- url.gsub!(/docs\/handbook\/index.html/, "index.html")
- url
- end
-
options[:attribution] = <<-HTML
© 2012-2020 Microsoft<br>
Licensed under the Apache License, Version 2.0.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]