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

Commit 34a12c4

Browse files
committed
Show Readme file from github in Component.vue page
1 parent b6874cf commit 34a12c4

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

src/components/Component.vue

Lines changed: 43 additions & 2 deletions
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">
@@ -142,6 +147,7 @@ A watcher has been added to the component to render the details dynamically when
142147
contributors: [],
143148
license: '',
144149
author: '',
150+
readme: '',
145151
githubURL: 'https://www.github.com/',
146152
sniper_data: {},
147153
js_dependencies: [],
@@ -205,6 +211,7 @@ A watcher has been added to the component to render the details dynamically when
205211
value: details.forks
206212
}
207213
];
214+
console.log(this.githubURL.slice(0, 8) + 'api.' + this.githubURL.slice(8, 18) + '/repos' + this.githubURL.slice(18) + '/contents/README.md');
208215
const splitTime = time =>
209216
time && typeof time === 'string' ? time.split('T')[0] : undefined;
210217
this.stats = [
@@ -246,10 +253,37 @@ A watcher has been added to the component to render the details dynamically when
246253
this.sniper_data = result.data.sniper_data;
247254
this.js_dependencies = result.data.js_dependencies;
248255
this.css_dependencies = result.data.css_dependencies;
249-
this.isLoading = false;
250256
const url = `${API_URL}details/${this.name}`;
251257
console.log(this.sniper_data);
252-
258+
axios({
259+
method: 'GET',
260+
url: this.githubURL.slice(0, 8) + 'api.' + this.githubURL.slice(8, 18) + '/repos' + this.githubURL.slice(18) + '/contents/README.md'
261+
}).then(
262+
result => {
263+
this.readme = result.data.content;
264+
axios({
265+
method: 'POST',
266+
url: 'https://api.github.com/markdown/raw',
267+
headers: {'Content-Type': 'text/plain'},
268+
data: Buffer.from(result.data.content, 'base64').toString('ascii')
269+
}).then(
270+
result => {
271+
this.readme = result.data;
272+
this.isLoading = false;
273+
},
274+
error => {
275+
this.readme = '';
276+
this.isLoading = false;
277+
console.log(error);
278+
}
279+
);
280+
},
281+
error => {
282+
this.readme = '';
283+
this.isLoading = false;
284+
console.log(error);
285+
}
286+
);
253287
axios({ method: 'GET', url }).then(
254288
result => {
255289
if (result.data.error) {
@@ -280,6 +314,13 @@ A watcher has been added to the component to render the details dynamically when
280314
return 'none';
281315
}
282316
},
317+
computeReadme () {
318+
if (this.readme === '') {
319+
return 'Not available';
320+
} else {
321+
return this.readme;
322+
}
323+
},
283324
computeLicense () {
284325
if (this.license === '') {
285326
return 'Not available';

0 commit comments

Comments
 (0)