diff --git a/package.json b/package.json index b3dbf84..712671a 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "classnames": "^2.3.1", "cross-fetch": "^3.1.4", "gatsby-plugin-google-gtag": "^4.23.0", + "json-url": "^3.0.0", "lodash-es": "^4.17.21", "query-string": "^7.1.1", "react": "^17.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27b77f2..4460d01 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,7 @@ specifiers: gatsby-plugin-pnpm: ^1.2.10 gh-pages: ^3.1.0 husky: ^7.0.4 + json-url: ^3.0.0 less: ^4.1.0 lint-staged: ^12.3.5 lodash-es: ^4.17.21 @@ -41,6 +42,7 @@ dependencies: classnames: 2.3.1 cross-fetch: 3.1.5 gatsby-plugin-google-gtag: 4.24.0_67zqrbeeco77wy6p2csmn6n6uq + json-url: 3.0.0 lodash-es: 4.17.21 query-string: 7.1.1 react: 17.0.2 @@ -1293,6 +1295,14 @@ packages: transitivePeerDependencies: - supports-color + /@babel/runtime-corejs2/7.21.0: + resolution: {integrity: sha512-hVFDLYkuthnvQwWoOniPSq+RWyQTiimVdMXQJujoiSX8maFh/62+qRImGkRpeRflsVXXSMFS4HgNe3X9fuw5ww==} + engines: {node: '>=6.9.0'} + dependencies: + core-js: 2.6.12 + regenerator-runtime: 0.13.11 + dev: false + /@babel/runtime-corejs3/7.18.6: resolution: {integrity: sha512-cOu5wH2JFBgMjje+a+fz2JNIWU4GzYpl05oSob3UDvBEh6EuIn+TXFHMmBbhSb+k/4HMzgKCQfEEDArAWNF9Cw==} engines: {node: '>=6.9.0'} @@ -2727,6 +2737,7 @@ packages: dependencies: '@babel/core': 7.18.6 '@babel/runtime': 7.18.6 + '@babel/types': 7.18.7 gatsby: 2.32.13_fjtp7haypwd3jrz2anmo67qyu4 gatsby-core-utils: 2.14.0 @@ -2828,6 +2839,13 @@ packages: file-uri-to-path: 1.0.0 optional: true + /bl/2.2.1: + resolution: {integrity: sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==} + dependencies: + readable-stream: 2.3.7 + safe-buffer: 5.2.1 + dev: false + /bl/4.1.0: resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==} dependencies: @@ -3708,6 +3726,12 @@ packages: resolution: {integrity: sha512-XpoouuqIj4P+GWtdyV8ZO3/u4KftkeDVMfvp+308eGMhCrA3lVDSmAxO0c6GGOcmgVlaKDrgWVMo49h2ab/TDA==} requiresBuild: true + /core-js/2.6.12: + resolution: {integrity: sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==} + deprecated: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. + requiresBuild: true + dev: false + /core-js/3.23.3: resolution: {integrity: sha512-oAKwkj9xcWNBAvGbT//WiCdOMpb9XQG92/Fe3ABFM/R16BsHgePG00mFOgKf7IsCtfj8tA1kHtf/VwErhriz5Q==} requiresBuild: true @@ -5793,6 +5817,7 @@ packages: '@sindresorhus/slugify': 1.1.2 chokidar: 3.5.3 fs-exists-cached: 1.0.0 + fs-extra: 10.1.0 gatsby: 2.32.13_fjtp7haypwd3jrz2anmo67qyu4 gatsby-page-utils: 0.9.1 gatsby-telemetry: 1.10.2 @@ -5827,14 +5852,17 @@ packages: - gatsby - supports-color - /gatsby-plugin-utils/0.9.0_gatsby@2.32.13: + /gatsby-plugin-utils/0.9.0_l34axf24tmuqkyzdcphnvjynwe: resolution: {integrity: sha512-InM8PNHtx1kF87qQOlf4pVeNA8lSIsvSjImvN6dvpUjeQqOMRN1avY0W9Trh6LKTF/keWWj975Gk8Vcr+PYyDA==} engines: {node: '>=10.13.0'} peerDependencies: gatsby: ^2.24.79 + graphql: ^15.0.0 dependencies: '@babel/runtime': 7.18.6 + fastq: 1.13.0 gatsby: 2.32.13_fjtp7haypwd3jrz2anmo67qyu4 + graphql: 14.7.0 joi: 17.6.0 /gatsby-react-router-scroll/3.7.0_pwckoet67ool4kozvfcfu7xmha: @@ -6026,7 +6054,7 @@ packages: gatsby-link: 2.11.0_pwckoet67ool4kozvfcfu7xmha gatsby-plugin-page-creator: 2.10.2_gatsby@2.32.13 gatsby-plugin-typescript: 2.12.1_gatsby@2.32.13 - gatsby-plugin-utils: 0.9.0_gatsby@2.32.13 + gatsby-plugin-utils: 0.9.0_l34axf24tmuqkyzdcphnvjynwe gatsby-react-router-scroll: 3.7.0_pwckoet67ool4kozvfcfu7xmha gatsby-telemetry: 1.10.2 glob: 7.2.3 @@ -7466,6 +7494,18 @@ packages: /json-stringify-safe/5.0.1: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} + /json-url/3.0.0: + resolution: {integrity: sha512-c5iQnrKGNJ4/qAV1APNFHBDSgB0qgekmcVTBV3RRa2UUw8liUIrUvI3+Om7qtnM8JwobnEsPuAWMYmtCfxSkcw==} + dependencies: + '@babel/runtime-corejs2': 7.21.0 + bluebird: 3.7.2 + lz-string: 1.4.4 + lzma: 2.3.2 + msgpack5: 4.5.1 + node-lzw: 0.3.1 + urlsafe-base64: 1.0.0 + dev: false + /json2mq/0.2.0: resolution: {integrity: sha512-SzoRg7ux5DWTII9J2qkrZrqV1gt+rTaoufMxEzXbS26Uid0NwaJd123HcoB80TgubEppxxIGdNxCx50fEoEWQA==} dependencies: @@ -7852,6 +7892,16 @@ packages: dependencies: es5-ext: 0.10.61 + /lz-string/1.4.4: + resolution: {integrity: sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==} + hasBin: true + dev: false + + /lzma/2.3.2: + resolution: {integrity: sha512-DcfiawQ1avYbW+hsILhF38IKAlnguc/fjHrychs9hdxe4qLykvhT5VTGNs5YRWgaNePh7NTxGD4uv4gKsRomCQ==} + hasBin: true + dev: false + /make-dir/2.1.0: resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==} engines: {node: '>=6'} @@ -8496,6 +8546,15 @@ packages: /ms/2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + /msgpack5/4.5.1: + resolution: {integrity: sha512-zC1vkcliryc4JGlL6OfpHumSYUHWFGimSI+OgfRCjTFLmKA2/foR9rMTOhWiqfOrfxJOctrpWPvrppf8XynJxw==} + dependencies: + bl: 2.2.1 + inherits: 2.0.4 + readable-stream: 2.3.7 + safe-buffer: 5.2.1 + dev: false + /multicast-dns-service-types/1.1.0: resolution: {integrity: sha512-cnAsSVxIDsYt0v7HmC0hWZFwwXSh+E6PgCrREDuN/EsjgLwA5XRmlMHhSiDPrt6HxY1gTivEa/Zh7GtODoLevQ==} @@ -8651,6 +8710,11 @@ packages: util: 0.11.1 vm-browserify: 1.1.2 + /node-lzw/0.3.1: + resolution: {integrity: sha512-BGjQRR92HJsEsm1Ebp3Qvn2Jq+tlXEGY8zorNdal+FxOWpLMyyZBHoQWeyOc/TxsCzCvGbcCG4mU0u/RBSWxjQ==} + hasBin: true + dev: false + /node-object-hash/2.3.10: resolution: {integrity: sha512-jY5dPJzw6NHd/KPSfPKJ+IHoFS81/tJ43r34ZeNMXGzCOM8jwQDCD12HYayKIB6MuznrnqIYy2e891NA2g0ibA==} engines: {node: '>=0.10.0'} @@ -10600,6 +10664,10 @@ packages: /regenerate/1.4.2: resolution: {integrity: sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==} + /regenerator-runtime/0.13.11: + resolution: {integrity: sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==} + dev: false + /regenerator-runtime/0.13.9: resolution: {integrity: sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==} @@ -12357,6 +12425,10 @@ packages: punycode: 1.3.2 querystring: 0.2.0 + /urlsafe-base64/1.0.0: + resolution: {integrity: sha512-RtuPeMy7c1UrHwproMZN9gN6kiZ0SvJwRaEzwZY0j9MypEkFqyBaKv176jvlPtg58Zh36bOkS0NFABXMHvvGCA==} + dev: false + /use/3.1.1: resolution: {integrity: sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==} engines: {node: '>=0.10.0'} diff --git a/src/components/index.tsx b/src/components/index.tsx index 09e3ab5..87e7314 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -3,6 +3,7 @@ import { Button, Affix, Upload, Spin, message, Alert, Modal } from 'antd'; import type { RcFile } from 'antd/lib/upload'; import _ from 'lodash-es'; import qs from 'query-string'; +import jsonUrl from 'json-url'; import { getLanguage, getLocale } from '@/locale'; import { useModeSwitcher } from '@/hooks/useModeSwitcher'; import { getDefaultTitleNameMap } from '@/datas/constant'; @@ -18,6 +19,8 @@ import { Resume } from './Resume'; import type { ResumeConfig, ThemeConfig } from './types'; import './index.less'; +const codec = jsonUrl('lzma'); + export const Page: React.FC = () => { const lang = getLanguage(); const i18n = getLocale(); @@ -47,7 +50,6 @@ export const Page: React.FC = () => { template: config?.template || 'template1', ...qs.parse(currentSearch), }); - window.location.href = `${pathname}?${search}${hash}`; } }, [config]); @@ -108,9 +110,17 @@ export const Page: React.FC = () => { }); }); } else { - getConfig(lang, branch, user).then(data => store(data)); + if (query.data) { + codec.decompress(query.data).then(data => { + store(JSON.parse(data)); + }); + } else { + getConfig(lang, branch, user).then(data => { + store(data); + }); + } } - }, [lang, query.user, query.branch]); + }, [lang, query.user, query.branch, query.data]); const onConfigChange = useCallback( (v: Partial) => { @@ -203,6 +213,17 @@ export const Page: React.FC = () => { exportDataToLocal(getConfigJson(), `${user}'s resume info`); }; + const handleSharing = () => { + const fullConfig = getConfigJson(); + codec.compress(fullConfig).then(data => { + const url = new URL(window.location.href); + url.searchParams.set('data', data); + + console.log('sharing url', url.toString()); + copyToClipboard(url.toString()); + }); + }; + return ( @@ -278,6 +299,9 @@ export const Page: React.FC = () => { +