entry.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //= require app/searcher
  2. app.models.Entry = class Entry extends app.Model {
  3. static applyAliases(string) {
  4. const aliases = app.config.docs_aliases;
  5. if (aliases.hasOwnProperty(string)) {
  6. return [string, aliases[string]];
  7. } else {
  8. const words = string.split(".");
  9. for (let i = 0; i < words.length; i++) {
  10. var word = words[i];
  11. if (aliases.hasOwnProperty(word)) {
  12. words[i] = aliases[word];
  13. return [string, words.join(".")];
  14. }
  15. }
  16. }
  17. return string;
  18. }
  19. // Attributes: name, type, path
  20. constructor() {
  21. super(...arguments);
  22. this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name));
  23. }
  24. addAlias(name) {
  25. const text = Entry.applyAliases(app.Searcher.normalizeString(name));
  26. if (!Array.isArray(this.text)) {
  27. this.text = [this.text];
  28. }
  29. this.text.push(Array.isArray(text) ? text[1] : text);
  30. }
  31. fullPath() {
  32. return this.doc.fullPath(this.isIndex() ? "" : this.path);
  33. }
  34. dbPath() {
  35. return this.path.replace(/#.*/, "");
  36. }
  37. filePath() {
  38. return this.doc.fullPath(this._filePath());
  39. }
  40. fileUrl() {
  41. return this.doc.fileUrl(this._filePath());
  42. }
  43. _filePath() {
  44. let result = this.path.replace(/#.*/, "");
  45. if (result.slice(-5) !== ".html") {
  46. result += ".html";
  47. }
  48. return result;
  49. }
  50. isIndex() {
  51. return this.path === "index";
  52. }
  53. getType() {
  54. return this.doc.types.findBy("name", this.type);
  55. }
  56. loadFile(onSuccess, onError) {
  57. return app.db.load(this, onSuccess, onError);
  58. }
  59. };