forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marketplace.html
133 lines (115 loc) · 3.43 KB
/
marketplace.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Logseq Marketplace</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css"
integrity="sha512-Oy18vBnbSJkXTndr2n6lDMO5NN31UljR8e/ICzVPrGpSud4Gkckb8yUpqhKuUNoE+o9gAb4O/rAxxw1ojyUVzg=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<style>
html, body {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: sans-serif;
width: 100%;
min-height: 100%;
}
html::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.1);
}
html::-webkit-scrollbar {
background-color: rgba(0, 0, 0, 0.05);
}
html::-webkit-scrollbar-thumb:active {
background-color: rgba(0, 0, 0, 0.2);
}
html::-webkit-scrollbar {
width: 6px;
height: 8px;
}
html::-webkit-scrollbar-corner {
background: transparent;
}
body {
display: flex;
}
#app {
display: flex;
justify-content: center;
flex: 1;
width: 900px;
min-height: 100%;
padding: 30px;
margin: 0 auto;
color: #333;
}
#app > strong {
padding-top: 30vh;
font-weight: 400;
}
pre {
max-width: 800px;
}
</style>
</head>
<body>
<div id="app"></div>
<script src="./js/marked.min.js"></script>
<script>
;(async function () {
const app = document.getElementById('app')
const url = new URL(location.href)
const setMsg = (msg) => app.innerHTML = `<strong>${msg}</strong>`
const repo = url.searchParams.get('repo')
if (!repo) {
return setMsg('Repo parameter not found!')
}
const setContent = (content) => app.innerHTML = `<main class="markdown-body">${content}</main>`
const endpoint = (repo, branch, file) => `https://raw.githubusercontent.com/${repo}/${branch}/${file}`
let content = ''
let points = [
endpoint(repo, 'master', 'README.md'), endpoint(repo, 'main', 'README.md'),
endpoint(repo, 'master', 'readme.md'), endpoint(repo, 'main', 'readme.md')]
let readme
setMsg('Loading ...')
for (let url of points) {
try {
const res = await fetch(url)
if (res.status !== 200) {
throw new Error(res.statusText)
}
content = await res.text()
readme = url
break
} catch (e) {
console.debug('Error:', url, e.message)
}
}
const fixLink = (link) => readme.replace(/README\.md$/i, link)
const isRelative = (href) => href && !href.startsWith('http') && !!href.match(/^([.\/]+|[^\/]+)/) && href.replace(/^[.\/]+/, '')
marked.use({
renderer: {
link (href, title, text) {
return `<a href="${href}" target="_blank" title="${title}">${text}</a>`
},
image (href, title, text) {
let link = isRelative(href)
if (link) {
link = fixLink(link)
return `<img style="max-width: 100%;" src="${link}" alt="${title}" />`
}
return false
}
}
})
content = marked(content).replace('src="./', `src="${fixLink('')}`)
setContent(content)
}())
</script>
</body>
</html>