Skip to content

Commit 0d23f9b

Browse files
authored
test: upload to COS (#588)
* test: upload to COS * test: build & upload * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * update: archive * tweak: gatsby link for trailing slash * tweak: purge cdn cache * test * test * test * tweak: cos sync * test * test * test * fix: gatsby-link patch * test * test * update: nocache * fix: archive header * fix: archive header * tweak: archive notice * tweak: redirect url * tweak: 404Template * update: docs-staging branch * fix: 404Template * chore: use prod config
1 parent fde3e01 commit 0d23f9b

File tree

11 files changed

+2767
-1429
lines changed

11 files changed

+2767
-1429
lines changed

.github/workflows/archive.yml

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,50 @@ jobs:
6262
GATSBY_DOC_BUILD_SUBMODULE_SHA: ${{ steps.submodule.outputs.submodule_status }}
6363
WEBSITE_BUILD_TYPE: archive
6464
run: |
65-
yarn build --verbose
65+
yarn build
6666
6767
- name: Check output
6868
id: check-output
6969
run: |
7070
sudo apt install tree
7171
tree public
7272
73-
- name: Set known_hosts
74-
id: known-hosts
73+
- name: Install coscli
7574
run: |
76-
echo "BJ1=$(ssh-keyscan -H ${{ secrets.BJ_1_HOST }})" >> $GITHUB_OUTPUT
77-
echo "BJ2=$(ssh-keyscan -H ${{ secrets.BJ_2_HOST }})" >> $GITHUB_OUTPUT
78-
echo "LA1=$(ssh-keyscan -H ${{ secrets.LA_1_HOST }})" >> $GITHUB_OUTPUT
79-
echo "LA2=$(ssh-keyscan -H ${{ secrets.LA_2_HOST }})" >> $GITHUB_OUTPUT
75+
wget https://cosbrowser.cloud.tencent.com/software/coscli/coscli-linux-amd64
76+
mv coscli-linux-amd64 coscli
77+
chmod 755 coscli
8078
81-
- name: Install SSH Key
82-
uses: shimataro/ssh-key-action@v2
83-
with:
84-
key: ${{ secrets.SSH_KEY }}
85-
known_hosts: |
86-
${{ steps.known-hosts.outputs.BJ1 }}
87-
${{ steps.known-hosts.outputs.BJ2 }}
88-
${{ steps.known-hosts.outputs.LA1 }}
89-
${{ steps.known-hosts.outputs.LA2 }}
90-
91-
- name: Deploy to BJ1
79+
- name: Deploy to COS
9280
run: |
93-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_1_HOST }}:${{ secrets.DEPLOY_PATH_ARCHIVE }}"
81+
./coscli sync public/ cos://${{ secrets.TENCENTCLOUD_ARCHIVE_BUCKET_ID }} \
82+
--init-skip \
83+
--recursive \
84+
--routines 16 \
85+
--secret-id ${{ secrets.TENCENTCLOUD_SECRET_ID }} \
86+
--secret-key ${{ secrets.TENCENTCLOUD_SECRET_KEY }} \
87+
--endpoint cos.na-ashburn.myqcloud.com
9488
95-
- name: Deploy to BJ2
96-
run: |
97-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_2_HOST }}:${{ secrets.DEPLOY_PATH_ARCHIVE }}"
89+
cdn-refresh:
90+
needs: build
91+
runs-on: ubuntu-latest
92+
name: Refresh CDN Cache
93+
env:
94+
TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }}
95+
TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }}
96+
steps:
97+
- name: Checkout repository
98+
uses: actions/checkout@v4
9899

99-
- name: Deploy to LA1
100-
run: |
101-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_1_HOST }}:${{ secrets.DEPLOY_PATH_ARCHIVE }}"
100+
- name: Set up Python environment
101+
uses: actions/setup-python@v5
102+
with:
103+
python-version: '3.12'
104+
architecture: 'x64'
105+
106+
- name: Install Tencent Cloud CLI
107+
run: pipx install tccli
108+
109+
- name: Purge production CDN cache
110+
run: tccli cdn PurgePathCache --Paths '["https://docs-archive.pingcap.com/"]' --FlushType delete
102111

