精简hugo文章发布操作

策略选取:powershell函数 之前情况:创建文章需要切换到hugo目录,再用hugo命令,发布网站则需要3个git命令。 改善之后:创建文章: np ‘文章名’ ; 发布网站: 一、创建文章: 1. 创建powershell配置文件 1 2 3 4 5 6 7 8 # 检查配置文件是否存在 Test-Path $PROFILE # 如果返回 False,创建配置文件 if (!(Test-Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force Write-Host "已创建 PowerShell 配置文件" -ForegroundColor Green } 2. 记事本打开文件并复制函数 1 2 # 用记事本打开配置文件 notepad $PROFILE PowerShell的函数 a.中文版:存在shell编码与函数编码不一致问题(前者中文编码,后者utf-8) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 function New-Post { param( [Parameter(Mandatory=$true)] [string]$Title ) # 保存当前目录 $currentLocation = Get-Location try { # 设置网站路径(!!!!!! hugo网站的根目录) $websitePath = "C:\Users\amebo\MyFreshWebsite" # 检查目录是否存在 if (-not (Test-Path $websitePath)) { Write-Host "错误:找不到目录 $websitePath" -ForegroundColor Red return } # 检查 Hugo 是否安装 if (-not (Get-Command hugo -ErrorAction SilentlyContinue)) { Write-Host "错误:未找到 hugo 命令" -ForegroundColor Red return } # 切换到网站目录并创建文章(!!!!核心操作:创建md) Set-Location $websitePath Write-Host "正在创建文章: $Title..." -ForegroundColor Yellow hugo new "posts/$Title.md" if ($LASTEXITCODE -eq 0) { Write-Host "成功创建文章:posts/$Title.md" -ForegroundColor Green } else { Write-Host "创建文章失败" -ForegroundColor Red } } finally { # 返回原始目录 Set-Location $currentLocation } } # 设置别名 Set-Alias -Name newpost -Value New-Post Set-Alias -Name np -Value New-Post Write-Host "New-Post 函数已加载!使用方法: np `"文章名称`"" -ForegroundColor Green b. 英文版:不存在编码问题 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 # 1. 创建英文版本的函数内容 $englishContent = @' function New-Post { param( [Parameter(Mandatory=$true)] [string]$Title ) $current = Get-Location $websitePath = "C:\Users\amebo\MyFreshWebsite" if (-not (Test-Path $websitePath)) { Write-Host "Error: Directory not found" -ForegroundColor Red return } if (-not (Get-Command hugo -ErrorAction SilentlyContinue)) { Write-Host "Error: hugo not found" -ForegroundColor Red return } Set-Location $websitePath Write-Host "Creating post: $Title..." -ForegroundColor Yellow hugo new "posts/$Title.md" if ($LASTEXITCODE -eq 0) { Write-Host "Success: posts/$Title.md created" -ForegroundColor Green } else { Write-Host "Failed to create post" -ForegroundColor Red } Set-Location $current } Set-Alias np New-Post Set-Alias newpost New-Post Write-Host "New-Post function loaded. Use: np `"PostTitle`"" -ForegroundColor Green '@ # 2. 保存到配置文件(使用ASCII编码) $englishContent | Out-File -FilePath $PROFILE -Encoding ASCII # 3. 重新加载配置文件 . $PROFILE 效果: ...

September 2, 2025 · 3 min · 509 words · Bob

HOW TO INTEREST PEOPLE

Everyone who was ever a guest of Theodore Roosevelt was astonished at the range and diversity of his knowledge. Whether his visitor was a cowboy or a Rough Rider, a New York politician or a diplomat, Roosevelt knew what to say. And how was it done? The answer was simple. Whenever Roosevelt expected a visitor, he sat up late the night before, reading up on the subject in which he knew his guest was particularly interested. For Roosevelt knew, as all leaders know, that the royal road to a person’s heart is to talk about the things he or she treasures most. The genial William Lyon Phelps, essayist and professor of literature at Yale, learned this lesson early in life. “When I was eight years old and was spending a weekend visiting my Aunt Libby Linsley at her home in Stratford on the Housatonic,” he wrote in his essay on Human Nature, “a middle-aged man called one evening, and after a polite skirmish with my aunt, he devoted his attention to me. At that time, I happened to be excited about boats, and the visitor discussed the subject in a way that seemed to me particularly interesting. After he left, I spoke of him with enthusiasm. What a man! My aunt informed me he was a New York lawyer, that he cared nothing whatever about boats—that he took not the slightest interest in the subject. ‘But why then did he talk all the time about boats?’ “‘Because he is a gentleman. He saw you were interested in boats, and he talked about the things he knew would interest and please you. He made himself agreeable.’” And William Lyon Phelps added, “I never forgot my aunt’s remark.” As I write this chapter, I have before me a letter from Edward L. Chalif, who was active in Boy Scout work. “One day I found I needed a favor,” wrote Mr. Chalif. “A big Scout jamboree was coming off in Europe, and I wanted the president of one of the largest corporations in America to pay the expenses of one of my boys for the trip. “Fortunately, just before I went to see this man, I heard that he had drawn a check for a million dollars, and that after it was canceled, he had had it framed. “So the first thing I did when I entered his office was to ask to see the check. A check for a million dollars! I told him I never knew that anybody had ever written such a check, and that I wanted to tell my boys that I had actually seen a check for a million dollars. He gladly showed it to me; I admired it and asked him to tell me all about how it happened to be drawn.” You notice, don’t you, that Mr. Chalif didn’t begin by talking about the Boy Scouts, or the jamboree in Europe, or what it was he wanted? He talked in terms of what interested the other man. Here’s the result: “Presently, the man I was interviewing said, ‘Oh, by the way, what was it you wanted to see me about?’ So I told him. “To my vast surprise,” Mr. Chalif continues, “he not only granted immediately what I asked for, but much more. I had asked him to send only one boy to Europe, but he sent five boys and myself, gave me a letter of credit for a thousand dollars and told us to stay in Europe for seven weeks. He also gave me letters of introduction to his branch presidents, putting them at our service, and he himself met us in Paris and showed us the town. ...

