forked from typeorm/typeorm.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentPage.js
61 lines (60 loc) · 2.17 KB
/
DocumentPage.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
const DocumentPage = {
template: `
<div class="document">
<markdown-reader :file="readUrl" :hash="hash"></markdown-reader>
<div class="contribute small">
{{$t("contribute")}} <a :href="editUrl">{{$t("edit")}}</a>
</div>
</div>
`,
data: function() {
return {
document: this.$route.params.document,
hash: this.$route.hash,
locale: $cookies.get("locale") || "en",
readLink: "https://raw.githubusercontent.com/typeorm/typeorm/master/",
editLink: "https://github.com/typeorm/typeorm/edit/master/"
};
},
watch: {
'$route': function(to, from) {
this.document = to.params.document;
this.hash = to.hash;
this.updateTitle();
}
},
create: function() {
this.updateTitle();
},
methods: {
updateTitle: function() {
const link = this.$t("links").find(link => link.url === this.document);
if (link) {
window.document.title = link.name + " | TypeORM";
}
}
},
components: {
"markdown-reader": MarkdownReader,
},
computed: {
readUrl: function () {
if (this.document === "changelog") {
return `https://raw.githubusercontent.com/typeorm/typeorm/master/CHANGELOG.md`;
} else if (!this.document || this.document === "readme") {
return this.readLink + (this.locale === "en"? `README.md`: `README-${this.locale}.md`);
} else {
return this.readLink + (this.locale === "en"? `docs/${this.document}.md`: `docs/${this.locale}/${this.document}.md`);
}
},
editUrl: function () {
if (this.document === "changelog") {
return `https://github.com/typeorm/typeorm/edit/master/CHANGELOG.md`;
} else if (!this.document) {
return this.editLink + (this.locale === "en"? "README.md": `README-${this.locale}.md`);
} else {
return this.editLink + (this.locale === "en"? `docs/${this.document}.md`: `docs/${this.locale}/${this.document}.md`);
}
}
}
};