History

Merge pull request #2344 from djpowers/include-search-aliases-docs-json

Add field to docs.json denoting available aliases

Simon Legner committed 1 year ago

Commit 002eb722 parents 22abb7d 050022b6 files · +45 −42Browse files

Unified · Split

6 files
  1. assets/javascripts/app/config.js.erb +1 −0
  2. assets/javascripts/models/entry.js +5 −40
  3. lib/app.rb +36 −0
  4. lib/docs/core/manifest.rb +1 −0
  5. test/files/docs.json +1 −1
  6. test/lib/docs/core/manifest_test.rb +1 −1
assets/javascripts/app/config.js.erb+1−0
@@ -1,6 +1,7 @@
11 app.config = {
22 db_filename: 'db.json',
33 default_docs: <%= App.default_docs.to_json %>,
4+ docs_aliases: <%= App.docs_aliases.to_json %>,
45 docs_origin: '<%= App.docs_origin %>',
56 env: '<%= App.environment %>',
67 history_cache_size: 10,
assets/javascripts/models/entry.js+5−40
@@ -2,14 +2,15 @@ · 1 unmodified line
22
33 app.models.Entry = class Entry extends app.Model {
44 static applyAliases(string) {
5− if (Entry.ALIASES.hasOwnProperty(string)) {
6− return [string, Entry.ALIASES[string]];
5+ const aliases = app.config.docs_aliases;
6+ if (aliases.hasOwnProperty(string)) {
7+ return [string, aliases[string]];
78 } else {
89 const words = string.split(".");
910 for (let i = 0; i < words.length; i++) {
1011 var word = words[i];
11− if (Entry.ALIASES.hasOwnProperty(word)) {
12− words[i] = Entry.ALIASES[word];
12+ if (aliases.hasOwnProperty(word)) {
13+ words[i] = aliases[word];
1314 return [string, words.join(".")];
1415 }
1516 }
@@ -17,43 +18,7 @@ app.models.Entry = class Entry extends app.Model { · 1 unmodified line
1718 return string;
1819 }
1920
20− static ALIASES = {
21− angular: "ng",
22− "angular.js": "ng",
23− "backbone.js": "bb",
24− "c++": "cpp",
25− coffeescript: "cs",
26− crystal: "cr",
27− elixir: "ex",
28− javascript: "js",
29− julia: "jl",
30− jquery: "$",
31− "knockout.js": "ko",
32− kubernetes: "k8s",
33− less: "ls",
34− lodash: "_",
35− löve: "love",
36− marionette: "mn",
37− markdown: "md",
38− matplotlib: "mpl",
39− modernizr: "mdr",
40− "moment.js": "mt",
41− openjdk: "java",
42− nginx: "ngx",
43− numpy: "np",
44− pandas: "pd",
45− postgresql: "pg",
46− python: "py",
47− "ruby.on.rails": "ror",
48− ruby: "rb",
49− rust: "rs",
50− sass: "scss",
51− tensorflow: "tf",
52− typescript: "ts",
53− "underscore.js": "_",
54− };
5521 // Attributes: name, type, path
56−
5722 constructor() {
5823 super(...arguments);
5924 this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name));
lib/app.rb+36−0
@@ -33,6 +33,42 @@ class App < Sinatra::Application · 32 unmodified lines
3333 set :default_docs, %w(css dom html http javascript)
3434 set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json')
3535
36+ set :docs_aliases, {
37+ 'angular' => 'ng',
38+ 'angular.js' => 'ng',
39+ 'backbone.js' => 'bb',
40+ 'c++' => 'cpp',
41+ 'coffeescript' => 'cs',
42+ 'crystal' => 'cr',
43+ 'elixir' => 'ex',
44+ 'javascript' => 'js',
45+ 'julia' => 'jl',
46+ 'jquery' => '$',
47+ 'knockout.js' => 'ko',
48+ 'kubernetes' => 'k8s',
49+ 'less' => 'ls',
50+ 'lodash' => '_',
51+ 'löve' => 'love',
52+ 'marionette' => 'mn',
53+ 'markdown' => 'md',
54+ 'matplotlib' => 'mpl',
55+ 'modernizr' => 'mdr',
56+ 'moment.js' => 'mt',
57+ 'openjdk' => 'java',
58+ 'nginx' => 'ngx',
59+ 'numpy' => 'np',
60+ 'pandas' => 'pd',
61+ 'postgresql' => 'pg',
62+ 'python' => 'py',
63+ 'ruby.on.rails' => 'ror',
64+ 'ruby' => 'rb',
65+ 'rust' => 'rs',
66+ 'sass' => 'scss',
67+ 'tensorflow' => 'tf',
68+ 'typescript' => 'ts',
69+ 'underscore.js' => '_',
70+ }
71+
3672 set :csp, false
3773
3874 require 'docs'
lib/docs/core/manifest.rb+1−0
@@ -20,6 +20,7 @@ module Docs · 19 unmodified lines
2020 if doc.options[:attribution].is_a?(String)
2121 json[:attribution] = doc.options[:attribution].strip
2222 end
23+ json[:alias] = App.docs_aliases[json["slug"].try(:to_sym)]
2324 result << json
2425 end
2526 end
test/files/docs.json+1−1
@@ -1 +1 @@
1−[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477}]
1+[{"name":"CSS","slug":"css","type":"mdn","release":null,"mtime":1420139788,"db_size":3460507,"alias":null},{"name":"DOM","slug":"dom","type":"mdn","release":null,"mtime":1420139789,"db_size":11399128,"alias":null},{"name":"DOM Events","slug":"dom_events","type":"mdn","release":null,"mtime":1420139790,"db_size":889020,"alias":null},{"name":"HTML","slug":"html~5","type":"mdn","version":"5","mtime":1420139791,"db_size":1835647,"alias":null},{"name":"HTML","slug":"html~4","type":"mdn","version":"4","mtime":1420139790,"db_size":1835646,"alias":null},{"name":"HTTP","slug":"http","type":"rfc","release":null,"mtime":1420139790,"db_size":183083,"alias":null},{"name":"JavaScript","slug":"javascript","type":"mdn","release":null,"mtime":1420139791,"db_size":4125477,"alias":"js"}]
test/lib/docs/core/manifest_test.rb+1−1
@@ -64,7 +64,7 @@ class ManifestTest < Minitest::Spec · 63 unmodified lines
6464 it "includes the doc's meta representation" do
6565 json = manifest.as_json
6666 assert_equal 1, json.length
67− assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s
67+ assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\", \"alias\"=>nil}", json[0].to_s
6868 end
6969 end
7070