July 15, 2025 · 7 min · 1393 words · Bob

AI开发blog遇到的问题

遇到的问题 初始化项目结构 前后端没有自动在对应的目录下构建 选用错误的技术栈:修正后前端bootstrap,后端knife4j 业务逻辑没有在后端实现:修改后将数据库触发器业务逻辑放在了后端 配置中间件及数据源 这里使用docker 国内docker源不生效 为docker配置国内源时,一直不生效,重启电脑和手动重启docker均无效,在命令行中输入下面代码问题解决了。 1 2 3 docker system prune -a # 清理所有缓存 net stop com.docker.service net start com.docker.service 开始开发前端部分 新提议:开始前生成页面设计文档,每完成一项便打勾一项。

1 min · 26 words · Bob

理解AI开发的博客程序

Docker 配置数据源和中间件 1 docker-compose up -d mysql redis 命令组成: docker-compose:调用容器编排工具 up:核心操作指令,会根据配置文件创建/重建容器 -d:表示以分离模式(后台)运行‌ 执行流程: 首先检查当前目录下的docker-compose.yml文件 创建所需的网络和存储卷 按依赖顺序启动MySQL和Redis容器‌ 1 docker exec bs-blog-mysql mysqladmin ping -h localhost -u root -p123456 命令结构: docker exec:在运行中的容器内执行命令 bs-blog-mysql:目标容器名称 mysqladmin ping:MySQL管理工具的健康检查指令 -h localhost:指定连接本地MySQL实例 -u root:使用root账户连接 -p123456:指定数据库密码 预期响应: 若服务正常会返回 mysqld is alive 若连接失败可能返回 Access denied 或连接超时错误

1 min · 47 words · Bob

理解苍穹外卖项目

全局异常处理 通过创建一个基础异常类,该类继承运行时异常, 1 2 3 4 5 6 7 8 9 10 11 12 13 /** * 业务异常 */ public class BaseException extends RuntimeException { public BaseException() { } public BaseException(String msg) { super(msg); } } 而项目中所有业务异常都继承该基础异常类(BaseException) 一个全局异常处理器,处理BaseException,业务流程中抛出的异常,经过该全局异常处理器的捕捉,最后通过一个统一的结果对象返回给前端 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 /** * 全局异常处理器,处理项目中抛出的业务异常 */ @RestControllerAdvice @Slf4j public class GlobalExceptionHandler { /** * 捕获业务异常 * @param ex * @return */ @ExceptionHandler public Result exceptionHandler(BaseException ex){ log.error("异常信息:{}", ex.getMessage()); return Result.error(ex.getMessage()); } } 统一的返回结果类Result,定义了重载的success静态方法(分别对应有无返回数据),和一个静态error方法。 ...

19 min · 3873 words · Bob

重大技术栈转变

重大技术栈转变 关于目前在学企业级技术栈SpringBoot 生态向 Node.js生态转换的决定 为了统一所学技术栈,终结前后端语言割裂的现象,践行全端(前后、移动、PC) 也便于日后JavaScript向TypeScript转变 Node.js Express 是 Node.js的一个库,提供了一些扩展: Express对 Node.js 的 HTTP 模块进行了封装,提供了更加简洁和灵活的 API 来构建 Web 应用和 API。 功能对比 特性 Node.js 原生 Express 路由处理 需手动解析 URL 和方法 提供简洁的路由 API 中间件支持 需自行实现 内置中间件机制 请求处理 需手动解析请求体 提供 body-parser 等工具 响应处理 需手动设置响应头 简化的响应方法 静态文件服务 需手动实现 一行代码搞定 错误处理 需自行处理 统一错误处理机制 现代 Node.js 技术栈 1. 框架生态 Express: 最流行的轻量级框架 Koa: Express 的下一代框架 Fastify: 高性能 Web 框架 NestJS: 受 Angular 和Spring 启发的企业级框架 Hapi: 配置驱动的框架 2. 适用实时应用 Node.js 的事件驱动和非阻塞 I/O 特性使其非常适合实时应用 ...

2 min · 246 words · Bob