Skip to content

Commit 0dfdcf3

Browse files
committed
chore: fix short link page
1 parent d49ff3c commit 0dfdcf3

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
},
4949
"license": "MIT",
5050
"devDependencies": {
51-
"@micro-app/plugin-deploy": "^0.0.6",
51+
"@micro-app/plugin-deploy": "^0.0.7",
5252
"@types/jest": "^24.9.1",
5353
"eslint-config-2o3t": "^2.0.1",
5454
"jest": "^24.9.0"
5555
},
5656
"dependencies": {
57-
"@micro-app/cli": "^0.3.10",
57+
"@micro-app/cli": "^0.3.11",
5858
"@vssue/api-github-v4": "^1.4.0",
5959
"@vssue/vuepress-plugin-vssue": "^1.4.3",
6060
"@vuepress/plugin-back-to-top": "^1.4.0",

theme/layouts/RedirectLayout.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div class="theme-container">
3+
<div class="theme-default-content">
4+
<h1>{{ $frontmatter.title }}</h1>
5+
<p>{{ $frontmatter.description }}</p>
6+
<hr />
7+
<p>
8+
原文链接:
9+
<NavLink :item="redirectLink" line>{{ redirectLink }}</NavLink>
10+
</p>
11+
<p>Redirect...</p>
12+
</div>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import NavLink from '@theme/components/NavLink.vue';
18+
export default {
19+
components: {
20+
NavLink,
21+
},
22+
computed: {
23+
redirectLink() {
24+
return this.$frontmatter.redirectLink;
25+
},
26+
},
27+
created() {
28+
this.$router.replace(this.redirectLink);
29+
},
30+
};
31+
</script>

theme/plugins/shortLinks/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = (options = {}, ctx) => ({
66
extendPageData($page) {
77
const themeConfig = ctx.themeConfig || {};
88

9-
let prefix = 's-';
9+
let prefix = '';
1010
if (typeof themeConfig.shortLinks === 'string') {
1111
prefix = themeConfig.shortLinks;
1212
}
@@ -16,10 +16,27 @@ module.exports = (options = {}, ctx) => ({
1616
const frontmatter = $page.frontmatter = $page.frontmatter || {};
1717
const shortLink = frontmatter.shortLink;
1818
if (shortLink !== false) {
19-
$page.shortLink = frontmatter.shortLink = shortLink || `/${$page.key.replace(/^v\-/, prefix)}`;
19+
$page.shortLink = frontmatter.shortLink = '/s' + (shortLink || `/${$page.key.replace(/^v\-/, prefix)}`);
2020
}
2121
}
2222
},
2323

24-
enhanceAppFiles: path.resolve(__dirname, 'enhanceAppFile.js'),
24+
async ready() {
25+
const { pages } = ctx;
26+
const allShortLinkPages = pages.filter(page => page.shortLink).map(page => {
27+
const id = `s-${page.key}`;
28+
const redirectLink = page._permalink;
29+
return {
30+
key: id, id,
31+
permalink: page.shortLink,
32+
frontmatter: {
33+
...page.frontmatter,
34+
layout: 'RedirectLayout',
35+
redirectLink,
36+
},
37+
};
38+
});
39+
40+
await Promise.all(allShortLinkPages.map(async page => ctx.addPage(page)));
41+
},
2542
});

yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,29 +1063,29 @@
10631063
"@types/istanbul-reports" "^1.1.1"
10641064
"@types/yargs" "^13.0.0"
10651065

1066-
"@micro-app/cli@^0.3.10":
1067-
version "0.3.10"
1068-
resolved "https://registry.yarnpkg.com/@micro-app/cli/-/cli-0.3.10.tgz#2081d92f9e1f97d74729def5328ae67401b03493"
1069-
integrity sha512-pTUzHEs+oa0zw1CSEiaT0qCIf2DszZh3MqsPmYgbAKaZYP5SAU3+L4lasUKYBlHH82LZqBM5AWDfRkIQQA6Nrg==
1066+
"@micro-app/cli@^0.3.11":
1067+
version "0.3.11"
1068+
resolved "https://registry.yarnpkg.com/@micro-app/cli/-/cli-0.3.11.tgz#b570284d25950fd3bf3cec9922a19b75a547def7"
1069+
integrity sha512-BOUBSBaSjNWbg6jd3SvjJ5W6mXQr9m4sZjGf33eLoh6GpVcf7XF2XGnwKyLVQwcVKj7oJ75aL/+9vrxkc/utNA==
10701070
dependencies:
1071-
"@micro-app/core" "^0.3.19"
1071+
"@micro-app/core" "^0.3.20"
10721072
"@zkochan/cmd-shim" "^4.3.0"
10731073
read-cmd-shim "^2.0.0"
10741074
update-notifier "^4.1.0"
10751075

1076-
"@micro-app/core@^0.3.19":
1077-
version "0.3.19"
1078-
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.3.19.tgz#4a2b67a9b110a9cb9454ee641c14a526076963be"
1079-
integrity sha512-u6AUTtn2pGCCanRakEG2WdWfqThpR6OLekEfZiXGKnC/O3palCDCOXtBkkndiU5HxI/8/O1xhgF0sF+6xkuGDw==
1076+
"@micro-app/core@^0.3.20":
1077+
version "0.3.21"
1078+
resolved "https://registry.yarnpkg.com/@micro-app/core/-/core-0.3.21.tgz#43315fa1713580d7500900f5ef90e183b9455b56"
1079+
integrity sha512-k7KOtQ6pxJbRAaMW8xF3jmuJxOQXjHXLCHtLNayU3ma1SNxOTGBbGbF7VyOBoo7V1sGlC40UjMaMJiqfvdE5lw==
10801080
dependencies:
10811081
"@micro-app/shared-utils" "^0.1.16"
10821082
dotenv "^8.2.0"
10831083
dotenv-expand "^5.1.0"
10841084

1085-
"@micro-app/plugin-deploy@^0.0.6":
1086-
version "0.0.6"
1087-
resolved "https://registry.yarnpkg.com/@micro-app/plugin-deploy/-/plugin-deploy-0.0.6.tgz#75a0b435a8f6b12252c7204642383511f66521b7"
1088-
integrity sha512-zvCqaKRTxwFx9A+A2p/RxdBJSDhYClpOJyQPmlx16RQwhqpFNUVdbR17qa7uaWCPyC11OM1IWAPiz10UA+XHeQ==
1085+
"@micro-app/plugin-deploy@^0.0.7":
1086+
version "0.0.7"
1087+
resolved "https://registry.yarnpkg.com/@micro-app/plugin-deploy/-/plugin-deploy-0.0.7.tgz#cc413f4a98b700db8e84a8a3137c6ee41ae71642"
1088+
integrity sha512-LcVQ3k3RSdsVaVd0HiBZJIF7RAZUAMHESekNt38xW4ZOPs9caU1UUhxVLNFo9ea5nCxqzvF/Ueo5e8iCQKW+WQ==
10891089
dependencies:
10901090
"@release-it/conventional-changelog" "^1.1.0"
10911091
release-it "^13.1.1"

0 commit comments

Comments
 (0)