{"id":23413429,"url":"https://github.com/tinyfunction/docusaurus-blogs-changes-to-workwechat","last_synced_at":"2025-04-09T04:46:30.702Z","repository":{"id":269122130,"uuid":"906112395","full_name":"TinyFunction/docusaurus-blogs-changes-to-workwechat","owner":"TinyFunction","description":"A Github Action for send docusaurus blogs changes to work-wechat.","archived":false,"fork":false,"pushed_at":"2024-12-21T08:45:38.000Z","size":496,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-14T23:20:13.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TinyFunction.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-20T07:33:42.000Z","updated_at":"2024-12-21T08:44:49.000Z","dependencies_parsed_at":"2024-12-21T05:18:46.125Z","dependency_job_id":"92319e09-8ccd-4aa0-b97f-9e75f338b593","html_url":"https://github.com/TinyFunction/docusaurus-blogs-changes-to-workwechat","commit_stats":null,"previous_names":["tinyfunction/docusaurus-blogs-changes-to-workwechat"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyFunction%2Fdocusaurus-blogs-changes-to-workwechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyFunction%2Fdocusaurus-blogs-changes-to-workwechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyFunction%2Fdocusaurus-blogs-changes-to-workwechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyFunction%2Fdocusaurus-blogs-changes-to-workwechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TinyFunction","download_url":"https://codeload.github.com/TinyFunction/docusaurus-blogs-changes-to-workwechat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980820,"owners_count":21027803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-22T19:35:49.827Z","updated_at":"2025-04-09T04:46:30.684Z","avatar_url":"https://github.com/TinyFunction.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docusaurus-blogs-changes-to-workwechat-action\n\n[English](./README.md) | [中文](./README_CN.md)\n\nA GitHub Action to detect changes in Docusaurus blog posts and send notifications to a Work-WeChat robot. This action is specifically designed for projects using Docusaurus with blogs stored in a specified directory (default: `blog`).\n\n---\n\n## 🚀 Features\n\n- Detects **newly added** and **updated** blog posts in your Docusaurus blog directory.\n- Sends notifications with a customizable message template to a Work-WeChat robot.\n- Supports integration with GitHub Pages for generating blog URLs.\n- Fully configurable inputs for flexibility in different Docusaurus setups.\n\n---\n\n## 🛠 Prerequisites\n\n### 1. Use `actions/checkout@v3` with `fetch-depth` set to `0` or a value greater than `1`.\n\nTo properly detect blog changes, this action requires the ability to compare the current commit (`HEAD`) with its parent commit (`HEAD^`). If the repository has only one commit (e.g., in a shallow clone with `fetch-depth: 1`), the action will output:\n\n```\nInitial commit detected. Skipping blog change detection.\n```\n\nHere is how you should configure `actions/checkout@v3` in your workflow:\n\n```yaml\n- name: Checkout repository\n  uses: actions/checkout@v3\n  with:\n    fetch-depth: 2  # Recommended: fetch at least the last two commits\n```\n\n---\n\n## 📦 Inputs\n\n| **Input Name**     | **Description**                                                                                                    | **Required** | **Default**                     |\n| ------------------ | ------------------------------------------------------------------------------------------------------------------ | ------------ | ------------------------------- |\n| `wechat_webhook`   | The webhook URL for your Work-WeChat robot.                                                                        | ✅ Yes        | N/A                             |\n| `base_url`         | The base URL of your GitHub Pages site (e.g., `https://\u003cyourusername\u003e.github.io/\u003cyourrepo\u003e`).                      | ✅ Yes        | N/A                             |\n| `blog_dir`         | The directory where your blog posts are stored.                                                                    | ❌ No         | `blog`                          |\n| `message_template` | The template of the message to send. Supports placeholders for `addedBlogs`, `updatedBlogs`, `github.*` variables. | ❌ No         | **See default template below.** |\n\n### **Default Message Template**\nThe default message template for Work-WeChat notifications is:\n\n```\n**📢 博客变更通知**\n分支: ${github.ref_name}\n提交信息: ${github.event.head_commit.message}\n提交人: ${github.actor}\n\n**新增博客文章**:\n${addedBlogs || '无新增博客'}\n\n**更新博客文章**:\n${updatedBlogs || '无更新博客'}\n```\n\nYou can customize this template to match your requirements. There are three `${github.*}` variables supported.\n\n| variables     | Github Actions variables         |\n| ------------- | -------------------------------- |\n| refName       | ref_name                         |\n| commitMessage | github.event.head_commit.message |\n| actor         | github.actor                     |\n\n---\n\n## 🔧 Example Usage\n\nHere is an example of how to use `docusaurus-blogs-changes-to-workwechat-action` in a GitHub Actions workflow:\n\n```yaml\nname: Blog Changes Notifier\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  notify:\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout repository\n        uses: actions/checkout@v3\n        with:\n          fetch-depth: 2  # Ensure we can compare HEAD with HEAD^\n\n      - name: Detect blog changes and send notifications\n        uses: TinyFunction/docusaurus-blogs-changes-to-workwechat@v1.0.0\n        with:\n          wechat_webhook: ${{ secrets.WECHAT_WEBHOOK }}\n          base_url: \"https://yourusername.github.io/yourrepo\"\n          blog_dir: \"blog\"  # Optional: Defaults to \"blog\"\n          message_template: |\n            **📢 博客变更通知**\n            仓库: ${github.repository}\n            分支: ${github.ref_name}\n            提交人: ${github.actor}\n\n            **新增博客文章**:\n            ${addedBlogs || '无新增博客'}\n\n            **更新博客文章**:\n            ${updatedBlogs || '无更新博客'}\n```\n\n---\n\n## 🧩 How It Works\n\n1. The action runs `git diff` to compare the current commit (`HEAD`) with its parent (`HEAD^`).\n2. It detects changes in the specified blog directory (default: `blog`) and categorizes files into:\n   - **New Blog Posts**: Newly added Markdown files.\n   - **Updated Blog Posts**: Modified Markdown files.\n3. It parses the `frontmatter` of each Markdown file to extract the `slug` (or uses the file name if `slug` is missing).\n4. It constructs URLs for the changed blog posts using the provided `base_url`.\n5. It sends a Work-WeChat notification using the `wechat_webhook` URL, with the message content based on the `message_template`.\n\n---\n\n## 🛠 Debugging\n\nIf something goes wrong, the following steps can help:\n- Ensure `fetch-depth` is set to `2` or `0` in `actions/checkout@v3`.\n- Check the Work-WeChat webhook URL in your GitHub Secrets (`WECHAT_WEBHOOK`).\n- Add debug logs to your workflow:\n  ```yaml\n  - name: Debug action\n    run: echo \"Added Blogs: ${{ env.addedBlogs }}, Updated Blogs: ${{ env.updatedBlogs }}\"\n  ```\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions! Here’s how you can get involved:\n\n1. **Report Bugs**: If you encounter any issues, please open an issue in the [GitHub repository](https://github.com/TinyFunction/docusaurus-blogs-changes-to-workwechat/issues).\n2. **Suggest Features**: Have an idea to improve this action? Open a feature request in the Issues section.\n3. **Submit Pull Requests**:\n   - Fork the repository.\n   - Make your changes.\n   - Submit a pull request with a clear explanation of the changes.\n\n### Development Guide\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/TinyFunction/docusaurus-blogs-changes-to-workwechat.git\n   cd docusaurus-blogs-changes-to-workwechat\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Build the project:\n   ```bash\n   npm run build\n   ```\n\n4. Test your changes locally.\n\n---\n\n## 📝 License\n\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT).\n\n---\n\n## 🛡 Security\n\nEnsure that sensitive data like `wechat_webhook` is stored securely in GitHub Secrets and not hardcoded in workflows.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyfunction%2Fdocusaurus-blogs-changes-to-workwechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyfunction%2Fdocusaurus-blogs-changes-to-workwechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyfunction%2Fdocusaurus-blogs-changes-to-workwechat/lists"}