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. subMaxLevel: 2,
  38. auto2top: true,
  39. routerMode: window.DOCSIFY_ROUTER_MODE || "hash",
  40. noEmoji: true,
  41. alias: {
  42. '/latest/': 'README.md',
  43. '/latest/(.*)': '$1',
  44. '/([0-9]+\.[0-9]+)/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/$2',
  45. '/([0-9]+\.[0-9]+)/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v$1.0/docs/README.md',
  46. '/(.*)': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/$1',
  47. '/': 'https://raw.githubusercontent.com/imgproxy/imgproxy/v' + latestVersion + '.0/docs/README.md',
  48. },
  49. search: {
  50. namespace: 'docs-imgproxy',
  51. depth: 6,
  52. pathNamespaces: versions.map(function (v) { return "/" + v })
  53. },
  54. namespaces: [
  55. {
  56. id: "version",
  57. values: versions,
  58. optional: true,
  59. selector: "#version-selector"
  60. }
  61. ],
  62. plugins: [
  63. function (hook, vm) {
  64. window.DocsifyVM = vm
  65. hook.beforeEach(function () {
  66. if (clink) {
  67. clink.href = "https://docs.imgproxy.net" + vm.route.path
  68. }
  69. });
  70. hook.doneEach(function () {
  71. var appNameLink = Docsify.dom.find("#home-link");
  72. if (!appNameLink) return;
  73. appNameLink.href = vm.config.currentNamespace;
  74. });
  75. hook.doneEach(function() {
  76. if (document.title != documentTitleBase)
  77. document.title += " | " + documentTitleBase;
  78. });
  79. hook.afterEach(function (html) {
  80. var docName = vm.route.file.replace(
  81. /https\:\/\/raw.githubusercontent\.com\/(.*)\/docs\//, ''
  82. )
  83. if (!docName) {
  84. return html;
  85. }
  86. var editButton = '<a class="github-edit-btn" title="Edit on GitHub" href="' +
  87. docEditBase + docName +
  88. '" target="_blank">' +
  89. 'Edit on <strong>GitHub</strong>' +
  90. '</a>';
  91. return html + editButton
  92. })
  93. hook.beforeEach(function (content, next) {
  94. content = content.replaceAll(proBadgeRegex, proLink)
  95. content = content.replaceAll(oldProBadge, proLink)
  96. console.log(content)
  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. }