Skip to content

Commit bbec8ca

Browse files
committed
docs: link directly to equivalent pages in translations
vuejs/docs@883b753
1 parent b077f96 commit bbec8ca

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

src/.vuepress/config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,23 +423,28 @@ module.exports = {
423423
// Translation maintainers: Please include the link below to the English documentation
424424
{
425425
text: 'English',
426-
link: 'https://v3.vuejs.org/'
426+
link: 'https://v3.vuejs.org/',
427+
isTranslation: true
427428
},
428429
{
429430
text: '中文',
430-
link: 'https://v3.cn.vuejs.org/'
431+
link: 'https://v3.cn.vuejs.org/',
432+
isTranslation: true
431433
},
432434
{
433435
text: '한국어',
434-
link: 'https://v3.ko.vuejs.org/'
436+
link: 'https://v3.ko.vuejs.org/',
437+
isTranslation: true
435438
},
436439
// {
437-
// text: '日本語',
438-
// link: 'https://v3.ja.vuejs.org/'
440+
// text: '日本語',
441+
// link: 'https://v3.ja.vuejs.org/',
442+
// isTranslation: true
439443
// },
440444
{
441445
text: 'Русский',
442-
link: 'https://v3.ru.vuejs.org/'
446+
link: 'https://v3.ru.vuejs.org/ru/',
447+
isTranslation: true
443448
},
444449
{
445450
text: 'その他の翻訳',

src/.vuepress/theme/components/NavLink.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,26 @@
2222
</template>
2323

2424
<script>
25+
import Vue from 'vue'
2526
import { isExternal, isMailto, isTel, ensureExt } from '../util'
2627
28+
const pageLocation = Vue.observable({ path: '/' })
29+
30+
let initPath = () => {
31+
initPath = () => {}
32+
33+
const updatePath = () => {
34+
pageLocation.path = location.pathname
35+
}
36+
37+
updatePath()
38+
39+
// There is no event for detecting navigation but these cover most cases
40+
for (const event of ['focusin', 'scroll', 'mouseover', 'keydown']) {
41+
window.addEventListener(event, updatePath)
42+
}
43+
}
44+
2745
export default {
2846
name: 'NavLink',
2947
@@ -35,7 +53,13 @@ export default {
3553
3654
computed: {
3755
link () {
38-
return ensureExt(this.item.link)
56+
let link = ensureExt(this.item.link)
57+
58+
if (this.item.isTranslation) {
59+
link = link.replace(/\/$/, '') + pageLocation.path
60+
}
61+
62+
return link
3963
},
4064
4165
exact () {
@@ -68,7 +92,7 @@ export default {
6892
},
6993
7094
rel () {
71-
if (this.isNonHttpURI) {
95+
if (this.isNonHttpURI || this.item.isTranslation) {
7296
return null
7397
}
7498
if (this.item.rel) {
@@ -82,6 +106,10 @@ export default {
82106
focusoutAction () {
83107
this.$emit('focusout')
84108
}
109+
},
110+
111+
mounted () {
112+
initPath()
85113
}
86114
}
87115
</script>

src/.vuepress/theme/layouts/404.vue

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
<div class="theme-default-content">
44
<h1>404</h1>
55

6-
<blockquote>{{ getMsg() }}</blockquote>
6+
<blockquote>
7+
<p>Whoops! This page doesn't exist.</p>
8+
</blockquote>
9+
10+
<p v-show="isTranslation">
11+
New pages are added to the documentation all the time. This page might not be included in all of the translations yet.
12+
</p>
713

814
<RouterLink to="/">
915
Take me home.
@@ -13,17 +19,22 @@
1319
</template>
1420

1521
<script>
16-
const msgs = [
17-
`There's nothing here.`,
18-
`How did we get here?`,
19-
`That's a Four-Oh-Four.`,
20-
`Looks like we've got some broken links.`
21-
]
22+
import { repos } from '../../components/guide/contributing/translations-data.js'
2223
2324
export default {
24-
methods: {
25-
getMsg () {
26-
return msgs[Math.floor(Math.random() * msgs.length)]
25+
data () {
26+
return {
27+
isTranslation: false
28+
}
29+
},
30+
31+
mounted () {
32+
const toOrigin = url => (String(url).match(/https?:\/\/[^/]+/) || [])[0]
33+
const referrer = toOrigin(document.referrer)
34+
35+
// Did we get here from a translation?
36+
if (referrer && referrer !== location.origin && repos.some(({ url }) => toOrigin(url) === referrer)) {
37+
this.isTranslation = true
2738
}
2839
}
2940
}

0 commit comments

Comments
 (0)