103-
- name: Deploy to LA2
104-
run: |
105-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_2_HOST }}:${{ secrets.DEPLOY_PATH_ARCHIVE }}"

.github/workflows/production.yml

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ on:
1818
type: boolean
1919
default: false
2020
required: false
21+
nocache:
22+
description: "Build without cache"
23+
type: boolean
24+
default: false
25+
required: false
2126

2227
concurrency: ci-prod
2328

@@ -81,6 +86,11 @@ jobs:
8186
sudo rm -rf /tmp/*
8287
sudo rm -rf /home/runner/work/_temp/*
8388
89+
- name: Clean cache
90+
if: ${{ inputs.nocache }}
91+
run: |
92+
yarn clean
93+
8494
- name: Build website
8595
if: ${{ !inputs.fallback || (steps.gatsby-cache.outputs.cache-hit != 'true') }}
8696
env:
@@ -92,44 +102,49 @@ jobs:
92102
GATSBY_DOC_BUILD_SUBMODULE_SHA: ${{ steps.submodule.outputs.submodule_status }}
93103
GATSBY_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
94104
run: |
95-
yarn build --verbose
105+
yarn build
96106
97107
- name: Check output
98108
id: check-output
99109
run: |
100110
sudo apt install tree
101111
tree public
102112
103-
- name: Set known_hosts
104-
id: known-hosts
113+
- name: Install coscli
105114
run: |
106-
echo "BJ1=$(ssh-keyscan -H ${{ secrets.BJ_1_HOST }})" >> $GITHUB_OUTPUT
107-
echo "BJ2=$(ssh-keyscan -H ${{ secrets.BJ_2_HOST }})" >> $GITHUB_OUTPUT
108-
echo "LA1=$(ssh-keyscan -H ${{ secrets.LA_1_HOST }})" >> $GITHUB_OUTPUT
109-
echo "LA2=$(ssh-keyscan -H ${{ secrets.LA_2_HOST }})" >> $GITHUB_OUTPUT
115+
wget https://cosbrowser.cloud.tencent.com/software/coscli/coscli-linux-amd64
116+
mv coscli-linux-amd64 coscli
117+
chmod 755 coscli
110118
111-
- name: Install SSH Key
112-
uses: shimataro/ssh-key-action@v2
113-
with:
114-
key: ${{ secrets.SSH_KEY }}
115-
known_hosts: |
116-
${{ steps.known-hosts.outputs.BJ1 }}
117-
${{ steps.known-hosts.outputs.BJ2 }}
118-
${{ steps.known-hosts.outputs.LA1 }}
119-
${{ steps.known-hosts.outputs.LA2 }}
120-
121-
- name: Deploy to BJ1
119+
- name: Deploy to COS
122120
run: |
123-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_1_HOST }}:${{ secrets.DEPLOY_PATH }}"
121+
./coscli sync public/ cos://${{ secrets.TENCENTCLOUD_BUCKET_ID }} \
122+
--init-skip \
123+
--recursive \
124+
--routines 16 \
125+
--secret-id ${{ secrets.TENCENTCLOUD_SECRET_ID }} \
126+
--secret-key ${{ secrets.TENCENTCLOUD_SECRET_KEY }} \
127+
--endpoint cos.na-ashburn.myqcloud.com
128+
129+
cdn-refresh:
130+
needs: build
131+
runs-on: ubuntu-latest
132+
name: Refresh CDN Cache
133+
env:
134+
TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }}
135+
TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }}
136+
steps:
137+
- name: Checkout repository
138+
uses: actions/checkout@v4
124139

125-
- name: Deploy to BJ2
126-
run: |
127-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.BJ_2_HOST }}:${{ secrets.DEPLOY_PATH }}"
140+
- name: Set up Python environment
141+
uses: actions/setup-python@v5
142+
with:
143+
python-version: "3.12"
144+
architecture: "x64"
128145

129-
- name: Deploy to LA1
130-
run: |
131-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_1_HOST }}:${{ secrets.DEPLOY_PATH }}"
146+
- name: Install Tencent Cloud CLI
147+
run: pipx install tccli
132148

133-
- name: Deploy to LA2
134-
run: |
135-
rsync -avz --delete public/ "${{ secrets.SSH_USER }}@${{ secrets.LA_2_HOST }}:${{ secrets.DEPLOY_PATH }}"
149+
- name: Purge production CDN cache
150+
run: tccli cdn PurgePathCache --Paths '["https://docs.pingcap.com/"]' --FlushType delete

.github/workflows/upload-test.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@ on:
66
jobs:
77
build:
88
runs-on: ubuntu-latest
9-
name: Build website
9+
name: Upload to COS
1010
steps:
1111
- uses: actions/checkout@v3
1212
with:
1313
ref: "master"
1414

15-
- name: Set known_hosts
16-
id: known-hosts
15+
- name: Install coscli
1716
run: |
18-
echo "BJ1=$(ssh-keyscan -H ${{ secrets.BJ_1_HOST }})" >> $GITHUB_OUTPUT
17+
wget https://cosbrowser.cloud.tencent.com/software/coscli/coscli-linux-amd64
18+
mv coscli-linux-amd64 coscli
19+
chmod 755 coscli
1920
20-
- name: Install SSH Key
21-
uses: shimataro/ssh-key-action@v2
22-
with:
23-
key: ${{ secrets.SSH_KEY }}
24-
known_hosts: |
25-
${{ steps.known-hosts.outputs.BJ1 }}
26-
27-
- name: Deploy to BJ1
21+
- name: Upload test file
2822
run: |
29-
rsync -avz --delete README.md "${{ secrets.SSH_USER }}@${{ secrets.BJ_1_HOST }}:${{ secrets.DEPLOY_PATH }}"
30-
23+
./coscli cp README.md cos://${{ secrets.TENCENTCLOUD_BUCKET_ID }}/README.md \
24+
--init-skip \
25+
--recursive \
26+
--secret-id ${{ secrets.TENCENTCLOUD_SECRET_ID }} \
27+
--secret-key ${{ secrets.TENCENTCLOUD_SECRET_KEY }} \
28+
--endpoint cos.na-ashburn.myqcloud.com

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require("ts-node").register({ transpileOnly: true });
33
const docs = require("./docs/docs.json");
44

55
module.exports = {
6+
trailingSlash: "always",
67
siteMetadata: {
78
title:
89
process.env.WEBSITE_BUILD_TYPE === "archive"

locale/en/translation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@
147147
"title": "Sorry, we can't find the page you were looking for.",
148148
"youMayWish": "You may wish to:",
149149
"goToDocHome": "Go to <0>Docs Home</0>",
150-
"searchDoc": "Search our current documentation"
150+
"searchDoc": "Search our current documentation",
151+
"archive": {
152+
"title": "You might be looking for archived documentation:",
153+
"redirect": "Redirecting in {{ seconds }} seconds..."
154+
}
151155
},
152156
"fab": {
153157
"scrollToTop": "Scroll to top",

locale/ja/translation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@
144144
"title": "お探しのページが見つかりません。",
145145
"youMayWish": "You may wish to:",
146146
"goToDocHome": "Go to <0>Docs Home</0>",
147-
"searchDoc": "Search our current documentation"
147+
"searchDoc": "Search our current documentation",
148+
"archive": {
149+
"title": "お探しのページはアーカイブされたドキュメントです。",
150+
"redirect": "{{ seconds }} 秒後にリダイレクトします..."
151+
}
148152
},
149153
"fab": {
150154
"scrollToTop": "トップへ戻る",

locale/zh/translation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@
144144
"title": "抱歉,您要找的页面走丢了…",
145145
"youMayWish": "您可以:",
146146
"goToDocHome": "去 <0>文档中心</0>",
147-
"searchDoc": "搜索文档"
147+
"searchDoc": "搜索文档",
148+
"archive": {
149+
"title": "您可能正在寻找归档文档:",
150+
"redirect": "将在 {{ seconds }} 秒后重定向..."
151+
}
148152
},
149153
"fab": {
150154
"scrollToTop": "回到顶部",

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"axios": "^0.24.0",
3232
"clsx": "^1.1.1",
3333
"copy-to-clipboard": "^3.3.1",
34-
"gatsby": "^4.4.0",
34+
"gatsby": "^4.13.0",
3535
"gatsby-plugin-google-analytics": "^4.12.1",
3636
"gatsby-plugin-google-tagmanager": "^4.12.1",
3737
"gatsby-plugin-material-ui": "^4.0.2",
@@ -86,6 +86,7 @@
8686
"husky": "^7.0.4",
8787
"is-ci": "^3.0.1",
8888
"lint-staged": "^12.1.2",
89+
"patch-package": "^8.0.0",
8990
"pegjs": "^0.10.0",
9091
"prettier": "2.5.1",
9192
"sass": "^1.45.0",
@@ -97,6 +98,7 @@
9798
],
9899
"license": "MIT",
99100
"scripts": {
101+
"postinstall": "patch-package",
100102
"start": "gatsby develop",
101103
"start:0.0.0.0": "gatsby develop -H 0.0.0.0",
102104
"build": "gatsby build",

patches/gatsby-link+4.25.0.patch

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/node_modules/gatsby-link/dist/index.modern.mjs b/node_modules/gatsby-link/dist/index.modern.mjs
2+
index d6061b8..056e3f5 100644
3+
--- a/node_modules/gatsby-link/dist/index.modern.mjs
4+
+++ b/node_modules/gatsby-link/dist/index.modern.mjs
5+
@@ -1,3 +1,3 @@
6+
"client export"
7+
-import t from"prop-types";import e from"react";import{resolve as n,Location as r,Link as o}from"@gatsbyjs/reach-router";import{applyTrailingSlashOption as s}from"gatsby-page-utils/apply-trailing-slash-option";function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function a(t){let e=t||"/",n="",r="";const o=e.indexOf("#");-1!==o&&(r=e.slice(o),e=e.slice(0,o));const s=e.indexOf("?");return-1!==s&&(n=e.slice(s),e=e.slice(0,s)),{pathname:e,search:"?"===n?"":n,hash:"#"===r?"":r}}const c=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,l=t=>{if("string"==typeof t)return!(t=>c.test(t))(t)},p=()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __PATH_PREFIX__?__PATH_PREFIX__:void 0:__PATH_PREFIX__;function h(t,e=(()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __BASE_PATH__?__BASE_PATH__:void 0:__BASE_PATH__)()){var n;if(!l(t))return t;if(t.startsWith("./")||t.startsWith("../"))return t;const r=null!=(n=null!=e?e:p())?n:"/";return`${null!=r&&r.endsWith("/")?r.slice(0,-1):r}${t.startsWith("/")?t:`/${t}`}`}const f=t=>null==t?void 0:t.startsWith("/"),u=()=>"undefined"!=typeof __TRAILING_SLASH__?__TRAILING_SLASH__:void 0,_=(t,e)=>"number"==typeof t?t:l(t)?f(t)?function(t){const e=h(t),n=u();if("always"===n||"never"===n){const{pathname:t,search:r,hash:o}=a(e);return`${s(t,n)}${r}${o}`}return e}(t):function(t,e){if(f(t))return t;const r=u(),o=n(t,e);return"always"===r||"never"===r?s(o,r):o}(t,e):t,d=["to","getProps","onClick","onMouseEnter","activeClassName","activeStyle","innerRef","partiallyActive","state","replace","_location"];function m(t){return h(t,p())}const y={activeClassName:t.string,activeStyle:t.object,partiallyActive:t.bool};function v(t){/*#__PURE__*/return e.createElement(r,null,({location:n})=>/*#__PURE__*/e.createElement(b,i({},t,{_location:n})))}class b extends e.Component{constructor(t){super(t),this.defaultGetProps=({isPartiallyCurrent:t,isCurrent:e})=>(this.props.partiallyActive?t:e)?{className:[this.props.className,this.props.activeClassName].filter(Boolean).join(" "),style:i({},this.props.style,this.props.activeStyle)}:null;let e=!1;"undefined"!=typeof window&&window.IntersectionObserver&&(e=!0),this.state={IOSupported:e},this.abortPrefetch=null,this.handleRef=this.handleRef.bind(this)}_prefetch(){let t=window.location.pathname+window.location.search;this.props._location&&this.props._location.pathname&&(t=this.props._location.pathname+this.props._location.search);const e=a(_(this.props.to,t)),n=e.pathname+e.search;if(t!==n)return ___loader.enqueue(n)}componentWillUnmount(){if(!this.io)return;const{instance:t,el:e}=this.io;this.abortPrefetch&&this.abortPrefetch.abort(),t.unobserve(e),t.disconnect()}handleRef(t){this.props.innerRef&&Object.prototype.hasOwnProperty.call(this.props.innerRef,"current")?this.props.innerRef.current=t:this.props.innerRef&&this.props.innerRef(t),this.state.IOSupported&&t&&(this.io=((t,e)=>{const n=new window.IntersectionObserver(n=>{n.forEach(n=>{t===n.target&&e(n.isIntersecting||n.intersectionRatio>0)})});return n.observe(t),{instance:n,el:t}})(t,t=>{t?this.abortPrefetch=this._prefetch():this.abortPrefetch&&this.abortPrefetch.abort()}))}render(){const t=this.props,{to:n,getProps:r=this.defaultGetProps,onClick:s,onMouseEnter:c,state:p,replace:h,_location:f}=t,u=function(t,e){if(null==t)return{};var n,r,o={},s=Object.keys(t);for(r=0;r<s.length;r++)e.indexOf(n=s[r])>=0||(o[n]=t[n]);return o}(t,d);"production"===process.env.NODE_ENV||l(n)||console.warn(`External link ${n} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`);const m=_(n,f.pathname);return l(m)?/*#__PURE__*/e.createElement(o,i({to:m,state:p,getProps:r,innerRef:this.handleRef,onMouseEnter:t=>{c&&c(t);const e=a(m);___loader.hovering(e.pathname+e.search)},onClick:t=>{if(s&&s(t),!(0!==t.button||this.props.target||t.defaultPrevented||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)){t.preventDefault();let e=h;const n=encodeURI(m)===f.pathname;"boolean"!=typeof h&&n&&(e=!0),window.___navigate(m,{state:p,replace:e})}return!0}},u)):/*#__PURE__*/e.createElement("a",i({href:m},u))}}b.propTypes=i({},y,{onClick:t.func,to:t.string.isRequired,replace:t.bool,state:t.object});var w=e.forwardRef((t,n)=>/*#__PURE__*/e.createElement(v,i({innerRef:n},t)));const P=(t,e)=>{window.___navigate(_(t,window.location.pathname),e)};export{w as default,P as navigate,a as parsePath,m as withAssetPrefix,h as withPrefix};
8+
+import t from"prop-types";import e from"react";import{resolve as n,Location as r,Link as o}from"@gatsbyjs/reach-router";import{applyTrailingSlashOption as s}from"gatsby-page-utils/apply-trailing-slash-option";function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i.apply(this,arguments)}function a(t){let e=t||"/",n="",r="";const o=e.indexOf("#");-1!==o&&(r=e.slice(o),e=e.slice(0,o));const s=e.indexOf("?");return-1!==s&&(n=e.slice(s),e=e.slice(0,s)),{pathname:e,search:"?"===n?"":n,hash:"#"===r?"":r}}const c=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,l=t=>{if("string"==typeof t)return!(t=>c.test(t))(t)},p=()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __PATH_PREFIX__?__PATH_PREFIX__:void 0:__PATH_PREFIX__;function h(t,e=(()=>"production"!==process.env.NODE_ENV?"undefined"!=typeof __BASE_PATH__?__BASE_PATH__:void 0:__BASE_PATH__)()){var n;if(!l(t))return t;if(t.startsWith("./")||t.startsWith("../"))return t;const r=null!=(n=null!=e?e:p())?n:"/";return`${null!=r&&r.endsWith("/")?r.slice(0,-1):r}${t.startsWith("/")?t:`/${t}`}`}const f=t=>null==t?void 0:t.startsWith("/"),u=()=>"undefined"!=typeof __TRAILING_SLASH__?__TRAILING_SLASH__:void 0,_=(t,e)=>"number"==typeof t?t:l(t)?f(t)?function(t){const e=h(t),n=u();if("always"===n||"never"===n){const{pathname:t,search:r,hash:o}=a(e);return`${s(t,n)}${r}${o}`}return e}(t):function(t,e){if(f(t))return t;const r=u(),o=n(t,e);const {pathname,search,hash}=a(o);return"always"===r||"never"===r?`${s(pathname,r)}${search}${hash}`:o}(t,e):t,d=["to","getProps","onClick","onMouseEnter","activeClassName","activeStyle","innerRef","partiallyActive","state","replace","_location"];function m(t){return h(t,p())}const y={activeClassName:t.string,activeStyle:t.object,partiallyActive:t.bool};function v(t){/*#__PURE__*/return e.createElement(r,null,({location:n})=>/*#__PURE__*/e.createElement(b,i({},t,{_location:n})))}class b extends e.Component{constructor(t){super(t),this.defaultGetProps=({isPartiallyCurrent:t,isCurrent:e})=>(this.props.partiallyActive?t:e)?{className:[this.props.className,this.props.activeClassName].filter(Boolean).join(" "),style:i({},this.props.style,this.props.activeStyle)}:null;let e=!1;"undefined"!=typeof window&&window.IntersectionObserver&&(e=!0),this.state={IOSupported:e},this.abortPrefetch=null,this.handleRef=this.handleRef.bind(this)}_prefetch(){let t=window.location.pathname+window.location.search;this.props._location&&this.props._location.pathname&&(t=this.props._location.pathname+this.props._location.search);const e=a(_(this.props.to,t)),n=e.pathname+e.search;if(t!==n)return ___loader.enqueue(n)}componentWillUnmount(){if(!this.io)return;const{instance:t,el:e}=this.io;this.abortPrefetch&&this.abortPrefetch.abort(),t.unobserve(e),t.disconnect()}handleRef(t){this.props.innerRef&&Object.prototype.hasOwnProperty.call(this.props.innerRef,"current")?this.props.innerRef.current=t:this.props.innerRef&&this.props.innerRef(t),this.state.IOSupported&&t&&(this.io=((t,e)=>{const n=new window.IntersectionObserver(n=>{n.forEach(n=>{t===n.target&&e(n.isIntersecting||n.intersectionRatio>0)})});return n.observe(t),{instance:n,el:t}})(t,t=>{t?this.abortPrefetch=this._prefetch():this.abortPrefetch&&this.abortPrefetch.abort()}))}render(){const t=this.props,{to:n,getProps:r=this.defaultGetProps,onClick:s,onMouseEnter:c,state:p,replace:h,_location:f}=t,u=function(t,e){if(null==t)return{};var n,r,o={},s=Object.keys(t);for(r=0;r<s.length;r++)e.indexOf(n=s[r])>=0||(o[n]=t[n]);return o}(t,d);"production"===process.env.NODE_ENV||l(n)||console.warn(`External link ${n} was detected in a Link component. Use the Link component only for internal links. See: https://gatsby.dev/internal-links`);const m=_(n,f.pathname);return l(m)?/*#__PURE__*/e.createElement(o,i({to:m,state:p,getProps:r,innerRef:this.handleRef,onMouseEnter:t=>{c&&c(t);const e=a(m);___loader.hovering(e.pathname+e.search)},onClick:t=>{if(s&&s(t),!(0!==t.button||this.props.target||t.defaultPrevented||t.metaKey||t.altKey||t.ctrlKey||t.shiftKey)){t.preventDefault();let e=h;const n=encodeURI(m)===f.pathname;"boolean"!=typeof h&&n&&(e=!0),window.___navigate(m,{state:p,replace:e})}return!0}},u)):/*#__PURE__*/e.createElement("a",i({href:m},u))}}b.propTypes=i({},y,{onClick:t.func,to:t.string.isRequired,replace:t.bool,state:t.object});var w=e.forwardRef((t,n)=>/*#__PURE__*/e.createElement(v,i({innerRef:n},t)));const P=(t,e)=>{window.___navigate(_(t,window.location.pathname),e)};export{w as default,P as navigate,a as parsePath,m as withAssetPrefix,h as withPrefix};
9+
//# sourceMappingURL=index.modern.mjs.map

0 commit comments

Comments
 (0)