hexo-llm-tagging v3.2.2
Hexo LLM Tagging Plugin
A Hexo plugin that uses OpenAI's LLM (Large Language Model) to automatically generate categories and tags for your blog posts based on their content.
Features
- Automatic Tagging: Analyzes post content using OpenAI's API to generate a single category and 2-5 relevant tags.
- Seamless Integration: Works with Hexo's
before_post_renderfilter to updatefront-matterwithout altering post content. - Configurable: Supports custom OpenAI models, API keys, and endpoints via Hexo configuration.
- Debugging Support: Detailed logging for troubleshooting and verification.
Installation
Install the Plugin: Run the following command in your Hexo project directory:
npm install hexo-llm-tagging --saveInstall Dependencies: Ensure the required dependencies are installed:
npm install openai markdown-it html-to-text hexo-front-matter hexo-fs
Configuration
Add the following configuration to your Hexo _config.yml file:
llm_tagging:
api_key: "your-openai-api-key"
model: "gpt-3.5-turbo" # or any other supported model
endpoint: "https://api.openai.com/v1" # optional, defaults to OpenAI's API
max_tokens: 100 # optional, defaults to 100api_key: Your OpenAI API key (required).model: The OpenAI model to use (required).endpoint: Custom API endpoint (optional).max_tokens: Maximum tokens for the API response (optional).
Usage
Write Your Posts: Create or edit Markdown files in the
_postsdirectory as usual. The plugin will process them automatically.Generate Site: Run Hexo generation to tag your posts:
hexo generate --debugUse
--debugto see detailed logs of the tagging process.Check Results:
- The plugin updates the
categoriesandtagsin thefront-matterof each post. - Example before:
--- title: Better MC 个人汉化 date: 2023-12-12 19:55:38 ---  ## 整合包介绍 ... - Example after:
--- title: Better MC 个人汉化 categories: - 游戏模组 tags: - Minecraft - 汉化 - Better MC - 模组整合包 - Forge date: 2023-12-12 19:55:38 ---  ## 整合包介绍 ...
- The plugin updates the
How It Works
- Content Analysis: The plugin extracts plain text from your Markdown content using
markdown-itandhtml-to-text. - LLM Processing: Sends the title and content to OpenAI's API, requesting a single category and 2-5 tags in JSON format.
- Front-matter Update: Updates the
front-matterwith the generatedcategoriesandtags, preserving the original post content. - Rendering Sync: Ensures the updated metadata is reflected in Hexo's rendering process.
Logging
- Info: Logs when a post is processed and tagged successfully.
- Debug: Provides detailed output, including
front-matterupdates and rendering states. - Error: Reports issues like API failures or configuration errors.
Example debug output:
INFO Processing post: Better MC 个人汉化
INFO Tagged post: Better MC 个人汉化 - Category: 游戏模组, Tags: Minecraft, 汉化, Better MC, 模组整合包, Forge
DEBUG Before render - Title: Better MC 个人汉化, Categories: ["游戏模组"], Tags: ["Minecraft", "汉化", "Better MC", "模组整合包", "Forge"]Troubleshooting
- API Errors: Ensure your
api_keyis valid and you have network access to the OpenAI endpoint. - Missing Tags: Check if
max_tokensis sufficient for the API response. - Content Not Tagged: Verify that the post is in the
_postsdirectory and contains readable content.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.