docsify-init.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. if (window.DOCSIFY_ROUTER_MODE === "history") {
  2. var clink = document.createElement("link")
  3. clink.rel = "canonical"
  4. document.getElementsByTagName("head")[0].appendChild(clink)
  5. }
  6. var documentTitleBase = document.title;
  7. var gitterURL = "https://gitter.im/imgproxy/imgproxy";
  8. var gitterBadgeURL = "https://img.shields.io/gitter/room/imgproxy/imgproxy" +
  9. "?color=1775d3&style=for-the-badge&logo=gitter";
  10. var gitterBadge = '<div class="gitter">' +
  11. '<a class="gitter-link" href="' + gitterURL + '" target="_blank">' +
  12. '<img alt="Chat on Gitter" src="' + gitterBadgeURL + '">' +
  13. '</div></a>';
  14. var docEditBase = 'https://github.com/imgproxy/imgproxy/edit/master/docs/';
  15. var proBadge = document.createElement("img")
  16. proBadge.setAttribute("src", "/assets/pro.svg")
  17. proBadge.setAttribute("title", "This feature is available in imgproxy Pro")
  18. var proBadgeRegex = /\!\[pro\]\((\S+)\)/g;
  19. var proLink = '<a class="badge" href="https://imgproxy.net/#pro" target="_blank">' +
  20. proBadge.outerHTML + '</a>';
  21. var oldProBadge = "<i class='badge badge-pro'></i>";
  22. var versions = ["latest"].concat(window.IMGPROXY_VERSIONS);
  23. var latestVersion = window.IMGPROXY_VERSIONS[0];
  24. var versionSelect = '<select id="version-selector" name="version" class="sidebar-version-select">';
  25. versions.forEach(function (version) {
  26. var value = version == latestVersion ? "" : version;
  27. versionSelect = versionSelect + '<option value="' + value + '">' + version + '</value>';
  28. });
  29. versionSelect = versionSelect + '</select>';
  30. window.$docsify = {
  31. name: '<a id="home-link" class="app-name-link" href="/"><img src="/assets/logo.svg"></a>' +
  32. gitterBadge +
  33. versionSelect,
  34. nameLink: false,
  35. repo: 'https://github.com/imgproxy',
  36. loadSidebar: true,
  37. relativePath: true,
  38. subMaxLevel: 3,
  39. auto2top: true,
  40. routerMode: window.DOCSIFY_ROUTER_MODE || "hash",
  41. noEmoji: true,
  42. alias: {
  43. '/latest/': 'README.md',
  44. '/latest/(.*)': '$1',
  45. '/([0-9]+\.[0-9]+)/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/$2',
  46. '/([0-9]+\.[0-9]+)/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/README.md',
  47. '/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/$1',
  48. '/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/README.md',
  49. },
  50. search: {
  51. namespace: 'docs-imgproxy',
  52. depth: 6,
  53. pathNamespaces: versions.map(function (v) { return "/" + v })
  54. },
  55. namespaces: [
  56. {
  57. id: "version",
  58. values: versions,
  59. optional: true,
  60. selector: "#version-selector"
  61. }
  62. ],
  63. plugins: [
  64. function (hook, vm) {
  65. window.DocsifyVM = vm
  66. hook.beforeEach(function () {
  67. if (clink) {
  68. clink.href = "https://docs.imgproxy.net" + vm.route.path
  69. }
  70. });
  71. hook.doneEach(function () {
  72. var appNameLink = Docsify.dom.find("#home-link");
  73. if (!appNameLink) return;
  74. appNameLink.href = vm.config.currentNamespace;
  75. });
  76. hook.doneEach(function() {
  77. if (document.title != documentTitleBase)
  78. document.title += " | " + documentTitleBase;
  79. });
  80. hook.afterEach(function (html) {
  81. var docName = vm.route.file.replace(
  82. /https\:\/\/raw.githubusercontent\.com\/(.*)\/docs\//, ''
  83. )
  84. if (!docName) {
  85. return html;
  86. }
  87. var editButton = '<a class="github-edit-btn" title="Edit on GitHub" href="' +
  88. docEditBase + docName +
  89. '" target="_blank">' +
  90. 'Edit on <strong>GitHub</strong>' +
  91. '</a>';
  92. return html + editButton
  93. })
  94. hook.beforeEach(function (content, next) {
  95. content = content.replaceAll(proBadgeRegex, proLink)
  96. content = content.replaceAll(oldProBadge, proLink)
  97. next(content)
  98. })
  99. hook.doneEach(function () {
  100. var badges = Docsify.dom.findAll(".sidebar .badge-pro")
  101. badges.forEach(function (b) { b.replaceWith(proBadge.cloneNode()) })
  102. // Docsify cuts off "target" sometimes
  103. var links = Docsify.dom.findAll("a.badge")
  104. links.forEach(function(l){ l.setAttribute("target", "_blank") })
  105. })
  106. }
  107. ]
  108. }