-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (79 loc) · 2.33 KB
/
index.js
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
MathJax = {
loader: {
load: ['input/asciimath']
},
asciimath: {
delimiters: [['$', '$']]
}
};
const repoDetails = {
github_api_url: "https://api.github.com/repos",
username: "mohanen",
repo_name: "cheatsheet_test",
}
const repo_url = repoDetails.github_api_url + "/" + repoDetails.username + "/" + repoDetails.repo_name;
const repo_content_url = repo_url + "/contents";
var mdit = window.markdownit({
html: false, // Enable HTML tags in source
breaks: false, // Convert '\n' in paragraphs into <br>
linkify: true, // Autoconvert URL-like text to links
typographer: true,
quotes: '“”‘’',
highlight: function (/*str, lang*/) { return ''; }
});
var vueFolder = new Vue({
el: '#folders',
data: { githubFolders: [], enabled: true }
})
var vueFile = new Vue({
el: '#file',
data: { md: "", enabled: false },
updated: function () {
this.$nextTick(function () {
// Code that will run only after the entire view has been re-rendered
MathJax && MathJax.typeset && MathJax.typeset()
})
}
})
function updateHome() {
axios
.get(repo_content_url)
.then(response => {
vueFolder.githubFolders = response.data;
vueFolder.githubFolders.forEach((folder, index) => {
axios
.get(folder.url)
.then(response => {
vueFolder.githubFolders[index].files = response.data;
vueFolder.$forceUpdate();
})
});
})
}
function openMd(mdFileUrl) {
vueFolder.enabled = false;
vueFile.enabled = true;
axios
.get(mdFileUrl)
.then(response => {
vueFile.md = response.data;
console.log(response.data);
vueFile.$forceUpdate();
})
}
function home() {
vueFolder.enabled = true;
vueFile.enabled = false;
vueFile.md = "";
updateHome();
}
// helper functions
const hf = {
toSentenceCase: function (text) {
var result = text.replace(/([A-Z])/g, " $1");
return result.charAt(0).toUpperCase() + result.slice(1);
},
toHeaderCase: text => (hf.toSentenceCase(text).toUpperCase()),
toMdFileCase: text => (hf.toSentenceCase(text).slice(0, -".md".length)),
}
home();