Skip to content

Commit

Permalink
feat(zhi-blog-api): add a common blog api
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 5, 2023
1 parent 639e79c commit fdc0d82
Show file tree
Hide file tree
Showing 26 changed files with 1,539 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/zhi-lib-blog-api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
38 changes: 38 additions & 0 deletions packages/zhi-lib-blog-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# zhi-lib-blog-api

a common blog interface

Note: BlogApi should be implemented as a specific BlogApi, it cannot be used directly

## Deps

```
├── @siyuan-community/zhi-env
├── @siyuan-community/zhi-log
````
## Dev
```bash
nx dev zhi-lib-blog-api
```

## Build

```bash
nx build zhi-lib-blog-api
```

## Test

Execute the unit tests via [vitest](https://vitest.dev)

```bash
nx test zhi-lib-blog-api
```

## Publish

```
nx publish zhi-lib-blog-api --ver=0.0.1 --tag=latest
```
16 changes: 16 additions & 0 deletions packages/zhi-lib-blog-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@siyuan-community/zhi-blog-api",
"version": "0.1.0",
"type": "module",
"description": "a common blog interface",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/packages/zhi-lib-blog-api",
"author": "terwer",
"license": "GPL",
"keywords": [
"blog",
"api"
]
}
35 changes: 35 additions & 0 deletions packages/zhi-lib-blog-api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "zhi-lib-blog-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-lib-blog-api/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/zhi-lib-blog-api"
}
},
"publish": {
"command": "node tools/scripts/publish.mjs zhi-lib-blog-api {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["coverage/packages/zhi-lib-blog-api"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/zhi-lib-blog-api"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-lib-blog-api/**/*.ts"]
}
}
},
"tags": []
}
28 changes: 28 additions & 0 deletions packages/zhi-lib-blog-api/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

interface ImportMeta {
readonly env: ImportMetaEnv
}
26 changes: 26 additions & 0 deletions packages/zhi-lib-blog-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

export * from "./lib/zhi-lib-blog-api"
174 changes: 174 additions & 0 deletions packages/zhi-lib-blog-api/src/lib/IBlogApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* 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.
*/

import UserBlog from "./models/userBlog"
import Post from "./models/post"
import MediaObject from "./models/mediaObject"
import CategoryInfo from "./models/categoryInfo"

/**
* 通用博客接口
*
* @public
* @author terwer
* @version 1.0.0
* @since 1.0.0
*/
interface IBlogApi {
/**
* 博客配置列表
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.getUsersBlogs getUsersBlogs}
* @returns {Promise<Array<UserBlog>>}
*/
getUsersBlogs(): Promise<Array<UserBlog>>

/**
* 最新文章数目
*
* @param keyword - 关键字(可选,部分平台不支持搜索)
* @returns {Promise<number>}
*/
getRecentPostsCount(keyword?: string): Promise<number>

/**
* 最新文章
*
* @param numOfPosts - 文章数目
* @param page - 页码(可选,从0开始,部分平台不支持分页)
* @param keyword - 关键字(可选,部分平台不支持搜索)
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.getRecentPosts getRecentPosts}
* @returns {Promise<Array<Post>>}
*/
getRecentPosts(numOfPosts: number, page?: number, keyword?: string): Promise<Array<Post>>

/**
* 发布文章
*
* @param post - 文章
* @param publish - 可选,是否发布
*
* ```ts
* const post = {
* description: "自动发布的测试内容",
* title: "自动发布的测试标题",
* categories: ["标签1","标签2"],
* // dateCreated: new Date(),
* // link: "",
* // permalink: "",
* // postid: "",
* // source: {
* // name: "",
* // url: ""
* // };
* // userid: ""
* }
*
* const result = newPost(post, false)
* ```
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost newPost}
* @returns {Promise<string>}
*/
newPost(post: Post, publish?: boolean): Promise<string>

/**
* 文章详情
* @param postid - postid
* @param useSlug - 是否使用的是别名(可选,部分平台不支持)
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.getPost getPost}
* @returns {Promise<Post>}
*/
getPost(postid: string, useSlug?: boolean): Promise<Post>

/**
* 更新文章
*
* @param postid - 文章id
* @param post - 文章
* @param publish - 可选,是否发布
*
* ```ts
* // wordpress
* // const postid = 4115
* // conf
* // const postid = 1540103
* const postid = "2490384_1"
* const post = {
* description: "修改过的自动发布的测试内容2",
* title: "修改过的自动发布的测试标题2",
* categories: ["标签1", "标签2"],
* // dateCreated: new Date(),
* // link: "",
* // permalink: "",
* // postid: postid,
* // source: {
* // name: "",
* // url: ""
* // };
* // userid: ""
* }
*
* const result = editPost(postid, post, false)
* ```
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.editPost editPost}
* @returns {Promise<boolean>}
*/
editPost(postid: string, post: Post, publish?: boolean): Promise<boolean>

/**
* 删除文章
*
* @param postid - 文章ID
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.deletePost deletePost}
* @returns {Promise<boolean>}
*/
deletePost(postid: string): Promise<boolean>

/**
* 获取分类列表
*
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.getCategories getCategories}
* @returns {Promise<CategoryInfo[]>}
*/
getCategories(): Promise<CategoryInfo[]>

/**
* 获取预览链接
*
* @param postid - 文章ID
* @returns {Promise<string>}
*/
getPreviewUrl(postid: string): Promise<string>

/**
* 上传附件
*
* @param mediaObject
* @see {@link https://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newMediaObject newMediaObject}
* @returns {Promise<MediaObject>}
*/
newMediaObject(mediaObject: MediaObject): Promise<MediaObject>
}

export { IBlogApi }
Loading

0 comments on commit fdc0d82

Please sign in to comment.