diff --git a/assets/javascripts/app/config.js.erb b/assets/javascripts/app/config.js.erb index 56ce2652..04bc8cba 100644 --- a/assets/javascripts/app/config.js.erb +++ b/assets/javascripts/app/config.js.erb @@ -1,6 +1,7 @@ app.config = { db_filename: 'db.json', default_docs: <%= App.default_docs.to_json %>, + docs_aliases: <%= App.docs_aliases.to_json %>, docs_origin: '<%= App.docs_origin %>', env: '<%= App.environment %>', history_cache_size: 10, diff --git a/assets/javascripts/models/entry.js b/assets/javascripts/models/entry.js index 79c81342..98822bc9 100644 --- a/assets/javascripts/models/entry.js +++ b/assets/javascripts/models/entry.js @@ -2,14 +2,15 @@ app.models.Entry = class Entry extends app.Model { static applyAliases(string) { - if (Entry.ALIASES.hasOwnProperty(string)) { - return [string, Entry.ALIASES[string]]; + const aliases = app.config.docs_aliases; + if (aliases.hasOwnProperty(string)) { + return [string, aliases[string]]; } else { const words = string.split("."); for (let i = 0; i < words.length; i++) { var word = words[i]; - if (Entry.ALIASES.hasOwnProperty(word)) { - words[i] = Entry.ALIASES[word]; + if (aliases.hasOwnProperty(word)) { + words[i] = aliases[word]; return [string, words.join(".")]; } } @@ -17,43 +18,7 @@ app.models.Entry = class Entry extends app.Model { return string; } - static ALIASES = { - angular: "ng", - "angular.js": "ng", - "backbone.js": "bb", - "c++": "cpp", - coffeescript: "cs", - crystal: "cr", - elixir: "ex", - javascript: "js", - julia: "jl", - jquery: "$", - "knockout.js": "ko", - kubernetes: "k8s", - less: "ls", - lodash: "_", - löve: "love", - marionette: "mn", - markdown: "md", - matplotlib: "mpl", - modernizr: "mdr", - "moment.js": "mt", - openjdk: "java", - nginx: "ngx", - numpy: "np", - pandas: "pd", - postgresql: "pg", - python: "py", - "ruby.on.rails": "ror", - ruby: "rb", - rust: "rs", - sass: "scss", - tensorflow: "tf", - typescript: "ts", - "underscore.js": "_", - }; // Attributes: name, type, path - constructor() { super(...arguments); this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name)); diff --git a/lib/app.rb b/lib/app.rb index e23b241c..939eab47 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -33,6 +33,42 @@ class App < Sinatra::Application set :default_docs, %w(css dom html http javascript) set :news_path, File.join(root, assets_prefix, 'javascripts', 'news.json') + set :docs_aliases, { + 'angular' => 'ng', + 'angular.js' => 'ng', + 'backbone.js' => 'bb', + 'c++' => 'cpp', + 'coffeescript' => 'cs', + 'crystal' => 'cr', + 'elixir' => 'ex', + 'javascript' => 'js', + 'julia' => 'jl', + 'jquery' => '$', + 'knockout.js' => 'ko', + 'kubernetes' => 'k8s', + 'less' => 'ls', + 'lodash' => '_', + 'löve' => 'love', + 'marionette' => 'mn', + 'markdown' => 'md', + 'matplotlib' => 'mpl', + 'modernizr' => 'mdr', + 'moment.js' => 'mt', + 'openjdk' => 'java', + 'nginx' => 'ngx', + 'numpy' => 'np', + 'pandas' => 'pd', + 'postgresql' => 'pg', + 'python' => 'py', + 'ruby.on.rails' => 'ror', + 'ruby' => 'rb', + 'rust' => 'rs', + 'sass' => 'scss', + 'tensorflow' => 'tf', + 'typescript' => 'ts', + 'underscore.js' => '_', + } + set :csp, false require 'docs' diff --git a/lib/docs/core/manifest.rb b/lib/docs/core/manifest.rb index 2a1f084c..134bb9e3 100644 --- a/lib/docs/core/manifest.rb +++ b/lib/docs/core/manifest.rb @@ -20,15 +20,7 @@ module Docs if doc.options[:attribution].is_a?(String) json[:attribution] = doc.options[:attribution].strip end - - # parse doc aliases from JS file as Ruby hash - entry_file = File.open("assets/javascripts/models/entry.js") - data = entry_file.read - aliases = eval data.split("ALIASES = ").last.split(";").first - - # set alias value - json["alias"] = aliases[json["slug"].try(:to_sym)] - + json[:alias] = App.docs_aliases[json["slug"].try(:to_sym)] result << json end end