diff --git a/custom.d.ts b/custom.d.ts new file mode 100644 index 00000000..8e49c0d7 --- /dev/null +++ b/custom.d.ts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +declare module "markdown-to-notion" \ No newline at end of file diff --git a/package.json b/package.json index 177e974e..a9f4ce21 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "@terwer/esbuild-config-custom": "^1.0.12", "@terwer/eslint-config-custom": "^1.3.6", - "@types/node": "^18.17.2", + "@types/node": "^18.17.3", "@vitejs/plugin-vue": "^4.2.3", "esbuild-plugin-copy": "^2.1.1", "esbuild-style-plugin": "^1.6.2", @@ -60,13 +60,14 @@ "vue-i18n": "^9.2.2", "vue-router": "^4.2.4", "xmlbuilder2": "^3.1.1", - "zhi-blog-api": "^1.20.10", + "zhi-blog-api": "^1.20.11", "zhi-common": "^1.11.8", "zhi-device": "^2.3.0", "zhi-fetch-middleware": "^0.2.8", "zhi-github-middleware": "^0.1.5", "zhi-lib-base": "^0.4.4", - "zhi-siyuan-api": "^1.29.11", + "zhi-notion-markdown": "^0.1.1", + "zhi-siyuan-api": "^1.29.13", "zhi-xmlrpc-middleware": "^0.4.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de0d89d1..d039ae30 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,8 +51,8 @@ dependencies: specifier: ^3.1.1 version: 3.1.1 zhi-blog-api: - specifier: ^1.20.10 - version: 1.20.10 + specifier: ^1.20.11 + version: 1.20.11 zhi-common: specifier: ^1.11.8 version: 1.11.8 @@ -68,9 +68,12 @@ dependencies: zhi-lib-base: specifier: ^0.4.4 version: 0.4.4 + zhi-notion-markdown: + specifier: ^0.1.1 + version: 0.1.1 zhi-siyuan-api: - specifier: ^1.29.11 - version: 1.29.11 + specifier: ^1.29.13 + version: 1.29.13 zhi-xmlrpc-middleware: specifier: ^0.4.3 version: 0.4.3 @@ -83,8 +86,8 @@ devDependencies: specifier: ^1.3.6 version: 1.3.6(@nuxt/eslint-config@0.1.1)(@typescript-eslint/eslint-plugin@5.62.0)(astro-eslint-parser@0.13.3)(eslint-config-prettier@8.10.0)(eslint-config-turbo@1.10.12)(eslint-plugin-prettier@4.2.1)(eslint-plugin-svelte@2.32.4)(eslint-plugin-vue@9.16.1)(eslint@8.46.0)(prettier-plugin-svelte@2.10.1)(prettier@2.8.8)(typescript@5.1.6) '@types/node': - specifier: ^18.17.2 - version: 18.17.2 + specifier: ^18.17.3 + version: 18.17.3 '@vitejs/plugin-vue': specifier: ^4.2.3 version: 4.2.3(vite@4.4.8)(vue@3.3.4) @@ -120,7 +123,7 @@ devDependencies: version: 31.2.2 vite: specifier: ^4.4.8 - version: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) + version: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) vite-plugin-html: specifier: ^3.2.0 version: 3.2.0(vite@4.4.8) @@ -876,6 +879,16 @@ packages: fastq: 1.15.0 dev: true + /@notionhq/client@1.0.4: + resolution: {integrity: sha512-m7zZ5l3RUktayf1lRBV1XMb8HSKsmWTv/LZPqP7UGC1NMzOlc+bbTOPNQ4CP/c1P4cP61VWLb/zBq7a3c0nMaw==} + engines: {node: '>=12'} + dependencies: + '@types/node-fetch': 2.6.4 + node-fetch: 2.6.12 + transitivePeerDependencies: + - encoding + dev: false + /@nuxt/eslint-config@0.1.1(eslint@8.46.0): resolution: {integrity: sha512-znm1xlbhldUubB2XGx6Ca5uarwlIieKf0o8CtxtF6eEauDbpa3T2p3JnTcdguMW2nj1YPneoGmhshANfOlghiQ==} peerDependencies: @@ -1118,6 +1131,20 @@ packages: typescript: 5.1.6 dev: true + /@tryfabric/martian@1.2.4: + resolution: {integrity: sha512-g7SP7beaxrjxLnW//vskra07a1jsJowqp07KMouxh4gCwaF+ItHbRZN8O+1dhJivBi3VdasT71BPyk+8wzEreQ==} + engines: {node: '>=15'} + dependencies: + '@notionhq/client': 1.0.4 + remark-gfm: 1.0.0 + remark-math: 4.0.0 + remark-parse: 9.0.0 + unified: 9.2.2 + transitivePeerDependencies: + - encoding + - supports-color + dev: false + /@ts-morph/common@0.11.1: resolution: {integrity: sha512-7hWZS0NRpEsNV8vWJzg7FEz6V8MaLNeJOmwmghqUXTpzk16V1LLZhdo+4QvE/+zv4cVci0OviuJFnqhEfoV3+g==} dependencies: @@ -1175,6 +1202,12 @@ packages: resolution: {integrity: sha512-22y3o88f4a94mKljsZcanlNWPzO0uBsBdzLAngf2tp533LzZcQzb6+eZPJ+vCTt+bqF2XnvT9gejTLsAcJAJyQ==} dev: false + /@types/mdast@3.0.12: + resolution: {integrity: sha512-DT+iNIRNX884cx0/Q1ja7NyUPpZuv0KPyL5rGNxm1WC1OtHstl7n4Jb7nk+xacNShQMbczJjt8uFzznpp6kYBg==} + dependencies: + '@types/unist': 2.0.7 + dev: false + /@types/minimist@1.2.2: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true @@ -1182,17 +1215,23 @@ packages: /@types/node-fetch@2.6.3: resolution: {integrity: sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 form-data: 3.0.1 dev: true + /@types/node-fetch@2.6.4: + resolution: {integrity: sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==} + dependencies: + '@types/node': 18.17.3 + form-data: 3.0.1 + dev: false + /@types/node@14.18.33: resolution: {integrity: sha512-qelS/Ra6sacc4loe/3MSjXNL1dNQ/GjxNHVzuChwMfmk7HuycRLVQN2qNY3XahK+fZc5E2szqQSKUyAF0E+2bg==} dev: true - /@types/node@18.17.2: - resolution: {integrity: sha512-wBo3KqP/PBqje5TI9UTiuL3yWfP6sdPtjtygSOqcYZWT232dfDeDOnkDps5wqZBP9NgGgYrNejinl0faAuE+HQ==} - dev: true + /@types/node@18.17.3: + resolution: {integrity: sha512-2x8HWtFk0S99zqVQABU9wTpr8wPoaDHZUcAkoTKH+nL7kPv3WUI9cRi/Kk5Mz4xdqXSqTkKP7IWNoQQYCnDsTA==} /@types/sass@1.45.0: resolution: {integrity: sha512-jn7qwGFmJHwUSphV8zZneO3GmtlgLsmhs/LQyVvQbIIa+fzGMUiHI4HXJZL3FT8MJmgXWbLGiVVY7ElvHq6vDA==} @@ -1208,9 +1247,13 @@ packages: /@types/stylus@0.48.38: resolution: {integrity: sha512-B5otJekvD6XM8iTrnO6e2twoTY2tKL9VkL/57/2Lo4tv3EatbCaufdi68VVtn/h4yjO+HVvYEyrNQd0Lzj6riw==} dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 dev: true + /@types/unist@2.0.7: + resolution: {integrity: sha512-cputDpIbFgLUaGQn6Vqg3/YsJwxUwHLO13v3i5ouxT4lat0khip9AEWxtERujXV9wxIB1EyF97BSJFt6vpdI8g==} + dev: false + /@types/web-bluetooth@0.0.16: resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==} dev: false @@ -1615,7 +1658,7 @@ packages: vite: ^4.0.0 vue: ^3.2.25 dependencies: - vite: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) + vite: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) vue: 3.3.4 dev: true @@ -2031,7 +2074,6 @@ packages: /asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - dev: true /available-typed-arrays@1.0.5: resolution: {integrity: sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==} @@ -2044,6 +2086,10 @@ packages: dequal: 2.0.3 dev: true + /bail@1.0.5: + resolution: {integrity: sha512-xFbRxM1tahm08yHBP16MMjVUAvDaBMD38zsM9EMAUN61omwLmKlOpB/Zku5QkjZ8TZ4vn53pj+t518cH0S03RQ==} + dev: false + /balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true @@ -2240,6 +2286,10 @@ packages: tslib: 2.6.1 dev: true + /ccount@1.1.0: + resolution: {integrity: sha512-vlNK021QdI7PNeiUh/lKkC/mNHHfV0m/Ad5JoI0TYtlBnJAslM/JIkm/tGC88bkLIwO6OQ5uV6ztS6kVAtCDlg==} + dev: false + /chai@4.3.7: resolution: {integrity: sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==} engines: {node: '>=4'} @@ -2261,6 +2311,18 @@ packages: supports-color: 7.2.0 dev: true + /character-entities-legacy@1.1.4: + resolution: {integrity: sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA==} + dev: false + + /character-entities@1.2.4: + resolution: {integrity: sha512-iBMyeEHxfVnIakwOuDXpVkc54HijNgCyQB2w0VfGQThle6NXn50zU6V/u+LDhxHcDUPojn6Kpga3PTAD8W1bQw==} + dev: false + + /character-reference-invalid@1.1.4: + resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==} + dev: false + /check-error@1.0.2: resolution: {integrity: sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==} dev: true @@ -2338,11 +2400,9 @@ packages: engines: {node: '>= 0.8'} dependencies: delayed-stream: 1.0.0 - dev: true /commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} - dev: true /commander@4.1.1: resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} @@ -2504,7 +2564,6 @@ packages: optional: true dependencies: ms: 2.1.2 - dev: true /deep-eql@4.1.3: resolution: {integrity: sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==} @@ -2551,7 +2610,6 @@ packages: /delayed-stream@1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} - dev: true /delegates@1.0.0: resolution: {integrity: sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==} @@ -3301,7 +3359,6 @@ packages: /escape-string-regexp@4.0.0: resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==} engines: {node: '>=10'} - dev: true /escape-string-regexp@5.0.0: resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==} @@ -3570,6 +3627,10 @@ packages: engines: {node: '>=6'} dev: true + /extend@3.0.2: + resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + dev: false + /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} dev: true @@ -3669,7 +3730,6 @@ packages: asynckit: 0.4.0 combined-stream: 1.0.8 mime-types: 2.1.35 - dev: true /fs-extra@10.1.0: resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==} @@ -3994,6 +4054,17 @@ packages: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} dev: true + /is-alphabetical@1.0.4: + resolution: {integrity: sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg==} + dev: false + + /is-alphanumerical@1.0.4: + resolution: {integrity: sha512-UzoZUr+XfVz3t3v4KyGEniVL9BDRoQtY7tOyrRybkVNjDFWyo1yhXNGrrBTQxp3ib9BLAWs7k2YKBQsFRkZG9A==} + dependencies: + is-alphabetical: 1.0.4 + is-decimal: 1.0.4 + dev: false + /is-arguments@1.1.1: resolution: {integrity: sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==} engines: {node: '>= 0.4'} @@ -4009,6 +4080,11 @@ packages: binary-extensions: 2.2.0 dev: true + /is-buffer@2.0.5: + resolution: {integrity: sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==} + engines: {node: '>=4'} + dev: false + /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} @@ -4020,6 +4096,10 @@ packages: has: 1.0.3 dev: true + /is-decimal@1.0.4: + resolution: {integrity: sha512-RGdriMmQQvZ2aqaQq3awNA6dCGtKpiDFcOzrTWrDAT2MiWrKQVPmxLGHl7Y2nNu6led0kEyoX0enY0qXYsv9zw==} + dev: false + /is-docker@2.2.1: resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} engines: {node: '>=8'} @@ -4056,6 +4136,10 @@ packages: is-extglob: 2.1.1 dev: true + /is-hexadecimal@1.0.4: + resolution: {integrity: sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==} + dev: false + /is-inside-container@1.0.0: resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==} engines: {node: '>=14.16'} @@ -4082,6 +4166,11 @@ packages: engines: {node: '>=8'} dev: true + /is-plain-obj@2.1.0: + resolution: {integrity: sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==} + engines: {node: '>=8'} + dev: false + /is-plain-object@5.0.0: resolution: {integrity: sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==} engines: {node: '>=0.10.0'} @@ -4206,6 +4295,13 @@ packages: graceful-fs: 4.2.11 dev: true + /katex@0.12.0: + resolution: {integrity: sha512-y+8btoc/CK70XqcHqjxiGWBOeIL8upbS0peTPXTvgrh21n1RiWWcIpSWM+4uXq+IAgNh9YYQWdc7LVDPDAEEAg==} + hasBin: true + dependencies: + commander: 2.20.3 + dev: false + /known-css-properties@0.28.0: resolution: {integrity: sha512-9pSL5XB4J+ifHP0e0jmmC98OGC1nL8/JjS+fi6mnTlIf//yt/MfVLtKg7S6nCtj/8KTcWX7nRlY0XywoYY1ISQ==} dev: true @@ -4302,6 +4398,10 @@ packages: /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + /longest-streak@2.0.4: + resolution: {integrity: sha512-vM6rUVCVUJJt33bnmHiZEvr7wPT78ztX7rojL+LW51bHtLh6HTjx84LA5W4+oa6aKEJA7jJu5LR6vQRBpA5DVg==} + dev: false + /loupe@2.3.6: resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} dependencies: @@ -4350,6 +4450,12 @@ packages: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} dev: true + /markdown-table@2.0.0: + resolution: {integrity: sha512-Ezda85ToJUBhM6WGaG6veasyym+Tbs3cMAw/ZhOPqXiYsr0jgocBV3j3nx+4lk47plLlIqjwuTm/ywVI+zjJ/A==} + dependencies: + repeat-string: 1.6.1 + dev: false + /md5.js@1.3.5: resolution: {integrity: sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==} dependencies: @@ -4358,6 +4464,90 @@ packages: safe-buffer: 5.2.1 dev: true + /mdast-util-find-and-replace@1.1.1: + resolution: {integrity: sha512-9cKl33Y21lyckGzpSmEQnIDjEfeeWelN5s1kUW1LwdB0Fkuq2u+4GdqcGEygYxJE8GVqCl0741bYXHgamfWAZA==} + dependencies: + escape-string-regexp: 4.0.0 + unist-util-is: 4.1.0 + unist-util-visit-parents: 3.1.1 + dev: false + + /mdast-util-from-markdown@0.8.5: + resolution: {integrity: sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==} + dependencies: + '@types/mdast': 3.0.12 + mdast-util-to-string: 2.0.0 + micromark: 2.11.4 + parse-entities: 2.0.0 + unist-util-stringify-position: 2.0.3 + transitivePeerDependencies: + - supports-color + dev: false + + /mdast-util-gfm-autolink-literal@0.1.3: + resolution: {integrity: sha512-GjmLjWrXg1wqMIO9+ZsRik/s7PLwTaeCHVB7vRxUwLntZc8mzmTsLVr6HW1yLokcnhfURsn5zmSVdi3/xWWu1A==} + dependencies: + ccount: 1.1.0 + mdast-util-find-and-replace: 1.1.1 + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /mdast-util-gfm-strikethrough@0.2.3: + resolution: {integrity: sha512-5OQLXpt6qdbttcDG/UxYY7Yjj3e8P7X16LzvpX8pIQPYJ/C2Z1qFGMmcw+1PZMUM3Z8wt8NRfYTvCni93mgsgA==} + dependencies: + mdast-util-to-markdown: 0.6.5 + dev: false + + /mdast-util-gfm-table@0.1.6: + resolution: {integrity: sha512-j4yDxQ66AJSBwGkbpFEp9uG/LS1tZV3P33fN1gkyRB2LoRL+RR3f76m0HPHaby6F4Z5xr9Fv1URmATlRRUIpRQ==} + dependencies: + markdown-table: 2.0.0 + mdast-util-to-markdown: 0.6.5 + dev: false + + /mdast-util-gfm-task-list-item@0.1.6: + resolution: {integrity: sha512-/d51FFIfPsSmCIRNp7E6pozM9z1GYPIkSy1urQ8s/o4TC22BZ7DqfHFWiqBD23bc7J3vV1Fc9O4QIHBlfuit8A==} + dependencies: + mdast-util-to-markdown: 0.6.5 + dev: false + + /mdast-util-gfm@0.1.2: + resolution: {integrity: sha512-NNkhDx/qYcuOWB7xHUGWZYVXvjPFFd6afg6/e2g+SV4r9q5XUcCbV4Wfa3DLYIiD+xAEZc6K4MGaE/m0KDcPwQ==} + dependencies: + mdast-util-gfm-autolink-literal: 0.1.3 + mdast-util-gfm-strikethrough: 0.2.3 + mdast-util-gfm-table: 0.1.6 + mdast-util-gfm-task-list-item: 0.1.6 + mdast-util-to-markdown: 0.6.5 + transitivePeerDependencies: + - supports-color + dev: false + + /mdast-util-math@0.1.2: + resolution: {integrity: sha512-fogAitds+wH+QRas78Yr1TwmQGN4cW/G2WRw5ePuNoJbBSPJCxIOCE8MTzHgWHVSpgkRaPQTgfzXRE1CrwWSlg==} + dependencies: + longest-streak: 2.0.4 + mdast-util-to-markdown: 0.6.5 + repeat-string: 1.6.1 + dev: false + + /mdast-util-to-markdown@0.6.5: + resolution: {integrity: sha512-XeV9sDE7ZlOQvs45C9UKMtfTcctcaj/pGwH8YLbMHoMOXNNCn2LsqVQOqrF1+/NU8lKDAqozme9SCXWyo9oAcQ==} + dependencies: + '@types/unist': 2.0.7 + longest-streak: 2.0.4 + mdast-util-to-string: 2.0.0 + parse-entities: 2.0.0 + repeat-string: 1.6.1 + zwitch: 1.0.5 + dev: false + + /mdast-util-to-string@2.0.0: + resolution: {integrity: sha512-AW4DRS3QbBayY/jJmD8437V1Gombjf8RSOUCMFBuo5iHi58AGEgVCKQ+ezHkZZDpAQS75hcBMpLqjpJTjtUL7w==} + dev: false + /mdn-data@2.0.30: resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} dev: true @@ -4375,6 +4565,73 @@ packages: engines: {node: '>= 8'} dev: true + /micromark-extension-gfm-autolink-literal@0.5.7: + resolution: {integrity: sha512-ePiDGH0/lhcngCe8FtH4ARFoxKTUelMp4L7Gg2pujYD5CSMb9PbblnyL+AAMud/SNMyusbS2XDSiPIRcQoNFAw==} + dependencies: + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark-extension-gfm-strikethrough@0.6.5: + resolution: {integrity: sha512-PpOKlgokpQRwUesRwWEp+fHjGGkZEejj83k9gU5iXCbDG+XBA92BqnRKYJdfqfkrRcZRgGuPuXb7DaK/DmxOhw==} + dependencies: + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark-extension-gfm-table@0.4.3: + resolution: {integrity: sha512-hVGvESPq0fk6ALWtomcwmgLvH8ZSVpcPjzi0AjPclB9FsVRgMtGZkUcpE0zgjOCFAznKepF4z3hX8z6e3HODdA==} + dependencies: + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark-extension-gfm-tagfilter@0.3.0: + resolution: {integrity: sha512-9GU0xBatryXifL//FJH+tAZ6i240xQuFrSL7mYi8f4oZSbc+NvXjkrHemeYP0+L4ZUT+Ptz3b95zhUZnMtoi/Q==} + dev: false + + /micromark-extension-gfm-task-list-item@0.3.3: + resolution: {integrity: sha512-0zvM5iSLKrc/NQl84pZSjGo66aTGd57C1idmlWmE87lkMcXrTxg1uXa/nXomxJytoje9trP0NDLvw4bZ/Z/XCQ==} + dependencies: + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark-extension-gfm@0.3.3: + resolution: {integrity: sha512-oVN4zv5/tAIA+l3GbMi7lWeYpJ14oQyJ3uEim20ktYFAcfX1x3LNlFGGlmrZHt7u9YlKExmyJdDGaTt6cMSR/A==} + dependencies: + micromark: 2.11.4 + micromark-extension-gfm-autolink-literal: 0.5.7 + micromark-extension-gfm-strikethrough: 0.6.5 + micromark-extension-gfm-table: 0.4.3 + micromark-extension-gfm-tagfilter: 0.3.0 + micromark-extension-gfm-task-list-item: 0.3.3 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark-extension-math@0.1.2: + resolution: {integrity: sha512-ZJXsT2eVPM8VTmcw0CPSDeyonOn9SziGK3Z+nkf9Vb6xMPeU+4JMEnO6vzDL10562Favw8Vste74f54rxJ/i6Q==} + dependencies: + katex: 0.12.0 + micromark: 2.11.4 + transitivePeerDependencies: + - supports-color + dev: false + + /micromark@2.11.4: + resolution: {integrity: sha512-+WoovN/ppKolQOFIAajxi7Lu9kInbPxFuTBVEavFcL8eAfVstoc5MocPmqBeAdBOJV00uaVjegzH4+MA0DN/uA==} + dependencies: + debug: 4.3.4 + parse-entities: 2.0.0 + transitivePeerDependencies: + - supports-color + dev: false + /micromatch@4.0.5: resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} engines: {node: '>=8.6'} @@ -4394,14 +4651,12 @@ packages: /mime-db@1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} engines: {node: '>= 0.6'} - dev: true /mime-types@2.1.35: resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} engines: {node: '>= 0.6'} dependencies: mime-db: 1.52.0 - dev: true /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} @@ -4504,7 +4759,6 @@ packages: /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - dev: true /muggle-string@0.3.1: resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==} @@ -4623,6 +4877,16 @@ packages: resolution: {integrity: sha512-Wj7+EJQ8mSuXr2iWfnujrimU35R2W4FAErEyTmJoJ7ucwTn2hOUSsRehMb5RSYkxXGTM7Y9QpvPmp++w5ftoJw==} dev: false + /notion-to-md@3.1.1: + resolution: {integrity: sha512-Zaa2P1B9Rx99bevFYTGuUMYbbfdHn2G1AZMsytYGDWIJjr6Ie1qp/8CorpwVUh1qrquES/V2PkEREqCuTu1zKA==} + engines: {node: '>=12'} + dependencies: + markdown-table: 2.0.0 + node-fetch: 2.6.12 + transitivePeerDependencies: + - encoding + dev: false + /npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -4772,6 +5036,17 @@ packages: safe-buffer: 5.2.1 dev: true + /parse-entities@2.0.0: + resolution: {integrity: sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==} + dependencies: + character-entities: 1.2.4 + character-entities-legacy: 1.1.4 + character-reference-invalid: 1.1.4 + is-alphanumerical: 1.0.4 + is-decimal: 1.0.4 + is-hexadecimal: 1.0.4 + dev: false + /parse-ms@2.1.0: resolution: {integrity: sha512-kHt7kzLoS9VBZfUsiKjv43mr91ea+U05EyKkEtqp7vNbHxmaVuEqN7XxeEVnGrMtYOAxGrDElSi96K7EgO1zCA==} engines: {node: '>=6'} @@ -5154,6 +5429,37 @@ packages: engines: {node: '>= 0.10'} dev: true + /remark-gfm@1.0.0: + resolution: {integrity: sha512-KfexHJCiqvrdBZVbQ6RopMZGwaXz6wFJEfByIuEwGf0arvITHjiKKZ1dpXujjH9KZdm1//XJQwgfnJ3lmXaDPA==} + dependencies: + mdast-util-gfm: 0.1.2 + micromark-extension-gfm: 0.3.3 + transitivePeerDependencies: + - supports-color + dev: false + + /remark-math@4.0.0: + resolution: {integrity: sha512-lH7SoQenXtQrvL0bm+mjZbvOk//YWNuyR+MxV18Qyv8rgFmMEGNuB0TSCQDkoDaiJ40FCnG8lxErc/zhcedYbw==} + dependencies: + mdast-util-math: 0.1.2 + micromark-extension-math: 0.1.2 + transitivePeerDependencies: + - supports-color + dev: false + + /remark-parse@9.0.0: + resolution: {integrity: sha512-geKatMwSzEXKHuzBNU1z676sGcDcFoChMK38TgdHJNAYfFtsfHDQG7MoJAjs6sgYMqyLduCYWDIWZIxiPeafEw==} + dependencies: + mdast-util-from-markdown: 0.8.5 + transitivePeerDependencies: + - supports-color + dev: false + + /repeat-string@1.6.1: + resolution: {integrity: sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==} + engines: {node: '>=0.10'} + dev: false + /require-from-string@2.0.2: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} @@ -5670,6 +5976,10 @@ packages: hasBin: true dev: true + /trough@1.0.5: + resolution: {integrity: sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==} + dev: false + /ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} dev: true @@ -5816,6 +6126,18 @@ packages: resolution: {integrity: sha512-RsPyTbqORDNDxqAdQPQBpgqhWle1VcTSou/FraClYlHf6TZnQcGslpLcAphNR+sQW4q5lLWLbOsRlh9j24baQg==} dev: true + /unified@9.2.2: + resolution: {integrity: sha512-Sg7j110mtefBD+qunSLO1lqOEKdrwBFBrR6Qd8f4uwkhWNlbkaqwHse6e7QvD3AP/MNoJdEDLaf8OxYyoWgorQ==} + dependencies: + '@types/unist': 2.0.7 + bail: 1.0.5 + extend: 3.0.2 + is-buffer: 2.0.5 + is-plain-obj: 2.1.0 + trough: 1.0.5 + vfile: 4.2.1 + dev: false + /unimport@3.1.3: resolution: {integrity: sha512-up4TE2yA+nMyyErGTjbYGVw95MriGa2hVRXQ3/JRp7984cwwqULcnBjHaovVpsO8tZc2j0fvgGu9yiBKOyxvYw==} dependencies: @@ -5834,6 +6156,23 @@ packages: - rollup dev: true + /unist-util-is@4.1.0: + resolution: {integrity: sha512-ZOQSsnce92GrxSqlnEEseX0gi7GH9zTJZ0p9dtu87WRb/37mMPO2Ilx1s/t9vBHrFhbgweUwb+t7cIn5dxPhZg==} + dev: false + + /unist-util-stringify-position@2.0.3: + resolution: {integrity: sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==} + dependencies: + '@types/unist': 2.0.7 + dev: false + + /unist-util-visit-parents@3.1.1: + resolution: {integrity: sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg==} + dependencies: + '@types/unist': 2.0.7 + unist-util-is: 4.1.0 + dev: false + /universal-user-agent@6.0.0: resolution: {integrity: sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==} dev: false @@ -5969,7 +6308,23 @@ packages: - supports-color dev: true - /vite-node@0.34.1(@types/node@18.17.2)(stylus@0.59.0): + /vfile-message@2.0.4: + resolution: {integrity: sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==} + dependencies: + '@types/unist': 2.0.7 + unist-util-stringify-position: 2.0.3 + dev: false + + /vfile@4.2.1: + resolution: {integrity: sha512-O6AE4OskCG5S1emQ/4gl8zK586RqA3srz3nfK/Viy0UPToBc5Trp9BVFb1u0CjsKrAWwnpr4ifM/KBXPWwJbCA==} + dependencies: + '@types/unist': 2.0.7 + is-buffer: 2.0.5 + unist-util-stringify-position: 2.0.3 + vfile-message: 2.0.4 + dev: false + + /vite-node@0.34.1(@types/node@18.17.3)(stylus@0.59.0): resolution: {integrity: sha512-odAZAL9xFMuAg8aWd7nSPT+hU8u2r9gU3LRm9QKjxBEF2rRdWpMuqkrkjvyVQEdNFiBctqr2Gg4uJYizm5Le6w==} engines: {node: '>=v14.18.0'} hasBin: true @@ -5979,7 +6334,7 @@ packages: mlly: 1.4.0 pathe: 1.1.1 picocolors: 1.0.0 - vite: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) + vite: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) transitivePeerDependencies: - '@types/node' - less @@ -6008,7 +6363,7 @@ packages: html-minifier-terser: 6.1.0 node-html-parser: 5.4.2 pathe: 0.2.0 - vite: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) + vite: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) dev: true /vite-plugin-node-polyfills@0.8.2(vite@4.4.8): @@ -6018,12 +6373,12 @@ packages: dependencies: '@rollup/plugin-inject': 5.0.3 node-stdlib-browser: 1.2.0 - vite: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) + vite: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) transitivePeerDependencies: - rollup dev: true - /vite@4.4.8(@types/node@18.17.2)(stylus@0.59.0): + /vite@4.4.8(@types/node@18.17.3)(stylus@0.59.0): resolution: {integrity: sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -6051,7 +6406,7 @@ packages: terser: optional: true dependencies: - '@types/node': 18.17.2 + '@types/node': 18.17.3 esbuild: 0.18.17 postcss: 8.4.27 rollup: 3.27.2 @@ -6093,7 +6448,7 @@ packages: dependencies: '@types/chai': 4.3.5 '@types/chai-subset': 1.3.3 - '@types/node': 18.17.2 + '@types/node': 18.17.3 '@vitest/expect': 0.34.1 '@vitest/runner': 0.34.1 '@vitest/snapshot': 0.34.1 @@ -6112,8 +6467,8 @@ packages: strip-literal: 1.3.0 tinybench: 2.5.0 tinypool: 0.7.0 - vite: 4.4.8(@types/node@18.17.2)(stylus@0.59.0) - vite-node: 0.34.1(@types/node@18.17.2)(stylus@0.59.0) + vite: 4.4.8(@types/node@18.17.3)(stylus@0.59.0) + vite-node: 0.34.1(@types/node@18.17.3)(stylus@0.59.0) why-is-node-running: 2.2.2 transitivePeerDependencies: - less @@ -6357,8 +6712,8 @@ packages: engines: {node: '>=12.20'} dev: true - /zhi-blog-api@1.20.10: - resolution: {integrity: sha512-NOdr8verO1ALDC9aaiqgN690Hw/JehpZAouqwm0oYS5IUnxsI7yN4ysTZetIlIC0U07YpWOjoFnLhQeEVv5jZA==} + /zhi-blog-api@1.20.11: + resolution: {integrity: sha512-AYk/T77/SVm02g3/9Iy1ycSrxdSpebTvcgIIAn2giLe6vhQohmpOl4LBBqMP2nSjABgntcJbsGi4itxcymBcGA==} dependencies: zhi-lib-base: 0.4.4 dev: false @@ -6394,10 +6749,20 @@ packages: resolution: {integrity: sha512-adu1KXVDRjsE/tshAXUeRW62VkaNIb0AOcYXnjgHODsw2gJlkxbvVn2wISuboCiwKv1JsD5gbmxdzSkRyJiC5Q==} dev: false - /zhi-siyuan-api@1.29.11: - resolution: {integrity: sha512-dYPps1MbKw4cxLYXlwOgV3A+l/3DGHaIYfoqm0Qe0G6wUAKxmiudnuu/z/GwQpBeZr0C6I8myjk8b8kX2GRHuw==} + /zhi-notion-markdown@0.1.1: + resolution: {integrity: sha512-h5crHNogqGmisQoXZSA1xQyMt6atGGgiM3RFyQiW8fI7H0bBZu3BWsp0MLIfq7WcY3f+8n+osMz5isPxNOD/9A==} + dependencies: + '@tryfabric/martian': 1.2.4 + notion-to-md: 3.1.1 + transitivePeerDependencies: + - encoding + - supports-color + dev: false + + /zhi-siyuan-api@1.29.13: + resolution: {integrity: sha512-s8pZ8n4rV6r6wAKvVy1JYJG2DO3+od9sAqPsJkxpguJVgUmouMVUQyolR9W2uyj/hPBmQmlNWqVY8tYvRCsuwQ==} dependencies: - zhi-blog-api: 1.20.10 + zhi-blog-api: 1.20.11 zhi-common: 1.11.8 zhi-lib-base: 0.4.4 dev: false @@ -6409,3 +6774,7 @@ packages: zhi-device: 2.3.0 zhi-lib-base: 0.4.4 dev: false + + /zwitch@1.0.5: + resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} + dev: false diff --git a/src/adaptors/api/base/baseBlogApi.ts b/src/adaptors/api/base/baseBlogApi.ts index 7b8e0b8b..a37d61f1 100644 --- a/src/adaptors/api/base/baseBlogApi.ts +++ b/src/adaptors/api/base/baseBlogApi.ts @@ -81,7 +81,7 @@ export class BaseBlogApi extends BlogApi { url: string, headers: any[], params: any, - method: "GET" | "POST" | "PUT" | "DELETE" = "GET", + method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" = "GET", contentType: string = "application/json" ): Promise { let body: any diff --git a/src/adaptors/api/notion/adaptor/notionApiAdaptor.ts b/src/adaptors/api/notion/adaptor/notionApiAdaptor.ts index 260387ab..436a53d0 100644 --- a/src/adaptors/api/notion/adaptor/notionApiAdaptor.ts +++ b/src/adaptors/api/notion/adaptor/notionApiAdaptor.ts @@ -28,6 +28,7 @@ import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts" import { NotionConfig } from "~/src/adaptors/api/notion/config/notionConfig.ts" import { createAppLogger } from "~/src/utils/appLogger.ts" import { ObjectUtil, StrUtil } from "zhi-common" +import { NotionMarkdownConverter } from "zhi-notion-markdown" /** * Notion API 适配器 @@ -57,7 +58,8 @@ class NotionApiAdaptor extends BaseBlogApi { } public async newPost(post: Post, publish?: boolean): Promise { - return super.newPost(post) + const pageId = post.cate_slugs?.[0] ?? this.cfg.blogid + return await this.createPage(post.title, post.description, pageId) } public async editPost(postid: string, post: Post, publish?: boolean): Promise { @@ -65,7 +67,8 @@ class NotionApiAdaptor extends BaseBlogApi { } public async deletePost(postid: string): Promise { - return await super.deletePost(postid) + const notionPostidKey = this.getNotionPostidKey(postid) + return await this.deletePage(notionPostidKey.pageId) } public async getPost(postid: string, useSlug?: boolean): Promise { @@ -94,7 +97,10 @@ class NotionApiAdaptor extends BaseBlogApi { public async getPreviewUrl(postid: string): Promise { const purl = this.cfg.previewUrl ?? "" - const postUrl = purl.replace("[postid]", postid) + const notionPostKey = this.getNotionPostidKey(postid) + // const pageId = notionPostKey.pageId + const endUrl = notionPostKey.endUrl + const postUrl = purl.replace("[postid]", endUrl) return StrUtil.pathJoin(this.cfg.home ?? "", postUrl) } @@ -109,12 +115,8 @@ class NotionApiAdaptor extends BaseBlogApi { property: "object", }, } - const searchResp = await this.notionRequest("/search", params, "POST") - this.logger.debug("notion searchResp=>", searchResp) - if (searchResp?.status === 401) { - throw new Error(searchResp?.message) - } - const pages = searchResp.results as any + const resp = await this.notionRequest("/search", params, "POST") + const pages = resp.results as any this.logger.debug("notion pages=>", pages) // https://stackoverflow.com/a/75537092/4037224 @@ -127,6 +129,72 @@ class NotionApiAdaptor extends BaseBlogApi { return pages } + // https://developers.notion.com/reference/post-page + private async createPage(title: string, markdownText: string, parentPageId?: string) { + // 如果没传递过来就用默认的父页面 + const page_id = parentPageId ?? this.cfg.blogid + const notionObject = NotionMarkdownConverter.markdownToNotion(markdownText) + const params = { + parent: { page_id: page_id }, + properties: { + title: [ + { + text: { + content: title, + }, + }, + ], + }, + children: notionObject, + } + this.logger.debug("before createPage, notionObject=>", notionObject) + const resp = await this.notionRequest("/pages", params, "POST") + if (resp.object !== "page") { + throw new Error("Notion create page error") + } + + // 保存url,否则后面打不开 + const url = resp.url + const endUrl = url.split("/").slice(-1)[0]; + return `${resp.id}_${endUrl}` + } + + private async deletePage(pageId: string): Promise { + this.logger.debug("before deletePage, pageId=>", pageId) + const url = `/pages/${pageId}` + const params = { + archived: true, + } + const resp = await this.notionRequest(url, params, "PATCH") + if (resp.object !== "page") { + throw new Error("Notion delete page error") + } + return resp.archived + } + + /** + * 获取封装的postid + * + * @param postid + * @private postid + */ + private getNotionPostidKey(postid: string): any { + let pageId + let endUrl + if (postid.indexOf("_") > 0) { + const idArr = postid.split("_") + pageId = idArr[0] + endUrl = idArr[1] + } else { + pageId = postid + } + + return { + pageId: pageId, + endUrl: endUrl, + } + } + /** * 向Notion请求数据 * @@ -138,7 +206,7 @@ class NotionApiAdaptor extends BaseBlogApi { private async notionRequest( url: string, params?: any, - method: "GET" | "POST" | "PUT" | "DELETE" = "POST" + method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" = "POST" ): Promise { const contentType = "application/json" // https://developers.notion.com/reference/post-search @@ -157,7 +225,7 @@ class NotionApiAdaptor extends BaseBlogApi { const resJson = await this.proxyFetch(url, [headers], body, method, contentType) this.logger.debug("向Notion请求数据,resJson =>", resJson) - if (resJson?.status === 401) { + if (resJson?.status === 400 || resJson?.status === 401 || resJson?.status === 404 || resJson?.status === 429) { throw new Error(resJson?.message) } diff --git a/src/adaptors/api/yuque/adaptor/yuqueApiAdaptor.ts b/src/adaptors/api/yuque/adaptor/yuqueApiAdaptor.ts index ac00f36e..2a08a54e 100644 --- a/src/adaptors/api/yuque/adaptor/yuqueApiAdaptor.ts +++ b/src/adaptors/api/yuque/adaptor/yuqueApiAdaptor.ts @@ -56,20 +56,13 @@ class YuqueApiAdaptor extends BaseBlogApi { } public async newPost(post: Post, publish?: boolean): Promise { - if (post.cate_slugs != null && post.cate_slugs.length > 0) { - const repo = post.cate_slugs[0] - return await this.addDoc(post.title, post.wp_slug, post.description, repo) - } else if (!StrUtil.isEmptyString(this.cfg.blogid)) { - // 确保最新的文章ID都包含了笔记本信息,防止以后文章出错 - const repo = this.cfg.blogid - return await this.addDoc(post.title, post.wp_slug, post.description, repo) - } else { - return await this.addDoc(post.title, post.wp_slug, post.description) - } + // 确保最新的文章ID都包含了笔记本信息,防止以后文章出错 + const repo = post.cate_slugs?.[0] ?? this.cfg.blogid + return await this.addDoc(post.title, post.wp_slug, post.description, repo) } public async editPost(postid: string, post: Post, publish?: boolean): Promise { - const yuquePostidKey = this.getYuquePostKey(postid) + const yuquePostidKey = this.getYuquePostidKey(postid) return await this.updateDoc( yuquePostidKey.docId, post.title, @@ -80,12 +73,12 @@ class YuqueApiAdaptor extends BaseBlogApi { } public async deletePost(postid: string): Promise { - const yuquePostidKey = this.getYuquePostKey(postid) + const yuquePostidKey = this.getYuquePostidKey(postid) return await this.delDoc(yuquePostidKey.docId, yuquePostidKey.docRepo) } public async getPost(postid: string, useSlug?: boolean): Promise { - const yuquePostidKey = this.getYuquePostKey(postid) + const yuquePostidKey = this.getYuquePostidKey(postid) const yuqueDoc = await this.getDoc(yuquePostidKey.docId, yuquePostidKey.docRepo) this.logger.debug("yuqueDoc=>", yuqueDoc) @@ -131,7 +124,7 @@ class YuqueApiAdaptor extends BaseBlogApi { public async getPreviewUrl(postid: string): Promise { // 替换文章链接 const purl = this.cfg.previewUrl ?? "" - const yuquePostidKey = this.getYuquePostKey(postid) + const yuquePostidKey = this.getYuquePostidKey(postid) const docId = yuquePostidKey.docId const repo = yuquePostidKey.docRepo ?? this.cfg.blogid ?? "" const postUrl = purl.replace("[postid]", docId).replace("[notebook]", repo) @@ -226,7 +219,7 @@ class YuqueApiAdaptor extends BaseBlogApi { * @param postid * @private postid */ - private getYuquePostKey(postid: string): any { + private getYuquePostidKey(postid: string): any { let docId let docRepo if (postid.indexOf("_") > 0) { @@ -308,7 +301,7 @@ class YuqueApiAdaptor extends BaseBlogApi { this.logger.debug("向语雀请求数据,params =>", params) // 使用兼容的fetch调用并返回统一的JSON数据 - const body = ObjectUtil.isEmptyObject(params) ? "" : JSON.stringify(params); + const body = ObjectUtil.isEmptyObject(params) ? "" : JSON.stringify(params) const resJson = await this.proxyFetch(url, [headers], body, method, contentType) this.logger.debug("向语雀请求数据,resJson =>", resJson) diff --git a/src/components/common/BackPage.vue b/src/components/common/BackPage.vue index 0e34dbf5..0ba74668 100644 --- a/src/components/common/BackPage.vue +++ b/src/components/common/BackPage.vue @@ -52,8 +52,7 @@ const showBack = ref(query.showBack === "true") const emit = defineEmits(["backEmit"]) const onBack = () => { - if (emit) { - emit("backEmit") + if (emit && emit("backEmit") as any) { } else { router.back() } diff --git a/src/components/publish/SinglePublishDoPublish.vue b/src/components/publish/SinglePublishDoPublish.vue index 75d12afd..ca2a9c48 100644 --- a/src/components/publish/SinglePublishDoPublish.vue +++ b/src/components/publish/SinglePublishDoPublish.vue @@ -80,27 +80,32 @@ const handlePublish = async () => { logger.info("单个常规发布开始") const processResult = await doSinglePublish(key, id, formData.mergedPost) - logger.info("normal publish processResult =>", processResult) logger.info("单个常规发布结束") - // 刷新页面 - // 如果是发布并且发布成功 - if (formData.method === MethodEnum.METHOD_ADD) { - formData.method = MethodEnum.METHOD_EDIT - window.location.href = BrowserUtil.setUrlParameter(window.location.href, "method", formData.method) - // 因为hash的原因,需要再刷新一次 - window.location.reload() + if (processResult.status) { + // 刷新页面 + // 如果是发布并且发布成功 + if (formData.method === MethodEnum.METHOD_ADD) { + formData.method = MethodEnum.METHOD_EDIT + window.location.href = BrowserUtil.setUrlParameter(window.location.href, "method", formData.method) + // 因为hash的原因,需要再刷新一次 + window.location.reload() + } else { + // 需要刷新才能继续操作,防止重复提交 + formData.isInit = false + await initPage() + formData.isInit = true + } } else { - // 需要刷新才能继续操作,防止重复提交 - formData.isInit = false - await initPage() - formData.isInit = true + ElMessage.error(processResult.errMsg) + logger.error(processResult.errMsg) } formData.actionEnable = true - } catch (error) { - ElMessage.error(error.message) + } catch (e) { + ElMessage.error(e.message) + logger.error(e) } finally { formData.isPublishLoading = false } @@ -130,22 +135,27 @@ const doDelete = async () => { formData.isDeleteLoading = true formData.actionEnable = false - await doSingleDelete(key, id) - - // 刷新页面 - const platformName = getPlatformName() - const blogName = getBlogName() - ElMessage.success(`[${platformName} - ${blogName}] 文章删除成功`) - - // 如果是发布并且发布成功 - setTimeout(() => { - formData.method = MethodEnum.METHOD_ADD - window.location.href = BrowserUtil.setUrlParameter(window.location.href, "method", formData.method) - // 因为hash的原因,需要再刷新一次 - window.location.reload() - }, 200) - } catch (error) { - ElMessage.error(error.message) + const processResult = await doSingleDelete(key, id) + if (processResult.status) { + // 刷新页面 + const platformName = getPlatformName() + const blogName = getBlogName() + ElMessage.success(`[${platformName} - ${blogName}] 文章删除成功`) + + // 如果是发布并且发布成功 + setTimeout(() => { + formData.method = MethodEnum.METHOD_ADD + window.location.href = BrowserUtil.setUrlParameter(window.location.href, "method", formData.method) + // 因为hash的原因,需要再刷新一次 + window.location.reload() + }, 200) + } else { + ElMessage.error(processResult.errMsg) + logger.error(processResult.errMsg) + } + } catch (e) { + ElMessage.error(e.message) + logger.error(e) } finally { formData.isDeleteLoading = false } @@ -218,6 +228,7 @@ const onBack = () => { } router.push(query) } + onMounted(async () => { logger.info("获取到的ID为=>", id) @@ -258,8 +269,9 @@ onMounted(async () => { - + @@ -314,4 +326,4 @@ onMounted(async () => { .top-tip margin-top 10px padding-left 0 - \ No newline at end of file + diff --git a/src/composables/usePublish.ts b/src/composables/usePublish.ts index f6454a75..ba415036 100644 --- a/src/composables/usePublish.ts +++ b/src/composables/usePublish.ts @@ -24,13 +24,13 @@ */ import { createAppLogger } from "~/src/utils/appLogger.ts" -import { reactive } from "vue" +import { reactive, toRaw } from "vue" import { SypConfig } from "~/syp.config.ts" import { JsonUtil, StrUtil } from "zhi-common" import { AppInstance } from "~/src/appInstance.ts" import Adaptors from "~/src/adaptors" import { Utils } from "~/src/utils/utils.ts" -import { BlogAdaptor, Post } from "zhi-blog-api" +import { BlogAdaptor, BlogConfig, PageTypeEnum, Post } from "zhi-blog-api" import { useVueI18n } from "~/src/composables/useVueI18n.ts" import { useSettingStore } from "~/src/stores/useSettingStore.ts" import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts" @@ -102,8 +102,11 @@ const usePublish = () => { singleFormData.isAdd = StrUtil.isEmptyString(singleFormData.postid) if (singleFormData.isAdd) { logger.info("文章未发布,准备发布") + logger.debug("before preHandlePost newPost, doc=>", toRaw(doc)) + const post = preHandlePost(doc, singleFormData.cfg) + logger.debug("after preHandlePost newPost, doc=>", toRaw(post)) // result 正常情况下就是 postid - const result = await api.newPost(doc) + const result = await api.newPost(post) // 写入postid到配置 singleFormData.postid = result @@ -115,8 +118,11 @@ const usePublish = () => { logger.info("new post=>", result) } else { logger.info("文章已发布,准备更新") + logger.debug("before preHandlePost editPost, doc=>", toRaw(doc)) + const post = preHandlePost(doc, singleFormData.cfg) + logger.debug("after preHandlePost editPost, doc=>", toRaw(post)) // result 正常情况下是 true - const result = await api.editPost(singleFormData.postid, doc) + const result = await api.editPost(singleFormData.postid, post) logger.info("edit post=>", result) } @@ -242,11 +248,21 @@ const usePublish = () => { singleFormData.previewUrl = isAbsoluteUrl ? previewUrl : `${singleFormData.cfg?.home ?? ""}${previewUrl}` } + const preHandlePost = (doc: Post, cfg: BlogConfig): Post => { + const post = doc + // 发布格式 + if (cfg.pageType == PageTypeEnum.Markdown) { + post.description = post.markdown + } + return post + } + const assignValue = (title1: string, title2: string) => (title1.length > title2.length ? title1 : title2) const doInitPage = async (key: string, id: string, method: MethodEnum = MethodEnum.METHOD_ADD) => { // 思源笔记原始文章数据 singleFormData.siyuanPost = await blogApi.getPost(id) + logger.debug("doInitPage init siyuanPost =>", toRaw(singleFormData.siyuanPost)) // 加载配置 singleFormData.setting = await getSetting() @@ -281,6 +297,7 @@ const usePublish = () => { singleFormData.mergedPost = new Post() singleFormData.mergedPost.title = singleFormData.siyuanPost.title singleFormData.mergedPost.description = singleFormData.siyuanPost.description + singleFormData.mergedPost.markdown = singleFormData.siyuanPost.markdown } else { logger.info("Reading post from remote platform") if (StrUtil.isEmptyString(postid)) { @@ -293,6 +310,7 @@ const usePublish = () => { singleFormData.mergedPost.title = assignValue(singleFormData.siyuanPost.title, singleFormData.platformPost.title) // 正文以思源笔记为准 singleFormData.mergedPost.description = singleFormData.siyuanPost.description + singleFormData.mergedPost.markdown = singleFormData.siyuanPost.markdown // 更新预览链接 await setPreviewUrl(api, postid) diff --git a/tsconfig.json b/tsconfig.json index d97e2a6e..a3315f78 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,14 +27,6 @@ "~/*": ["./*"] } }, - "include": [ - "*.ts", - "*.d.ts", - "**/**/*.ts", - "**/**/*.d.ts", - "*.vue", - "**/**/*.vue", - "src/picgo.d.ts" - ], + "include": ["*.ts", "*.vue", "*.d.ts", "**/**/*.ts", "**/**/*.d.ts", "**/**/*.vue", "custom.d.ts"], "references": [{ "path": "./tsconfig.node.json" }] }