-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
220 lines (188 loc) · 10.9 KB
/
index.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="referrer" content="same-origin">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Coup de pinceau</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap-reboot.css">
<script crossorigin="anonymous" src="https://cdn.polyfill.io/v2/polyfill.min.js?features=all"></script>
<script crossorigin="anonymous" src="./javascript/octokit-rest.min.js"></script>
<script crossorigin="anonymous" src="./javascript/bouture.js"></script>
<style>
body{
display: flex;
flex-direction: column;
align-items: stretch;
padding: 0 20%
}
body::after {
content: "";
background: url('https://png.pngtree.com/element_origin_min_pic/17/02/27/3c41f2373db576e9641e00950ef25a20.jpg');
opacity: 0.15;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
body > * {
max-width: 60em;
}
</style>
<script>
'use strict';
const access_token = (new URL(document.location)).searchParams.get('access_token')
document.addEventListener('DOMContentLoaded', e => {
const main = document.querySelector('main')
if (access_token) {
const octokit = new Octokit()
octokit.authenticate({
type: 'oauth',
token: access_token
})
octokit.users.get({})
.then(({data: user}) => {
const el = Bouture.div([
Bouture.p(`Hey ! Bienvenue dans coup de pinceau ! On a detecté que tu es connecté en tant que l'utilisateur Github @${user.login}`),
Bouture.form(
{
onSubmit: e => {
e.preventDefault();
const repo = e.target.querySelector('input').value;
const owner = user.login.toLowerCase()
const referenceIndexMd = {
owner: 'daktary-team',
repo: 'coup-de-pinceau',
path: 'index.md'
}
const publishedWebsiteURL = `https://${owner}.github.io/${repo}/`
// Create the new repo
octokit.repos.create({
name: repo,
homepage: publishedWebsiteURL,
has_issues: false,
has_projects: false,
has_wiki: false,
auto_init: false,
// license_template,
})
// Add an index.md
.then(() => octokit.repos.getContent(referenceIndexMd)
.then( ( {data: {content}} ) => octokit.repos.createFile({
owner,
repo,
path: referenceIndexMd.path,
message: `Création du fichier ${referenceIndexMd.path}`,
content
}))
)
// Create a _config.yml and pick a default theme
.then(() => octokit.repos.createFile({
owner,
repo,
path: '_config.yml',
message: `Création du fichier _config.yml`,
content: btoa(`theme: jekyll-theme-cayman`)
}))
// Create a _config.yml and pick a default theme
.then(() => octokit.repos.createFile({
owner,
repo,
path: 'exemple.md',
message: `Création de la page d'exemple`,
content: btoa(
'# Exemple de titre\n\n' +
'Hey ! Voici un contenu en [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#table-of-contents)'
)
}))
// Publish the repo (by creating a gh-pages branch)
.then(({data: {commit: {sha}}}) => octokit.gitdata.createReference({
owner,
repo,
ref: 'refs/heads/gh-pages',
sha
}))
// Make gh-pages branch the default
.then(() => octokit.repos.edit({
owner,
repo,
name: repo,
default_branch: 'gh-pages'
}))
// Delete master branch
.then(() => octokit.gitdata.deleteReference({
owner,
repo,
ref: 'heads/master',
}))
// all done, let's display the link to the blog
.then(() => {
console.log('success!')
return new Promise((resolve, reject) => {
(function checkIfBuilt(){
return octokit.repos.getPages({owner, repo})
.then(({data: {status}}) => {
console.log('build status', status)
if(status === 'built'){
resolve()
return;
}
if(status === 'errored'){
reject(new Error('Github pages build error'))
return;
}
setTimeout(checkIfBuilt, 500)
})
.catch(reject)
})()
})
.then( () => {
document.querySelector('form').replaceWith(
Bouture.div([
Bouture.span(`Bonne nouvelle ! Le `),
Bouture.a({href: `https://github.com/${owner}/${repo}/`}, 'dépôt github'),
Bouture.span(` a été créé et le `),
Bouture.a({href: publishedWebsiteURL}, `site a été publié ! `)
]).getElement()
)
})
})
.catch(err => console.error('Error while trying to publish a github repo', err))
}
},
[
Bouture
.label(`Donne-nous le nom du dépôt à créer et publier sur ton compte github`)
.input({type: 'text'}),
Bouture.button({type: 'submit'}, 'Créer le dépôt !')
]
)
]).getElement()
main.append(el)
})
.catch(err => console.error('api error', err))
} else {
const client_id = '2b4ed9ba835b05f83e2d'
const destination = 'https://daktary-team.github.io/coup-de-pinceau'
const redirect_url = 'https://file-moi-les-clefs.herokuapp.com/gh-callback'
const a = Bouture.a({href: `https://github.com/login/oauth/authorize?client_id=${client_id}&scope=public_repo&redirect_uri=${redirect_url}?destination=${destination}`}, 'Login with Github').getElement()
console.log('a', a)
main.append(a)
}
}, {once: true})
</script>
</head>
<body>
<header>
<h1>Bienvenue sur Coup de pinceau</h1>
<p>Publiez vos contenus markdown en un clic.</p>
</header>
<main>
</main>
<footer>
</footer>
</body>
</html>