Skip to content

Commit

Permalink
feat: Notion 支持文档更新
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 29, 2023
1 parent 85d01ed commit 23f331f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 66 deletions.
37 changes: 13 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,22 @@ Publish articles from siyuan-note to platforms such as Yuque, Notion, Cnblogs, W

Support features such as fast publishing, image bed management, platform expansion, smart labels, etc.

> The latest release: 🎉 Publish Tool Version `1.17.3`
> Recent Update: 🎉 Publish Tool new version `1.18.0` released.
**This is perhaps the most significant performance improvement to date. 😄**

- Version `1.17.3` incorporates minor performance enhancements and introduces a timing mechanism to display the elapsed duration of key page operations.
- Special thanks to [@cesaryuan](https://github.com/cesaryuan) for their contribution [#786](https://github.com/terwer/siyuan-plugin-publisher/issues/786), which resulted in a substantial enhancement in the performance of the release tool. Starting from version `1.17.2`, the initial screen loading time has been reduced from `1600ms` to `900ms`.
- Key changes in version `1.17.0` include:
- Optimized support for AI effects.
- Preferences are now persistent, eliminating concerns about preference settings becoming invalid due to restarts or other circumstances.
- Fixed the issue of Halo publication time not taking effect.
- Resolved the problem of articles not updating after being published by old widgets.
- Ah, in addition, starting from version `1.14.0`, the author quietly developed an import feature. You can use the `Settings` -> `Publish Settings` -> `Import Predefined Platforms` function to quickly import built-in platforms. 😄
- `1.18.0` brings compatibility with multiple platforms and overall enhanced user experience.
- Key changes in `1.18.0` include:
- A clever workaround has been introduced to support document updates in Notion.
- Ahem, in addition, the author secretly developed an import feature after version `1.14.0`. You can easily import predefined platforms through the `Settings` -> `Publish Settings` -> `Import Predefined Platforms` function 😄

> Platform Limitations:
- **WeChat Official Accounts**: Publishing Tool now supports posting articles to the WeChat Official Accounts draft box in version `1.13.0` and beyond. However, due to limitations on the WeChat platform in Electron, normal login operations are not possible. Therefore, you will need to visit `https://mp.weixin.qq.com/` yourself, complete the login, copy the cookie, and then paste it into the configuration options.
- **Notion**: Since Notion is block-based, not a whole document, it is constrained by technology and does not support updates. To update, you can only delete and then repost it.
- **Juejin**: Due to the mandatory requirements of the Jujin platform, tags and classifications must be filled in, if you do not select publishing, a backend classification and programmer label will be added by default, otherwise you will not be able to publish.
- **Juejin**: **Juejin need to review every time they publish an article**, so the preview may be 404 immediately after publishing the article, at which point you can modify the link '/post' to '/spost' for temporary viewing, or wait patiently for the review to pass.
- **CSDN**: CSDN requires setting tags, which is a requirement of the CSDN platform, and tags cannot be empty.
![](https://img1.terwer.space/api/public/202309211113950.png)
If not provided, CSDN will generate an error:
```json
{
"code": 400,
"msg": "Please set article tags"
}
```
- All Platforms: The Publish Tool retrieves and overwrites the latest edited content from Simplenote with each release. Remember, it overwrites the content every time. Thus, please refrain from modifying the content manually on the platforms.
- **WeChat Official Account**: The Publish Tool now supports publishing articles to the WeChat Official Account draft folder, starting from `1.13.0+`. However, due to limitations imposed by the WeChat platform on Electron, the login operation is not supported. Hence, you can manually visit `https://mp.weixin.qq.com/`, login, copy the cookie, and paste it into the configuration options.
- **Notion**: As Notion operates on a block-based system rather than whole documents, it is technically limited to perform regular updates. Starting from `1.18.0`, updates are supported by first deleting and then publishing the content. Please note that this process may take longer than usual.
- **Juejin**: Juejin platform requires mandatory tags and categories for publication. If not selected, a default backend category and programmer tag will be applied; otherwise, the article cannot be published.
- **Juejin**: **Each article published on Juejin needs to go through the approval process**. Therefore, immediately after publishing, previewing the article may result in a 404 error. In such cases, you can temporarily modify the link from `/post` to `/spost` for a preview, or patiently wait for the approval process to complete.
- **CSDN**: CSDN requires setting tags, as dictated by the platform's rules. Tags cannot be left empty.

> [Click here](https://blog.terwer.space/s/20230810132040-nn4q7vs) to view the latest help documentation.
## Update history
Expand Down
28 changes: 7 additions & 21 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,23 @@

将思源笔记的文章发布到语雀、Notion、Cnblogs、WordPress、Typecho、Hexo、知乎 等平台,支持极速发布、图床管理、平台扩展、智能标签等特色功能。

> 最近的新版本:🎉 发布工具新版本 `1.17.3` 发布
> 最近的新版本:🎉 发布工具新版本 `1.18.0` 发布
**这可能是目前为止,性能提升最大的一个版本。😄**

- `1.17.3` 小幅度优化性能,并增加计时器,展示部分主要页面操作耗时。
- 特别感谢 [@cesaryuan](https://github.com/cesaryuan) 的贡献 [#786](https://github.com/terwer/siyuan-plugin-publisher/issues/786) ,发布工具性能有了质的提升。`1.17.2`版本之后,首屏启动时间从 `1600ms` 提升到 `900ms`
- `1.17.0` 主要有以下重要变更:
- 对 AI 效果进行了优化支持。
- 偏好设置进行持久化,再也不用担心重启或者其他情况导致的偏好配置失效的问题了。
- 修复了 Halo 发布时间未生效问题。
- 修复了旧挂件发布过的文章无法更新的问题。
- `1.18.0` 新适配多个平台,全方位优化体验。
- `1.18.0` 主要有以下重要变更:
- 曲线救国,支持 Notion 更新文档。
- 咳咳,另外,在 `1.14.0` 版本之后,作者还悄悄开发了导入功能。您可以使用 `设置` -> `发布设置` -> `导入预定义平台` 功能快速导入内置平台 😄

> 平台限制说明
- 所有平台:发布工具每次都会获取思源笔记最新编辑的正文进行覆盖发布。每次发布都会覆盖正文,每次发布都会覆盖正文,每次发布都会覆盖正文。因此,请勿在平台自行修改正文。
- **微信公众号**:目前,发布工具在 `1.13.0+` 已经支持发布文章到微信公众号草稿箱。但是由于微信平台在 Electron 上有限制,无法正常进行登录操作。因此,只能自己访问 `https://mp.weixin.qq.com/` ,登录完成之后,复制 cookie 然后粘贴到配置选项。
- **Notion**: 由于 Notion 是基于块的,不是整篇文档,受限于技术,notion 不支持更新。如需更新,目前只能删除后重新发布
- **Notion**: 由于 Notion 是基于块的,不是整篇文档,受限于技术,正常更新不支持。`1.18.0` 之后,通过先删除在发布的方式可支持更新,但是操作时长可能比正常情况要久一些
- **掘金**:由于掘金平台强制要求,必须填写标签和分类,如果发布不选择默认会加上一个后端分类、程序员标签,否则将无法发布。
- **掘金****掘金每次发布文章都需要审核** ,因此发布文章之后马上预览可能会 404,此时可修改链接的 `/post``/spost` 临时查看,或者耐心等待审核通过。
- **CSDN**: CSDN 必须设置标签,这是 CSDN 平台规定的,标签不能为空。
![](https://img1.terwer.space/api/public/202309211113950.png)
如果不写,CSDN 会报错
```json
{
"code": 400,
"msg": "请设置文章标签"
}
```

**遇到问题或者需求建议?请加 QQ 群 `895063267` 讨论。或者查看下面的在线文档:**

**遇到其他问题或者需求建议?请加 QQ 群 `895063267` 讨论。或者查看下面的在线文档:**

> [猛击这里](https://blog.terwer.space/s/20230810132040-nn4q7vs),查看最新帮助文档。
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
"vue-i18n": "^9.6.1",
"vue-router": "^4.2.5",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.49.0",
"zhi-blog-api": "^1.50.0",
"zhi-common": "^1.25.0",
"zhi-device": "^2.10.0",
"zhi-fetch-middleware": "^0.7.11",
"zhi-github-middleware": "^0.4.8",
"zhi-gitlab-middleware": "^0.6.18",
"zhi-lib-base": "^0.8.0",
"zhi-notion-markdown": "^0.1.4",
"zhi-siyuan-api": "^2.11.8",
"zhi-siyuan-api": "^2.12.0",
"zhi-xmlrpc-middleware": "^0.6.11"
}
}
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions src/adaptors/api/notion/notionApiAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { CategoryInfo, Post, UserBlog } from "zhi-blog-api"
import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts"
import { NotionConfig } from "~/src/adaptors/api/notion/notionConfig.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { ObjectUtil, StrUtil } from "zhi-common"
import { ObjectUtil } from "zhi-common"
import { NotionMarkdownConverter } from "zhi-notion-markdown"
import { useSettingStore } from "~/src/stores/useSettingStore.ts"

/**
* Notion API 适配器
Expand Down Expand Up @@ -62,8 +63,25 @@ class NotionApiAdaptor extends BaseBlogApi {
return await this.createPage(post.title, post.description, pageId)
}

public async editPost(postid: string, post: Post, publish?: boolean): Promise<boolean> {
return await this.updatePage(postid, post.title, post.description)
public async editPost(oldPostid: string, post: Post, publish?: boolean): Promise<boolean> {
await this.deletePost(oldPostid)
const newPostid = await this.newPost(post)
// ================================
// 下面这一段是更新postid,需要注意适配
// 写入属性到配置
const { getSetting, updateSetting } = useSettingStore()
const setting = await getSetting()
const posidKey = this.cfg.posidKey
const id = post.originalId
const postMeta = ObjectUtil.getProperty(setting, id, {})
postMeta[posidKey] = newPostid
setting[id] = postMeta
await updateSetting(setting)
// ==============================
return true

// Notion的原生更新不支持
// return await this.updatePage(postid, post.title, post.description)
}

public async deletePost(postid: string): Promise<boolean> {
Expand Down
25 changes: 19 additions & 6 deletions src/composables/usePublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const usePublish = () => {
logger.info("文章属性处理完成")

// 更新预览链接
postPreviewUrl = await getPostPreviewUrl(api, postid, cfg)
postPreviewUrl = await getPostPreviewUrl(api, id, cfg)

singleFormData.publishProcessStatus = true
} catch (e) {
Expand Down Expand Up @@ -324,10 +324,15 @@ const usePublish = () => {
}
}

const getPostPreviewUrl = async (api: BlogAdaptor, postid: string, cfg: BlogConfig) => {
const previewUrl = await api.getPreviewUrl(postid)
const isAbsoluteUrl = /^http/.test(previewUrl)
return isAbsoluteUrl ? previewUrl : StrUtil.pathJoin(cfg?.home ?? "", previewUrl)
const getPostPreviewUrl = async (api: BlogAdaptor, id: string, cfg: BlogConfig) => {
// 获取最新id,兼容某些平台自定义行为
const { getSetting } = useSettingStore()
const setting = await getSetting()
const posidKey = cfg.posidKey
const postMeta = ObjectUtil.getProperty(setting, id, {})
const newPostid = postMeta[posidKey]
const previewUrl = await api.getPreviewUrl(newPostid)
return StrUtil.pathJoin(cfg?.home ?? "", previewUrl)
}

/**
Expand Down Expand Up @@ -463,6 +468,7 @@ const usePublish = () => {
logger.debug("get init platformPost ok =>", mergedPost)
mergedPost.title = platformPost.title
// 链接需要使用思源笔记的
mergedPost.originalId = siyuanPost.originalId
mergedPost.link = siyuanPost.link
// 正文需要使用思源笔记的
mergedPost.markdown = siyuanPost.markdown
Expand All @@ -472,7 +478,7 @@ const usePublish = () => {
mergedPost = initPublishMethods.doMergeBatchPost(siyuanPost, mergedPost)

// 更新预览链接
postPreviewUrl = await getPostPreviewUrl(api, postid, cfg)
postPreviewUrl = await getPostPreviewUrl(api, id, cfg)
}

logger.debug("doInitPage finished mergedPost =>", toRaw(mergedPost))
Expand All @@ -488,7 +494,10 @@ const usePublish = () => {
const mergedPost = _.cloneDeep(newPost) as Post

mergedPost.title = post.title
mergedPost.originalId = post.originalId
mergedPost.link = post.link
mergedPost.shortDesc = post.shortDesc
mergedPost.mt_excerpt = post.mt_excerpt
mergedPost.mt_keywords = post.mt_keywords
mergedPost.categories = post.categories

Expand All @@ -499,6 +508,10 @@ const usePublish = () => {
// 复制原始 newPost 对象以避免直接修改它
const mergedPost = _.cloneDeep(newPost) as Post

// 这两个属性需要保持
mergedPost.originalId = post.originalId
mergedPost.link = post.link

// 摘要
if (StrUtil.isEmptyString(mergedPost.shortDesc)) {
mergedPost.shortDesc = mergedPost.mt_excerpt
Expand Down

0 comments on commit 23f331f

Please sign in to comment.