Skip to content

Commit 002eb72

Browse files
authored
Merge pull request #2344 from djpowers/include-search-aliases-docs-json
Add field to docs.json denoting available aliases
2 parents 22abb7d + 050022b commit 002eb72

File tree

6 files changed

+45
-42
lines changed

6 files changed

+45
-42
lines changed

assets/javascripts/app/config.js.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,23 @@
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
}
1617
}
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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,42 @@ class App < Sinatra::Application
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def as_json
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ManifestTest < Minitest::Spec
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

0 commit comments

Comments
 (0)