From ae828cfb564c5bf7db321431d9601828a2baddb1 Mon Sep 17 00:00:00 2001 From: "xiaoqi.cxq" Date: Thu, 30 Mar 2023 15:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + package-lock.json | 2 +- package.json | 2 +- server/index.js | 4 +- src/components/Modal.vue | 4 + src/components/PreviewInPageButtons.vue | 48 ++++- src/components/menus/PublishMenu.vue | 10 +- src/components/menus/SyncMenu.vue | 13 +- .../modals/PublishManagementModal.vue | 29 ++- .../modals/providers/GistPublishModal.vue | 10 +- .../modals/providers/GistSyncModal.vue | 10 +- .../providers/GiteeGistPublishModal.vue | 79 +++++++++ .../modals/providers/GiteeGistSyncModal.vue | 64 +++++++ src/data/features.js | 20 ++- src/data/simpleModals.js | 9 + src/icons/Provider.vue | 1 + src/icons/Share.vue | 3 + src/icons/index.js | 2 + src/services/providers/giteeGistProvider.js | 95 ++++++++++ src/services/providers/helpers/giteeHelper.js | 38 +--- src/services/publishSvc.js | 10 +- static/landing/share.html | 165 ++++++++++++++++++ 22 files changed, 562 insertions(+), 57 deletions(-) create mode 100644 src/components/modals/providers/GiteeGistPublishModal.vue create mode 100644 src/components/modals/providers/GiteeGistSyncModal.vue create mode 100644 src/icons/Share.vue create mode 100644 src/services/providers/giteeGistProvider.js create mode 100644 static/landing/share.html diff --git a/README.md b/README.md index d8bc5fe9..70aa5861 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ StackEdit中文版 - 支持预览区域选择主题样式(2022-12-04) - Gitlab的支持优化(2023-02-23) - 导出HTML、PDF支持带预览主题导出(2023-02-26) +- 支持分享文档(2023-03-30) ## 国外开源版本弊端: - 作者已经不维护了 diff --git a/package-lock.json b/package-lock.json index 8aa07282..bde12dd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "stackedit", - "version": "5.15.17", + "version": "5.15.19", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c2a2b4cb..8819908e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stackedit", - "version": "5.15.18", + "version": "5.15.19", "description": "免费, 开源, 功能齐全的 Markdown 编辑器", "author": "Benoit Schweblin, 豆萁", "license": "Apache-2.0", diff --git a/server/index.js b/server/index.js index f04790a2..9ad7d738 100644 --- a/server/index.js +++ b/server/index.js @@ -61,13 +61,15 @@ module.exports = (app) => { res.redirect(`./app#providerId=googleDrive&state=${encodeURIComponent(req.query.state)}`)); // Serve the static folder with 30 day max-age app.use('/themes', serveStatic(resolvePath('static/themes'), { - maxAge: '1d', + maxAge: '5d', })); // Serve style.css with 1 day max-age app.get('/style.css', (req, res) => res.sendFile(resolvePath('dist/style.css'), { maxAge: '1d', })); + // Serve share.html + app.get('/share.html', (req, res) => res.sendFile(resolvePath('static/landing/share.html'))); // Serve static resources if (process.env.NODE_ENV === 'production') { diff --git a/src/components/Modal.vue b/src/components/Modal.vue index b3f224bd..e6f3f441 100644 --- a/src/components/Modal.vue +++ b/src/components/Modal.vue @@ -64,6 +64,8 @@ import GiteeOpenModal from './modals/providers/GiteeOpenModal'; import GiteeSaveModal from './modals/providers/GiteeSaveModal'; import GiteeWorkspaceModal from './modals/providers/GiteeWorkspaceModal'; import GiteePublishModal from './modals/providers/GiteePublishModal'; +import GiteeGistSyncModal from './modals/providers/GiteeGistSyncModal'; +import GiteeGistPublishModal from './modals/providers/GiteeGistPublishModal'; import GitlabAccountModal from './modals/providers/GitlabAccountModal'; import GitlabOpenModal from './modals/providers/GitlabOpenModal'; import GitlabPublishModal from './modals/providers/GitlabPublishModal'; @@ -131,6 +133,8 @@ export default { GiteeSaveModal, GiteeWorkspaceModal, GiteePublishModal, + GiteeGistSyncModal, + GiteeGistPublishModal, GitlabAccountModal, GitlabOpenModal, GitlabPublishModal, diff --git a/src/components/PreviewInPageButtons.vue b/src/components/PreviewInPageButtons.vue index c7d15f20..4d6ce2ff 100644 --- a/src/components/PreviewInPageButtons.vue +++ b/src/components/PreviewInPageButtons.vue @@ -4,6 +4,9 @@
  • +
  • + +
  • @@ -21,6 +24,8 @@ import { mapGetters, mapActions } from 'vuex'; // import juice from 'juice'; import store from '../store'; import DropdownMenu from './common/DropdownMenu'; +import publishSvc from '../services/publishSvc'; +import giteeGistProvider from '../services/providers/giteeGistProvider'; export default { components: { @@ -56,12 +61,16 @@ export default { value: 'custom', }], baseCss: '', + sharing: false, }), computed: { ...mapGetters('theme', [ 'currPreviewTheme', 'customPreviewThemeStyle', ]), + ...mapGetters('publishLocation', { + publishLocations: 'current', + }), selectedTheme() { return { value: this.currPreviewTheme || 'default', @@ -84,6 +93,43 @@ export default { this.toggleSideBar(true); store.dispatch('data/setSideBarPanel', 'help'); }, + async share() { + if (this.sharing) { + store.dispatch('notification/info', '分享链接创建中...请稍后再试'); + return; + } + try { + const currentFile = store.getters['file/current']; + await store.dispatch('modal/open', { type: 'shareHtmlPre', name: currentFile.name }); + this.sharing = true; + const mainToken = store.getters['workspace/mainWorkspaceToken']; + if (!mainToken) { + store.dispatch('notification/info', '登录主文档空间之后才可使用分享功能!'); + return; + } + let giteeGistId = null; + const filterLocations = this.publishLocations.filter(it => it.providerId === 'giteegist' && it.url && it.gistId); + if (filterLocations.length > 0) { + giteeGistId = filterLocations[0].gistId; + } + const location = giteeGistProvider.makeLocation( + mainToken, + `分享-${currentFile.name}`, + true, + null, + ); + location.templateId = 'styledHtmlWithTheme'; + location.fileId = currentFile.id; + location.gistId = giteeGistId; + const { gistId } = await publishSvc.publishLocationAndStore(location); + const url = `${window.location.protocol}//${window.location.host}/share.html?id=${gistId}`; + await store.dispatch('modal/open', { type: 'shareHtml', name: currentFile.name, url }); + } catch (err) { + /* cancel */ + } finally { + this.sharing = false; + } + }, }, }; @@ -94,7 +140,7 @@ export default { .preview-in-page-buttons { position: absolute; bottom: 10px; - right: -68px; + right: -98px; height: 34px; padding: 5px; background-color: rgba(84, 96, 114, 0.4); diff --git a/src/components/menus/PublishMenu.vue b/src/components/menus/PublishMenu.vue index 48a4167a..9a835acf 100644 --- a/src/components/menus/PublishMenu.vue +++ b/src/components/menus/PublishMenu.vue @@ -43,7 +43,7 @@
    -
    发布到 Gist
    +
    发布到 GitHubGist
    {{token.name}}
    @@ -53,6 +53,11 @@
    + + +
    发布到 GiteeGist
    + {{token.name}} +
    发布到 Gitee
    @@ -289,8 +294,9 @@ export default { publishBloggerPage: publishModalOpener('bloggerPagePublish', 'publishToBloggerPage'), publishDropbox: publishModalOpener('dropboxPublish', 'publishToDropbox'), publishGithub: publishModalOpener('githubPublish', 'publishToGithub'), - publishGitee: publishModalOpener('giteePublish', 'publishToGitee'), publishGist: publishModalOpener('gistPublish', 'publishToGist'), + publishGitee: publishModalOpener('giteePublish', 'publishToGitee'), + publishGiteeGist: publishModalOpener('giteeGistPublish', 'publishGiteeGist'), publishGitlab: publishModalOpener('gitlabPublish', 'publishToGitlab'), publishGitea: publishModalOpener('giteaPublish', 'publishToGitea'), publishGoogleDrive: publishModalOpener('googleDrivePublish', 'publishToGoogleDrive'), diff --git a/src/components/menus/SyncMenu.vue b/src/components/menus/SyncMenu.vue index 2cef7982..d01555eb 100644 --- a/src/components/menus/SyncMenu.vue +++ b/src/components/menus/SyncMenu.vue @@ -46,7 +46,7 @@
    -
    在Gist上保存
    +
    在GitHubGist上保存
    {{token.name}}
    @@ -61,6 +61,11 @@
    在Gitee上保存
    {{token.name}} + + +
    在GiteeGist上保存
    + {{token.name}} +
    @@ -330,6 +335,12 @@ export default { badgeSvc.addBadge('saveOnGist'); } catch (e) { /* cancel */ } }, + async saveGiteeGist(token) { + try { + await openSyncModal(token, 'giteeGistSync'); + badgeSvc.addBadge('saveOnGiteeGist'); + } catch (e) { /* cancel */ } + }, async openGitlab(token) { try { const syncLocation = await store.dispatch('modal/open', { diff --git a/src/components/modals/PublishManagementModal.vue b/src/components/modals/PublishManagementModal.vue index 52726eab..7e7cc49d 100644 --- a/src/components/modals/PublishManagementModal.vue +++ b/src/components/modals/PublishManagementModal.vue @@ -4,8 +4,8 @@ -

    {{currentFileName}} is published to the following location(s):

    -

    {{currentFileName}} is not published yet.

    +

    {{currentFileName}} 被发布到了以下位置:

    +

    {{currentFileName}} 还没有被发布.

    @@ -26,7 +26,7 @@ {{location.url}}
    - @@ -34,6 +34,19 @@
    +
    +
    + 分享链接: {{shareUrl(location)}} +
    +
    + + + + +
    +