# sync-post-commit

> Git提交时将内容推送到别的平台

Latest version **1.1.2** (published 2023-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install sync-post-commit
pnpm add sync-post-commit
yarn add sync-post-commit
bun add sync-post-commit
```

Provides the command `sync-post-commit`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-09-06 |
| First published | 2023-08-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 50.6 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | clboy |
| Maintainers | clboy |
| Keywords | blog, git hook, halo, docsify, yinxiang, evernote |

## Links

- npm: https://www.npmjs.com/package/sync-post-commit
- Repository: https://github.com/cloudlandboy/sync-post-commit
- Issues: https://github.com/cloudlandboy/sync-post-commit/issues
- npm.io page: https://npm.io/package/sync-post-commit

## Dependencies (12)

- [he](https://npm.io/package/he.md) ^1.2.0
- [css](https://npm.io/package/css.md) ^3.0.0
- [ora](https://npm.io/package/ora.md) 5.4.1
- [axios](https://npm.io/package/axios.md) ^1.5.0
- [marked](https://npm.io/package/marked.md) ^7.0.5
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.12
- [prompts](https://npm.io/package/prompts.md) ^2.4.2
- [evernote](https://npm.io/package/evernote.md) ^2.0.5
- [commander](https://npm.io/package/commander.md) ^11.0.0
- [micromatch](https://npm.io/package/micromatch.md) ^4.0.5
- [simple-git](https://npm.io/package/simple-git.md) ^3.19.1
- [highlight.js](https://npm.io/package/highlight.js.md) ^11.8.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.1.2 (latest) — 2023-09-06
- 1.1.1 — 2023-09-04
- 1.1.0 — 2023-09-04
- 1.0.0 — 2023-08-31

## README

# Git提交时推送到别的平台



由于本人写笔记一一直都是写 markdown 然后提交的github，再配合 docsify 生成的静态站点，搭的也有博客，但是很少去更新

我就想能不能在提交到github的时候顺带把笔记也推到自己的博客网站呢？

git虽然有钩子函数，但是对于不经常写shell的人来说很难上手，于是就用nodejs实现了下面这套逻辑：



```mermaid
graph TD
    A[git staus 获取新增/更改/删除的文件] --> B[过滤]
    B --> C[内容推送到自己的博客/其他平台]
    C --> X[git commit]
    X --> Z[git push]
```



如果你不想提交到远程仓库，可以使用 `git init` 初始化一个本地仓库，把他当作一个命令行工具使用，不需要 `git push` 



**源码：** https://github.com/cloudlandboy/sync-post-commit



## 安装

```shell
npm install sync-post-commit -g
```



## 使用

1. 打开终端

2. 进入git项目目录

3. 提交

   ```shell
   sync-post-commit commit 'git commit message'
   ```



## 配置

你可以在控制台运行 `sync-post-commit config` 命令进行引导配置

也可以自己编辑配置文件，配置文件位于 `用户目录/.sync-post-commit/config.json`

```json
{
  "postImpl": "实现名称",
  "filter": {
    "mode": "disable|s|i|e|si|se",
    "extension": ["md"],
    "include|exclude": ["**/_sidebar.md","/README.md"]
  },
  "实现名称": {
    "实现配置xx": "xxValue",
    "modulePath": "/home/clboy/halo-impl.js"
  }
}
```



## 内置实现

- [x] halo ( 1.x版本 )
- [x] csdn
- [x] 语雀
- [x] 印象笔记 (支持代码高亮)
- [ ] 博客园 (TODO)
- [ ] 简书 (TODO)



## 自定义推送实现

示例 **impl.js**

```javascript
async function post(utils, context) {
    context = Object.assign({}, context);
    // 推送逻辑
}

async function configure(utils, implConfig) {
    return utils.prompts([{
        type: 'text',
        name: 'key',
        initial: implConfig ? implConfig.key : null,
        message: '配置xxx: ',
    }])
}
```



------

`utils` ：

- `fileExists(path)` : 判断文件是否存在，参数：文件绝对路径
- `removeBlankItem(stringArray)` : 删除字符串数组中的空白字符元素
- `extractMarkdownTitle(content)` : 提取markdown文档内容标题
- `getPureDateTime()` : 获取 `yyyyMMddHHmmss` 格式日期时间 
- `axios` :  [Axios](https://www.npmjs.com/package/axios) , http客户端
- `ora` : [ora](https://www.npmjs.com/package/ora) , 终端loading
- `prompts` : [prompts](https://www.npmjs.com/package/prompts) , 控制台交互
- `marked` : [marked](https://www.npmjs.com/package/marked) , markdown解析器

------

`context` : 

- `config` : 配置信息
- `implConfig` : 实现自己的配置部分信息
- `configFolderPath` : 配置文件所在目录绝对路径
- `repoPath` : 运行命令所在项目目录绝对路径
- `fileCount` : 本次预计推送文件总数
- `entitys` : 所有文件数据集合
  
  ```json
  [
      {
          "flag": "文件状态, c:创建, u:更新, d:删除",
          "content": "文件内容",
          "relativePath": "文件相对于项目的路径",
          "absolutePath": "文件绝对路径"
      }
  ]
  ```
  
- `syncRecordsFilePath` : 同步记录文件路径
- `refreshConfig()` : 更新配置到磁盘
- `getSyncRecords()` : 获取同步记录
- `flushSyncRecords()` : 更新同步记录到磁盘
  ```javascript
  context.getSyncRecords()[entity.relativePath] = res.data.data.article_id;
  context.flushSyncRecords();
  ```

---
_Source: https://npm.io/package/sync-post-commit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
