forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.js
More file actions
70 lines (59 loc) · 1.54 KB
/
Copy pathentry.js
File metadata and controls
70 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//= require app/searcher
app.models.Entry = class Entry extends app.Model {
static applyAliases(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 (aliases.hasOwnProperty(word)) {
words[i] = aliases[word];
return [string, words.join(".")];
}
}
}
return string;
}
// Attributes: name, type, path
constructor() {
super(...arguments);
this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name));
}
addAlias(name) {
const text = Entry.applyAliases(app.Searcher.normalizeString(name));
if (!Array.isArray(this.text)) {
this.text = [this.text];
}
this.text.push(Array.isArray(text) ? text[1] : text);
}
fullPath() {
return this.doc.fullPath(this.isIndex() ? "" : this.path);
}
dbPath() {
return this.path.replace(/#.*/, "");
}
filePath() {
return this.doc.fullPath(this._filePath());
}
fileUrl() {
return this.doc.fileUrl(this._filePath());
}
_filePath() {
let result = this.path.replace(/#.*/, "");
if (result.slice(-5) !== ".html") {
result += ".html";
}
return result;
}
isIndex() {
return this.path === "index";
}
getType() {
return this.doc.types.findBy("name", this.type);
}
loadFile(onSuccess, onError) {
return app.db.load(this, onSuccess, onError);
}
};