Skip to content

Commit cdefce5

Browse files
committed
feat: upgrading page(after-9.0.0)
1 parent 4385e3f commit cdefce5

18 files changed

+690
-14
lines changed

docs/.vitepress/config.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {exampleAutoAnchorPreprocessor} from "./theme/anchor/exampleAutoAnchorPre
1010
import {mathjaxContainerPreprocessor} from "./theme/mathjax/mathjaxContainerPreprocessor";
1111
import {withMermaid} from "vitepress-plugin-mermaid";
1212
import {mermaidSpaceConverter} from "./theme/mermaid/mermaidSpaceConverter";
13+
import {injectUpgradePartsPlugin} from "./theme/upgrade/injectUpgradePartsPlugin";
1314

1415
const defaultLocale: string = 'en';
1516
const supportLocales: string[] = [
@@ -20,6 +21,7 @@ const editLinkPattern = `${repository.url}/edit/master/docs/:path`;
2021

2122
const commonSidebarOptions: VitePressSidebarOptions = {
2223
excludeFilesByFrontmatterFieldName: "hidden",
24+
excludeFolders: ["upgrade-parts"],
2325
collapsed: false,
2426
collapseDepth: 4,
2527
capitalizeFirst: true,
@@ -107,6 +109,7 @@ const vitepressOptions: UserConfig = {
107109
},
108110
config: (md) => {
109111
tabsPlugin(md);
112+
injectUpgradePartsPlugin(md);
110113
mermaidSpaceConverter(md);
111114
exampleAutoAnchorPreprocessor(md);
112115
mathjaxContainerPreprocessor(md);

docs/.vitepress/theme/style/global.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ kbd:not(.DocSearch-Button-Key) {
4949
line-height: 1;
5050
padding: 5px;
5151
white-space: nowrap;
52+
}
53+
54+
.menu .VPMenu {
55+
max-height: 64vh;
56+
}
57+
58+
.hide-anchor .header-anchor {
59+
display: none;
5260
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup>
2+
3+
import {nowChanges, nowUpgradeInfo} from "./upgrade";
4+
</script>
5+
6+
<template>
7+
<div style="text-align: center" v-if="nowChanges.length === 0 ">
8+
<b>Congratulations!<br/>You do not need to do anything to upgrade from {{nowUpgradeInfo.from}} to {{nowUpgradeInfo.to}}</b>
9+
</div>
10+
</template>
11+
12+
<style scoped>
13+
14+
</style>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<script setup lang="ts">
2+
3+
import {onMounted, onUnmounted, ref, watch} from "vue";
4+
import {getChanges, getVersionsAfter, getVersionsBefore, keyVersions, nowChanges, nowUpgradeInfo} from "./upgrade";
5+
6+
const fromOptions = ref([]);
7+
const toOptions = ref([]);
8+
const nowFrom = ref(nowUpgradeInfo.value.from);
9+
const nowTo = ref(nowUpgradeInfo.value.to);
10+
const isFromDropdownOpen = ref(false);
11+
const isToDropdownOpen = ref(false);
12+
13+
onMounted(() => {
14+
reload();
15+
window.addEventListener('hashchange', reload);
16+
});
17+
18+
onUnmounted(() => {
19+
window.removeEventListener('hashchange', reload);
20+
});
21+
22+
watch(nowFrom, () => {
23+
update();
24+
});
25+
26+
watch(nowTo, () => {
27+
update();
28+
});
29+
30+
function openFromDropdown() {
31+
isFromDropdownOpen.value = true;
32+
}
33+
34+
function closeFromDropdown() {
35+
isFromDropdownOpen.value = false;
36+
}
37+
38+
function selectFrom(version: string) {
39+
nowFrom.value = version;
40+
}
41+
42+
function openToDropdown() {
43+
isToDropdownOpen.value = true;
44+
}
45+
46+
function closeToDropdown() {
47+
isToDropdownOpen.value = false;
48+
}
49+
50+
function selectTo(version: string) {
51+
nowTo.value = version;
52+
}
53+
54+
function update() {
55+
nowUpgradeInfo.value = {
56+
from: nowFrom.value,
57+
to: nowTo.value
58+
};
59+
window.location.hash = `#${nowUpgradeInfo.value.from}-${nowUpgradeInfo.value.to}`;
60+
fromOptions.value = getVersionsBefore(nowUpgradeInfo.value.to);
61+
toOptions.value = getVersionsAfter(nowUpgradeInfo.value.from);
62+
nowChanges.value = getChanges(nowUpgradeInfo.value);
63+
const changes = nowChanges.value.map(change => `${change.from}-to-${change.to}`);
64+
document.querySelectorAll('.upgrade-parts-container div').forEach(ele => {
65+
if (changes.includes(ele.id)) {
66+
ele.classList.add('show');
67+
} else {
68+
ele.classList.remove('show');
69+
}
70+
});
71+
}
72+
73+
function reload() {
74+
const anchor = window.location.hash;
75+
const [from, to] = anchor.slice(1).split('-');
76+
if (keyVersions.slice(0, -1).includes(from) && getVersionsAfter(from).includes(to)) {
77+
nowFrom.value = from;
78+
nowTo.value = to;
79+
}
80+
update()
81+
}
82+
</script>
83+
84+
<template>
85+
<div class="card">
86+
I'm upgrading from
87+
<div class="dropdown" @mouseover="openFromDropdown" @mouseleave="closeFromDropdown">
88+
<button class="dropdown-button">{{ nowFrom }}</button>
89+
<div class="dropdown-content" :class="{ 'show-content': isFromDropdownOpen }">
90+
<a v-for="ver in fromOptions" @click="selectFrom(ver)">{{ ver }}</a>
91+
</div>
92+
</div>
93+
to
94+
<div class="dropdown" @mouseover="openToDropdown" @mouseleave="closeToDropdown">
95+
<button class="dropdown-button">{{ nowTo }}</button>
96+
<div class="dropdown-content" :class="{ 'show-content': isToDropdownOpen }">
97+
<a v-for="ver in toOptions" @click="selectTo(ver)">{{ ver }}</a>
98+
</div>
99+
</div>
100+
</div>
101+
</template>
102+
103+
<style scoped>
104+
.card {
105+
font-family: 'Helvetica Neue', sans-serif;
106+
width: fit-content;
107+
padding: 16px;
108+
margin-top: 20px;
109+
margin-bottom: 8px;
110+
border-radius: 4px;
111+
background-color: var(--vt-c-bg-soft);
112+
}
113+
114+
.dropdown {
115+
width: fit-content;
116+
position: relative;
117+
display: inline-block;
118+
}
119+
120+
.dropdown-button {
121+
border: 1px solid var(--vt-c-divider-light);
122+
border-radius: 4px;
123+
background-color: var(--vt-c-bg);
124+
color: var(--vt-c-text-1);
125+
padding: 10px;
126+
font-size: 16px;
127+
cursor: pointer;
128+
}
129+
130+
.dropdown-content {
131+
opacity: 0;
132+
overflow: hidden;
133+
display: block;
134+
position: absolute;
135+
background-color: var(--vp-c-bg-elv);
136+
border-radius: 4px;
137+
border: 1px solid var(--vp-c-divider);
138+
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
139+
z-index: 1;
140+
transition: opacity 0.25s;
141+
}
142+
143+
.dropdown-content a {
144+
font-size: 16px;
145+
color: var(--vp-c-text-1);
146+
padding: 10px;
147+
text-decoration: none;
148+
display: block;
149+
}
150+
151+
.dropdown-content a:hover {
152+
transition: color 0.2s;
153+
color: var(--vp-c-brand-1);
154+
}
155+
156+
.show-content {
157+
opacity: 1 !important;
158+
}
159+
</style>
160+
161+
<style>
162+
.show {
163+
display: initial !important;
164+
}
165+
166+
.default-hide {
167+
display: none;
168+
}
169+
</style>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import MarkdownIt from "markdown-it";
2+
import {upgradeInfos} from "./upgrade";
3+
import fs from "fs";
4+
5+
export const injectUpgradePartsPlugin = (md: MarkdownIt) => {
6+
md.core.ruler.before('normalize', 'generate-upgrade-page', (state) => {
7+
const INJECT_UPGRADE_PARTS = '<div class="upgrade-parts-container"></div>';
8+
if (!state.src.includes(INJECT_UPGRADE_PARTS)) {
9+
return;
10+
}
11+
state.src = `<div class="upgrade-parts-container">
12+
${state.src.replace(INJECT_UPGRADE_PARTS, upgradeInfos
13+
.map(info => {
14+
const targetPartFile = `./docs/en/upgrade-parts/${info.from}-to-${info.to}.md`;
15+
const targetPartContent = fs.readFileSync(targetPartFile, 'utf-8');
16+
return `
17+
<div id="${info.from}-to-${info.to}" class="default-hide">
18+
19+
## ${info.from}${info.to} {#${info.from}-to-${info.to}}
20+
21+
${targetPartContent}
22+
23+
</div>
24+
25+
`
26+
}).join('\n'))}
27+
</div>`;
28+
});
29+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {ref, Ref} from "vue";
2+
3+
class UpgradeInfo {
4+
from: string
5+
to: string
6+
}
7+
8+
export const upgradeInfos: UpgradeInfo[] = [
9+
// {from: '6.5.2', to: '7.0.0'},
10+
// {from: '7.0.0', to: '8.0.0'},
11+
// {from: '8.0.0', to: '8.1.0'},
12+
// {from: '8.3.1', to: '8.4.0'},
13+
// {from: '8.5.0', to: '8.5.1'},
14+
// {from: '8.5.1', to: '8.6.0'},
15+
{from: '8.6.0', to: '8.7.0'},
16+
{from: '8.8.0', to: '9.0.0'},
17+
{from: '9.0.0', to: '9.0.1'},
18+
{from: '9.0.1', to: '9.0.2'},
19+
{from: '9.0.3', to: '9.1.0'},
20+
{from: '9.2.0', to: '9.3.0'},
21+
]
22+
23+
export const keyVersions = Array.from(new Set(upgradeInfos.map(info => [info.from, info.to]).flat()));
24+
25+
export function getVersionsBefore(version: string) {
26+
const index = keyVersions.indexOf(version)
27+
if (index === -1) {
28+
return []
29+
}
30+
return keyVersions.slice(0, index)
31+
}
32+
33+
export function getVersionsAfter(version: string) {
34+
const index = keyVersions.indexOf(version)
35+
if (index === -1) {
36+
return []
37+
}
38+
return keyVersions.slice(index + 1)
39+
}
40+
41+
export function getDefaultUpgradeInfo() {
42+
return upgradeInfos[upgradeInfos.length - 1]
43+
}
44+
45+
export function getChanges(info: UpgradeInfo) {
46+
const result = [];
47+
let put = false;
48+
upgradeInfos.forEach(upgradeInfo => {
49+
if (info.from === upgradeInfo.from) {
50+
put = info.from !== upgradeInfo.from || info.to !== upgradeInfo.to;
51+
result.push(upgradeInfo);
52+
} else if (info.from === upgradeInfo.to) {
53+
put = true;
54+
} else if (info.to === upgradeInfo.from) {
55+
put = false;
56+
} else if (info.to === upgradeInfo.to) {
57+
put = false;
58+
result.push(upgradeInfo);
59+
} else if (put) {
60+
result.push(upgradeInfo);
61+
}
62+
});
63+
return result;
64+
}
65+
66+
export const nowUpgradeInfo: Ref<UpgradeInfo> = ref(getDefaultUpgradeInfo());
67+
export const nowChanges: Ref<UpgradeInfo[]> = ref([]);

docs/.vitepress/theme/versioning/VersionSwitcher.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import VPMenuLink from 'vitepress/dist/client/theme-default/components/VPMenuLin
66
import VPFlyout from 'vitepress/dist/client/theme-default/components/VPFlyout.vue'
77
import {parse} from "yaml";
88
import {useRoute} from "vitepress";
9+
import {currentVersion, latestVersion} from "./version";
910
1011
const props = defineProps<{
1112
screenMenu?: boolean
1213
}>();
1314
const route = useRoute();
1415
1516
let versionList: string[] = [];
16-
const currentVersion = ref('');
17-
const latestVersion = ref('');
1817
const versions = ref<string[]>([]);
1918
2019
function refresh() {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {ref} from "vue";
2+
3+
export const currentVersion = ref('');
4+
export const latestVersion = ref('');

docs/en/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ You can use the sidebar on the left to access the various sections of the docume
3737

3838
Using the search icon in the top left corner, you can search for anything in this entire documentation. For example, typing "Example" will show a list of examples which are included throughout the documentation.
3939

40-
## Latest documentation changes ( `9.4.1 → 9.7.0` )
40+
## Latest documentation changes ( `9.4.1 → 9.7.0` ) {#latest-changes}
4141
- Updates [Particle data (1.20.5+)](./create-commands/arguments/types/misc/particle-arguments) page with new `Trail` particle information.
4242
- Adds new [`thenNested()`](./create-commands/command-trees#reduce-indentation-with-nested-arguments) method to command trees.
4343
- Adds [tools](./test/intro) for running unit tests on commands.

docs/en/upgrade-parts/8.6.0-to-8.7.0.md

Whitespace-only changes.

0 commit comments

Comments
 (0)