<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title><![CDATA[ERAIN]]></title> 
<atom:link href="https://erain.cc/rss.php" rel="self" type="application/rss+xml" />
<description><![CDATA[探索科技边界，连接艺术与生活 —— 发现未来的无限可能]]></description>
<link>https://erain.cc/</link>
<language>zh-cn</language>
<generator>www.emlog.net</generator>
<item>
    <title>Emlog-MCP：基于 Model Context Protocol 的智能博客管理工具</title>
    <link>https://erain.cc/post-7.html</link>
    <description><![CDATA[<h1>Emlog-MCP：基于 Model Context Protocol 的智能博客管理工具</h1>
<h2>项目简介</h2>
<p>我很高兴向大家介绍我开发的一个创新项目——<strong>Emlog-MCP</strong>，这是一个基于 Model Context Protocol (MCP) 的 Emlog 博客系统集成服务。该项目允许 AI 助手（如 Claude）通过标准化接口与 Emlog 博客进行无缝交互，实现智能化的博客管理和内容创作。</p>
<h2>项目背景与动机</h2>
<p>随着 AI 技术的快速发展，越来越多的内容创作者希望能够利用 AI 助手来提高工作效率。然而，传统的博客系统往往缺乏与 AI 工具的直接集成能力。为了解决这个问题，我开发了 Emlog-MCP，它基于 Anthropic 推出的 Model Context Protocol，为 Emlog 博客系统提供了完整的 AI 集成解决方案。</p>
<h2>核心功能特性</h2>
<h3>🔗 资源管理 (Resources)</h3>
<p>Emlog-MCP 提供了丰富的资源访问接口：</p>
<ul>
<li><strong>博客文章</strong> (<code>emlog://articles</code>) - 获取所有博客文章列表</li>
<li><strong>分类管理</strong> (<code>emlog://categories</code>) - 获取所有分类信息</li>
<li><strong>评论系统</strong> (<code>emlog://comments</code>) - 获取评论列表</li>
<li><strong>微语笔记</strong> (<code>emlog://notes</code>) - 获取微语笔记列表</li>
<li><strong>用户信息</strong> (<code>emlog://user</code>) - 获取当前用户信息</li>
</ul>
<h3>🛠️ 智能工具 (Tools)</h3>
<p>项目提供了完整的博客管理工具集：</p>
<h4>文章管理</h4>
<ul>
<li><strong>create_article</strong> - 创建新的博客文章</li>
<li><strong>update_article</strong> - 更新现有博客文章</li>
<li><strong>get_article</strong> - 获取指定文章详情</li>
<li><strong>search_articles</strong> - 智能搜索文章（支持关键词、标签、分类等筛选）</li>
</ul>
<h4>互动功能</h4>
<ul>
<li><strong>like_article</strong> - 为文章点赞</li>
<li><strong>add_comment</strong> - 添加评论</li>
<li><strong>get_comments</strong> - 获取指定文章的评论列表</li>
</ul>
<h4>内容创作</h4>
<ul>
<li><strong>create_note</strong> - 创建微语笔记</li>
<li><strong>upload_file</strong> - 上传文件（图片等媒体资源）</li>
<li><strong>get_user_info</strong> - 获取用户信息</li>
</ul>
<h2>技术架构</h2>
<h3>技术栈选择</h3>
<p>项目采用了现代化的技术栈：</p>
<ul>
<li><strong>TypeScript</strong> - 提供类型安全保障</li>
<li><strong>Node.js</strong> - 高性能的 JavaScript 运行时</li>
<li><strong>MCP SDK</strong> - Model Context Protocol TypeScript SDK</li>
<li><strong>Axios</strong> - 可靠的 HTTP 客户端库</li>
<li><strong>Zod</strong> - TypeScript 优先的模式验证库</li>
<li><strong>form-data</strong> - 多部分表单数据处理</li>
</ul>
<h3>架构设计</h3>
<p>项目采用模块化设计，主要包含：</p>
<ol>
<li><strong>MCP 服务器核心</strong> (<code>src/index.ts</code>) - 处理 MCP 协议通信</li>
<li><strong>Emlog 客户端</strong> (<code>src/emlog-client.ts</code>) - 封装 Emlog API 调用</li>
<li><strong>类型定义</strong> - 完整的 TypeScript 类型支持</li>
<li><strong>配置管理</strong> - 灵活的环境变量配置</li>
</ol>
<h2>安装与使用指南</h2>
<h3>快速开始（推荐方式）</h3>
<p>最简单的使用方式是直接在 Claude Desktop 中配置 <code>emlog-mcp</code>：</p>
<ol>
<li>
<p><strong>配置 Claude Desktop</strong><br />
在 Claude Desktop 的配置文件中添加：</p>
<pre><code class="language-json">{
 "mcpServers": {
   "emlog": {
     "command": "npx",
     "args": ["emlog-mcp"],
     "env": {
       "EMLOG_API_URL": "https://your-blog.com",
       "EMLOG_API_KEY": "your_api_key"
     }
   }
 }
}</code></pre>
</li>
<li>
<p><strong>获取 API 密钥</strong></p>
<ul>
<li>登录 Emlog 后台管理系统</li>
<li>进入「设置」→「API 接口」</li>
<li>启用 API 功能并生成 API 密钥</li>
</ul>
</li>
<li>
<p><strong>开始使用</strong><br />
重启 Claude Desktop，即可开始使用 AI 助手管理您的博客！</p>
</li>
</ol>
<h3>本地开发安装</h3>
<p>如果您想要进行二次开发或本地调试：</p>
<pre><code class="language-bash"># 克隆项目
git clone https://github.com/eraincc/emlog-mcp.git
cd emlog-mcp

# 安装依赖
npm install

# 配置环境变量
cp .env.example .env
# 编辑 .env 文件，设置您的 API URL 和密钥

# 构建项目
npm run build

# 运行服务
npm start</code></pre>
<h2>使用场景与优势</h2>
<h3>🚀 提升创作效率</h3>
<ul>
<li><strong>智能写作助手</strong>：AI 可以帮助生成文章大纲、优化内容结构</li>
<li><strong>批量内容管理</strong>：快速处理大量文章的分类、标签等元数据</li>
<li><strong>自动化发布</strong>：根据预设规则自动发布定时内容</li>
</ul>
<h3>📊 数据分析与洞察</h3>
<ul>
<li><strong>内容分析</strong>：AI 可以分析文章表现，提供优化建议</li>
<li><strong>用户互动</strong>：智能回复评论，提升用户参与度</li>
<li><strong>SEO 优化</strong>：自动优化文章标题、描述等 SEO 元素</li>
</ul>
<h3>🔄 工作流程优化</h3>
<ul>
<li><strong>多平台同步</strong>：轻松将内容同步到多个平台</li>
<li><strong>内容审核</strong>：AI 辅助内容质量检查</li>
<li><strong>数据备份</strong>：自动化的内容备份和迁移</li>
</ul>
<h2>安全性考虑</h2>
<p>项目在设计时充分考虑了安全性：</p>
<ul>
<li><strong>API 密钥加密</strong>：支持签名验证和免签名两种鉴权方式</li>
<li><strong>环境变量管理</strong>：敏感信息通过环境变量安全存储</li>
<li><strong>类型安全</strong>：TypeScript 提供编译时类型检查</li>
<li><strong>输入验证</strong>：使用 Zod 进行严格的数据验证</li>
</ul>
<h2>开源贡献</h2>
<p>作为一个开源项目，Emlog-MCP 欢迎社区贡献：</p>
<ul>
<li><strong>GitHub 仓库</strong>：<a href="https://github.com/eraincc/emlog-mcp">https://github.com/eraincc/emlog-mcp</a></li>
<li><strong>许可证</strong>：MIT License</li>
<li><strong>问题反馈</strong>：通过 GitHub Issues 提交 bug 报告和功能请求</li>
<li><strong>代码贡献</strong>：欢迎提交 Pull Request</li>
</ul>
<h2>未来规划</h2>
<p>我计划在未来版本中添加以下功能：</p>
<ul>
<li>支持更多博客系统（WordPress、Typecho 等）</li>
<li>增强的 AI 内容生成能力</li>
<li>可视化的博客数据分析面板</li>
<li>更丰富的自动化工作流</li>
<li>移动端管理应用</li>
</ul>
<h2>结语</h2>
<p>Emlog-MCP 项目代表了我对 AI 与内容管理系统结合的探索和实践。通过这个项目，我希望能够为广大博客作者和内容创作者提供更智能、更高效的创作工具。</p>
<p>如果您对这个项目感兴趣，欢迎：</p>
<ul>
<li>⭐ 在 GitHub 上给项目点星</li>
<li>🐛 提交 bug 报告和功能建议</li>
<li>🤝 参与项目开发和改进</li>
<li>📢 分享给更多有需要的朋友</li>
</ul>
<p>让我们一起推动 AI 辅助内容创作的发展，让创作变得更加简单和高效！</p>]]></description>
    <pubDate>Sat, 21 Jun 2025 22:45:47 +0800</pubDate>
    <dc:creator>Yiklam</dc:creator>
    <guid>https://erain.cc/post-7.html</guid>
</item>
<item>
    <title>Linux下安装Anaconda及查看、创建、切换虚拟环境</title>
    <link>https://erain.cc/linux-anaconda.html</link>
    <description><![CDATA[<h1>安装Anaconda</h1>
<blockquote>
<p>推荐更稳定的离线安装，需要下载Anaconda的安装包。</p>
</blockquote>
<p>安装包从<a href="https://repo.anaconda.com/archive/" title="Anaconda官网">Anaconda官网</a>或者<a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/" title="清华大学镜像站">清华大学镜像站</a></p>
<p>这里使用Anaconda官网安装包，命令行下载：</p>
<pre><code class="language-bash">wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh</code></pre>
<h2>bash安装</h2>
<pre><code class="language-bash">bash Anaconda3-2023.09-0-Linux-x86_64.sh</code></pre>
<p>看到下列提示直接回车</p>
<pre><code class="language-bash">Welcome to Anaconda3 2023.09-0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
&gt;&gt;&gt;</code></pre>
<p>看到下列许可提示，直接yes就好：</p>
<pre><code class="language-bash">==================================================
End User License Agreement - Anaconda Distribution
==================================================

Copyright 2015-2023, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:
...
Do you accept the license terms? [yes|no]
[no] &gt;&gt;&gt; yes</code></pre>
<p>然后选择安装位置，直接回车默认就好：</p>
<pre><code class="language-bash">Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/anaconda3] &gt;&gt;&gt; </code></pre>
<p>下面会让选择是否初始化base环境，yes就好，之后也可以配置。</p>
<pre><code class="language-bash">PREFIX=/root/anaconda3
Unpacking payload ...

Installing base environment...

Downloading and Extracting Packages

Downloading and Extracting Packages

Preparing transaction: done
Executing transaction: / 

    Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
    More details are available here: https://intel.github.io/scikit-learn-intelex

    For example:

        $ conda install scikit-learn-intelex
        $ python -m sklearnex my_application.py

done
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
   run the following command when conda is activated:

conda config --set auto_activate_base false

You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] &gt;&gt;&gt; yes</code></pre>
<p>看到如下提示就表示Anaconda3安装成功</p>
<pre><code class="language-bash">no change     /root/anaconda3/condabin/conda
no change     /root/anaconda3/bin/conda
no change     /root/anaconda3/bin/conda-env
no change     /root/anaconda3/bin/activate
no change     /root/anaconda3/bin/deactivate
no change     /root/anaconda3/etc/profile.d/conda.sh
no change     /root/anaconda3/etc/fish/conf.d/conda.fish
no change     /root/anaconda3/shell/condabin/Conda.psm1
no change     /root/anaconda3/shell/condabin/conda-hook.ps1
no change     /root/anaconda3/lib/python3.11/site-packages/xontrib/conda.xsh
no change     /root/anaconda3/etc/profile.d/conda.csh
modified      /root/.bashrc

==&gt; For changes to take effect, close and re-open your current shell. &lt;==

Thank you for installing Anaconda3!</code></pre>
<p>这时需要重新登录终端，检查conda是否正常。<br />
重新登录以后输入</p>
<pre><code class="language-bash">conda env list</code></pre>
<p>如果列出所有环境列表，表示conda一切正常了。</p>
<pre><code class="language-bash"># conda environments:
#
base                  *  /root/anaconda3</code></pre>
<h2>安装成功后建议更新一下Anaconda</h2>
<pre><code class="language-bash">conda update -y conda</code></pre>
<blockquote>
<p>注意：conda更新只能在base环境下进行</p>
</blockquote>
<h1>查看、创建、切换虚拟环境</h1>
<p>使用conda命令，可以方便的创建和切换各版本的python虚拟环境。</p>
<h2>查看现有虚拟环境</h2>
<pre><code class="language-bash">conda env list</code></pre>
<h2>创建虚拟环境</h2>
<p>在命令行输入如下命令</p>
<pre><code class="language-bash">conda create --name newEnvName python=3.9</code></pre>
<h2>切换虚拟环境</h2>
<pre><code class="language-bash">conda activate newEnvName</code></pre>
<h2>退出当前虚拟环境</h2>
<pre><code class="language-bash">conda deactivate</code></pre>
<h1>小妙招</h1>
<p>默认情况下，系统会进入base虚拟环境，只要编辑.bashrc文件</p>
<pre><code class="language-bash">vim ~/.bashrc</code></pre>
<p>在最后加入</p>
<pre><code class="language-bash">conda activate newEnvName</code></pre>
<p>即可在下次登录系统后直接进入newEnvName的虚拟环境。</p>]]></description>
    <pubDate>Wed, 10 Jan 2024 15:38:00 +0800</pubDate>
    <dc:creator>Yiklam</dc:creator>
    <guid>https://erain.cc/linux-anaconda.html</guid>
</item>
<item>
    <title>Golang使用Decimal库避免运算中精度损失</title>
    <link>https://erain.cc/golang-decimal.html</link>
    <description><![CDATA[<h1>前言</h1>
<p>我们在项目中涉及到数值计算时，如果直接使用golang的运算符，会造成精度的损失，例如：</p>
<pre><code class="language-go">a := 1136.1
b := a * 100
fmt.Println(b) // 正确结果应该是 113610 但输出 113609.99999999999

c := 1.7
fmt.Println(a - c) // 正确结果应该是 1134.4 但输出 1134.3999999999999
fmt.Println(b - c) // 正确结果应该是 113608.3 但输出 113608.29999999999</code></pre>
<p>那么如何避免这种情况呢？golang中没有提供对于精度运算相应的包。这里需要用到第三方的decimal包了。</p>
<hr />
<h1>一、Decimal库是什么？</h1>
<p>是一个第三方提供的用于go程序数值计算时避免精度损失的包，引用官方的描述：</p>
<pre><code>Arbitrary-precision fixed-point decimal numbers in go.

Note: Decimal library can "only" represent numbers with a maximum of 2^31 digits after the decimal point.</code></pre>
<p><code>注意这里有个Note：Decimal库“只能”表示小数点后最多2^31位的数字。当然，这对于绝大部分项目来说足够了。</code></p>
<h1>二、使用步骤</h1>
<h2>1.引入库</h2>
<p>下载包：</p>
<pre><code class="language-shell">go get github.com/shopspring/decimal</code></pre>
<p>go代码中引入包：</p>
<pre><code class="language-go">import "github.com/shopspring/decimal"</code></pre>
<h2>2.Decimal库的使用</h2>
<p>使用decimal后，上面例子的代码就应该这样写：</p>
<pre><code class="language-go">package main

import (
    "fmt"
    "github.com/shopspring/decimal"
)

func main() {
    a := decimal.NewFromFloat(1136.1)
    b := a.Mul(decimal.NewFromInt(100))
    fmt.Println(b) // 正确输出 113610

    c := decimal.NewFromFloat(1.7)
    fmt.Println(a.Sub(c)) // 正确输出 1134.4
    fmt.Println(b.Sub(c)) // 正确输出 113608.3
}</code></pre>
<p>之后对于各种数字的计算就会变得得心应手：</p>
<pre><code class="language-go">package main

import (
    "fmt"
    "github.com/shopspring/decimal"
)

func main() {
    a := decimal.NewFromFloat(1.52)
    b := decimal.NewFromFloat(0.02)

    // 加减乘除运算
    c := a.Add(b) // 1.52 + 0.02 = 1.54
    d := a.Sub(b) // 1.52 - 0.02 = 1.5
    e := a.Mul(b) // 1.52 * 0.02 = 0.0304
    f := a.Div(b) // 1.52 / 0.02 = 76
    fmt.Println(a, b, c, d, e, f)

    // 对于保留小数的处理
    pi := decimal.NewFromFloat(3.1415926535897932384626)
    pi1 := pi.Round(3)    // 对pi值四舍五入保留3位小数
    fmt.Println(pi1)       // 3.142
    pi2 := pi.Truncate(3) // 对pi值保留3位小数之后直接舍弃
    fmt.Println(pi2)       // 3.141
}</code></pre>
<p>对于数值变量类型的转换也游刃有余了：</p>
<pre><code class="language-go">var a float64
var b = "69.77"
var c int64

d, err := decimal.NewFromString(b)
if err != nil {
    fmt.Println(err.Error())
}

a, _ = d.Float64()
fmt.Println(a) // float64 69.77

c = d.IntPart() // 舍去小数取整
fmt.Println(c)  // int64 69

b = decimal.NewFromInt(c).String()
fmt.Println(b) // string 69

c = d.Round(0).IntPart() // 不保留小数四舍五入取整
fmt.Println(c)           // int64 70</code></pre>
<p>这里列出一些常用的方法：</p>
<pre><code class="language-go">n1 := decimal.NewFromFloat(-1.23)
n2 := decimal.NewFromInt(3)
n3, _ := decimal.NewFromString("0")

n1.Abs()                  // 取绝对值
n1.Equal(n2)              // n1 是否与 n2 相等
n1.LessThan(n2)           // n1 是否小于 n2
n1.LessThanOrEqual(n2)    // n1 是否小于或等于 n2
n1.GreaterThan(n2)        // n1 是否大于 n2
n1.GreaterThanOrEqual(n2) // n1 是否大于或等于 n2
n3.IsZero()               // n3 是否为0</code></pre>
<hr />
<h1>总结</h1>
<p>Decimal库会给我们项目中用到数值计算时提供极大的便利和安全性。<br />
最后需要注意的一点是，使用Decimal库的变量数据类型全部为decimal.Decimal，同样decimal.Decimal也可以作为声明变量时的数据类型使用，所以记得在最后做变量赋值时转换为需要的数据类型。</p>
<pre><code class="language-go">package main

import (
    "fmt"
    "github.com/shopspring/decimal"
    "reflect"
)

func main() {
    n1 := decimal.NewFromFloat(3.14)
    var n2 string
    var n3 float64
    var n4 int64
    var n5 decimal.Decimal

    n2 = n1.String()
    n3, _ = n1.Float64()
    n4 = n1.IntPart()

    fmt.Printf("n1 = %v, type = %v\n", n1, reflect.TypeOf(n1).String())
    // n1 = 3.14, type = decimal.Decimal
    fmt.Printf("n2 = %v, type = %v\n", n2, reflect.TypeOf(n2).String())
    // n2 = 3.14, type = string
    fmt.Printf("n3 = %v, type = %v\n", n3, reflect.TypeOf(n3).String())
    // n3 = 3.14, type = float64
    fmt.Printf("n4 = %v, type = %v\n", n4, reflect.TypeOf(n4).String())
    // n4 = 3, type = int64
    fmt.Printf("n5 = %v, type = %v\n", n5, reflect.TypeOf(n5).String())
    // n5 = 0, type = decimal.Decimal
}</code></pre>]]></description>
    <pubDate>Wed, 27 Dec 2023 23:44:00 +0800</pubDate>
    <dc:creator>Yiklam</dc:creator>
    <guid>https://erain.cc/golang-decimal.html</guid>
</item></channel>
</rss>