Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 8f27698

Browse files
Merge pull request #81 from Nikhil-Vats/master
Show Readme file from github in Component.vue page
2 parents 9507662 + 9120a80 commit 8f27698

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/components/Component.vue

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
<contributor v-for="contributor in contributors" :key="contributor.id" :imageURL="contributor.avatar_url" :name="contributor.username" />
8686
</div>
8787
</div>
88+
<div id="readme" class="section">
89+
<div class="title">README</div>
90+
<div class="content" v-html="computeReadme ()">
91+
</div>
92+
</div>
8893
<div id="legal" class="section">
8994
<div class="title">Legal</div>
9095
<div class="content">
@@ -144,6 +149,7 @@ A watcher has been added to the component to render the details dynamically when
144149
contributors: [],
145150
license: '',
146151
author: '',
152+
readme: '',
147153
githubURL: 'https://www.github.com/',
148154
sniper_data: {},
149155
js_dependencies: [],
@@ -250,10 +256,38 @@ A watcher has been added to the component to render the details dynamically when
250256
this.sniper_data = result.data.sniper_data;
251257
this.js_dependencies = result.data.js_dependencies;
252258
this.css_dependencies = result.data.css_dependencies;
253-
this.isLoading = false;
254259
const url = `${API_URL}details/${this.name}`;
255260
console.log(this.sniper_data);
256261
262+
axios({
263+
method: 'GET',
264+
url: `https://api.github.com/repos/${this.githubURL.slice(19)}/contents/README.md`
265+
}).then(
266+
result => {
267+
this.readme = result.data.content;
268+
axios({
269+
method: 'POST',
270+
url: 'https://api.github.com/markdown/raw',
271+
headers: {'Content-Type': 'text/plain'},
272+
data: Buffer.from(result.data.content, 'base64').toString('ascii')
273+
}).then(
274+
result => {
275+
this.readme = result.data;
276+
this.isLoading = false;
277+
},
278+
error => {
279+
this.readme = '';
280+
this.isLoading = false;
281+
console.log(error);
282+
}
283+
);
284+
},
285+
error => {
286+
this.readme = '';
287+
this.isLoading = false;
288+
console.log(error);
289+
}
290+
);
257291
axios({ method: 'GET', url }).then(
258292
result => {
259293
if (result.data.error) {
@@ -284,6 +318,13 @@ A watcher has been added to the component to render the details dynamically when
284318
return 'none';
285319
}
286320
},
321+
computeReadme () {
322+
if (this.readme === '') {
323+
return 'Not available';
324+
} else {
325+
return this.readme;
326+
}
327+
},
287328
computeLicense () {
288329
if (this.license === '') {
289330
return 'Not available';
@@ -406,6 +447,11 @@ A watcher has been added to the component to render the details dynamically when
406447
// margin-top: -20px;
407448
color: rgba(0, 0, 0, 0.7);
408449
}
450+
#readme {
451+
* {
452+
overflow-x: auto;
453+
}
454+
}
409455
#biojsio {
410456
width: 80%;
411457
border-radius: 3px;

0 commit comments

Comments
 (0)