marketplace.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Logseq Marketplace</title>
  9. <link rel="stylesheet"
  10. href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css"
  11. integrity="sha512-Oy18vBnbSJkXTndr2n6lDMO5NN31UljR8e/ICzVPrGpSud4Gkckb8yUpqhKuUNoE+o9gAb4O/rAxxw1ojyUVzg=="
  12. crossorigin="anonymous" referrerpolicy="no-referrer"/>
  13. <style>
  14. html, body {
  15. padding: 0;
  16. margin: 0;
  17. box-sizing: border-box;
  18. font-family: sans-serif;
  19. width: 100%;
  20. min-height: 100%;
  21. }
  22. html::-webkit-scrollbar-thumb {
  23. background-color: rgba(0, 0, 0, 0.1);
  24. }
  25. html::-webkit-scrollbar {
  26. background-color: rgba(0, 0, 0, 0.05);
  27. }
  28. html::-webkit-scrollbar-thumb:active {
  29. background-color: rgba(0, 0, 0, 0.2);
  30. }
  31. html::-webkit-scrollbar {
  32. width: 6px;
  33. height: 8px;
  34. }
  35. html::-webkit-scrollbar-corner {
  36. background: transparent;
  37. }
  38. body {
  39. display: flex;
  40. }
  41. #app {
  42. display: flex;
  43. justify-content: center;
  44. flex: 1;
  45. width: 900px;
  46. min-height: 100%;
  47. padding: 30px;
  48. margin: 0 auto;
  49. color: #333;
  50. }
  51. #app > strong {
  52. padding-top: 30vh;
  53. font-weight: 400;
  54. }
  55. pre {
  56. max-width: 800px;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div id="app"></div>
  62. <script src="./js/marked.min.js"></script>
  63. <script>
  64. ;(async function () {
  65. const app = document.getElementById('app')
  66. const url = new URL(location.href)
  67. const setMsg = (msg) => app.innerHTML = `<strong>${msg}</strong>`
  68. const repo = url.searchParams.get('repo')
  69. if (!repo) {
  70. return setMsg('Repo parameter not found!')
  71. }
  72. const setContent = (content) => app.innerHTML = `<main class="markdown-body">${content}</main>`
  73. const endpoint = (repo, branch, file) => `https://raw.githubusercontent.com/${repo}/${branch}/${file}`
  74. let content = ''
  75. let points = [
  76. endpoint(repo, 'master', 'README.md'), endpoint(repo, 'main', 'README.md'),
  77. endpoint(repo, 'master', 'readme.md'), endpoint(repo, 'main', 'readme.md')]
  78. let readme
  79. setMsg('Loading ...')
  80. for (let url of points) {
  81. try {
  82. const res = await fetch(url)
  83. if (res.status !== 200) {
  84. throw new Error(res.statusText)
  85. }
  86. content = await res.text()
  87. readme = url
  88. break
  89. } catch (e) {
  90. console.debug('Error:', url, e.message)
  91. }
  92. }
  93. const fixLink = (link) => readme.replace(/README\.md$/i, link)
  94. const isRelative = (href) => href && !href.startsWith('http') && !!href.match(/^([.\/]+|[^\/]+)/) && href.replace(/^[.\/]+/, '')
  95. marked.use({
  96. renderer: {
  97. link (href, title, text) {
  98. return `<a href="${href}" target="_blank" title="${title}">${text}</a>`
  99. },
  100. image (href, title, text) {
  101. let link = isRelative(href)
  102. if (link) {
  103. link = fixLink(link)
  104. return `<img style="max-width: 100%;" src="${link}" alt="${title}" />`
  105. }
  106. return false
  107. }
  108. }
  109. })
  110. content = marked.parse(content).replace('src="./', `src="${fixLink('')}`)
  111. setContent(content)
  112. }())
  113. </script>
  114. </body>
  115. </html>