This is an automated email from the ASF dual-hosted git repository. shuai pushed a commit to branch test in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit d0c1267b53db4ac6b75c9eedaff725e74e503058 Author: hgaol <[email protected]> AuthorDate: Fri Jul 12 16:40:29 2024 +0800 replace with front-matter --- ui/package.json | 3 +- ui/pnpm-lock.yaml | 65 +++++------------------------------- ui/src/index.tsx | 4 --- ui/src/pages/Questions/Ask/index.tsx | 17 +++++----- 4 files changed, 19 insertions(+), 70 deletions(-) diff --git a/ui/package.json b/ui/package.json index a918f027..19e66981 100644 --- a/ui/package.json +++ b/ui/package.json @@ -23,14 +23,13 @@ "axios": "^0.28.1", "bootstrap": "^5.3.2", "bootstrap-icons": "^1.10.5", - "buffer": "^6.0.3", "classnames": "^2.3.1", "codemirror": "^6.0.1", "color": "^4.2.3", "copy-to-clipboard": "^3.3.2", "dayjs": "^1.11.5", "diff": "^5.1.0", - "gray-matter": "^4.0.3", + "front-matter": "^4.0.2", "i18next": "^21.9.0", "lodash": "^4.17.21", "marked": "^4.0.19", diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml index 244d7ad2..b855bfa0 100644 --- a/ui/pnpm-lock.yaml +++ b/ui/pnpm-lock.yaml @@ -29,9 +29,6 @@ importers: bootstrap-icons: specifier: ^1.10.5 version: 1.10.5 - buffer: - specifier: ^6.0.3 - version: 6.0.3 classnames: specifier: ^2.3.1 version: 2.3.2 @@ -50,9 +47,9 @@ importers: diff: specifier: ^5.1.0 version: 5.1.0 - gray-matter: - specifier: ^4.0.3 - version: 4.0.3 + front-matter: + specifier: ^4.0.2 + version: 4.0.2 i18next: specifier: ^21.9.0 version: 21.9.2 @@ -4398,10 +4395,6 @@ packages: /[email protected]: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} - /[email protected]: - resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - dev: false - /[email protected]: resolution: {integrity: sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw==} @@ -4533,13 +4526,6 @@ packages: /[email protected]: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} - /[email protected]: - resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - dev: false - /[email protected]: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} @@ -6436,13 +6422,6 @@ packages: transitivePeerDependencies: - supports-color - /[email protected]: - resolution: {integrity: sha512-zCnTtlxNoAiDc3gqY2aYAWFx7XWWiasuF2K8Me5WbN8otHKTUKBwjPtNpRs/rbUZm7KxWAaNj7P1a/p52GbVug==} - engines: {node: '>=0.10.0'} - dependencies: - is-extendable: 0.1.1 - dev: false - /[email protected]: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -6648,6 +6627,12 @@ packages: resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==} engines: {node: '>= 0.6'} + /[email protected]: + resolution: {integrity: sha512-I8ZuJ/qG92NWX8i5x1Y8qyj3vizhXS31OxjKDu3LKP+7/qBgfIKValiZIEwoVoJKUHlhWtYrktkxV1XsX+pPlg==} + dependencies: + js-yaml: 3.14.1 + dev: false + /[email protected]: resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} engines: {node: '>=12'} @@ -6845,16 +6830,6 @@ packages: /[email protected]: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} - /[email protected]: - resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==} - engines: {node: '>=6.0'} - dependencies: - js-yaml: 3.14.1 - kind-of: 6.0.3 - section-matter: 1.0.0 - strip-bom-string: 1.0.0 - dev: false - /[email protected]: resolution: {integrity: sha512-ax7ZYomf6jqPTQ4+XCpUGyXKHk5WweS+e05MBO4/y3WJ5RkmPXNKvX+bx1behVILVwr6JSQvZAku021CHPXG3Q==} engines: {node: '>=10'} @@ -7115,10 +7090,6 @@ packages: dependencies: harmony-reflect: 1.6.2 - /[email protected]: - resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - dev: false - /[email protected]: resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} engines: {node: '>= 4'} @@ -7270,11 +7241,6 @@ packages: hasBin: true dev: true - /[email protected]: - resolution: {integrity: sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==} - engines: {node: '>=0.10.0'} - dev: false - /[email protected]: resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} engines: {node: '>=0.10.0'} @@ -10573,14 +10539,6 @@ packages: ajv-formats: 2.1.1([email protected]) ajv-keywords: 5.1.0([email protected]) - /[email protected]: - resolution: {integrity: sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==} - engines: {node: '>=4'} - dependencies: - extend-shallow: 2.0.1 - kind-of: 6.0.3 - dev: false - /[email protected]: resolution: {integrity: sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==} @@ -11050,11 +11008,6 @@ packages: dependencies: ansi-regex: 6.0.1 - /[email protected]: - resolution: {integrity: sha512-uCC2VHvQRYu+lMh4My/sFNmF2klFymLX1wHJeXnbEJERpV/ZsVuonzerjfrGpIGF7LBVa1O7i9kjiWvJiFck8g==} - engines: {node: '>=0.10.0'} - dev: false - /[email protected]: resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==} engines: {node: '>=4'} diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 174677cb..e2930c08 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -17,8 +17,6 @@ * under the License. */ -import { Buffer } from 'buffer'; - import React from 'react'; import ReactDOM from 'react-dom/client'; @@ -31,8 +29,6 @@ const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement, ); -window.Buffer = window.Buffer || Buffer; - /** * Uniformly hide broken images * - The `onload` event for elements such as `img` can only be `capture` on `document` (window cannot). diff --git a/ui/src/pages/Questions/Ask/index.tsx b/ui/src/pages/Questions/Ask/index.tsx index ef4b3d63..30398f2f 100644 --- a/ui/src/pages/Questions/Ask/index.tsx +++ b/ui/src/pages/Questions/Ask/index.tsx @@ -26,7 +26,7 @@ import dayjs from 'dayjs'; import classNames from 'classnames'; import isEqual from 'lodash/isEqual'; import debounce from 'lodash/debounce'; -import matter from 'gray-matter'; +import fm from 'front-matter'; import { usePageTags, usePromptWithUnload } from '@/hooks'; import { Editor, EditorRef, TagSelector } from '@/components'; @@ -144,20 +144,21 @@ const Ask = () => { const prefill = searchParams.get('prefill'); if (prefill || draft) { if (prefill) { - const file = matter(decodeURIComponent(prefill)); - formData.title.value = file.data?.title; - formData.content.value = file.content; - if (!queryTags && file.data?.tags) { - updateTags(file.data.tags); + const file = fm<any>(decodeURIComponent(prefill)); + formData.title.value = file.attributes?.title; + formData.content.value = file.body; + if (!queryTags && file.attributes?.tags) { + updateTags(file.attributes.tags); } } else if (draft) { formData.title.value = draft.title; formData.content.value = draft.content; formData.tags.value = draft.tags; formData.answer_content.value = draft.answer_content; + setCheckState(Boolean(draft.answer_content)); + setHasDraft(true); } - setCheckState(Boolean(draft.answer_content)); - setHasDraft(true); + setFormData({ ...formData }); } else { resetForm();
