Move docs_aliases to class App

pull/2344/head
Simon Legner 2 months ago
parent ed116eb795
commit 050022bfb7

@ -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,

@ -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));

@ -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'

@ -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

Loading…
Cancel
Save