使用 gptel 帮助生成博客的 url
背景: 经常需要写博客,又期望定制一个符合博文主题的 url,以前是自己去 Google translate 翻译然后改成 slug 格式(全小写,连字符连接)。 像这篇文章的格式: using-gptel-to-generate-blog-urls 现在有 llm 之后,会开一个 deepseek 的网页或者 ChatGPT 的网页,设置基础 prompt,然后就将中文的文章名称发给它,让他给出对应的英文 最近我想到也许可以将这个步骤通过一个 elisp 函数来实现,最终基于 gptel 加上一些简单的 elisp 代码实现了整个流程。 完整代码: (defun my/gptel-gen-hugo-properties () "Generate Hugo export properties for current Org heading." (interactive) (unless (org-at-heading-p) (user-error "必须在 Org 模式标题位置使用")) (gptel-request (format "将中文标题转换为英文 slug(全小写,连字符连接): 需要翻译的原文:「%s」" (string-trim (org-get-heading t t t t))) :system "只返回转换后的字符串" :callback (lambda (response info) (when-let* ((raw response) (slug (replace-regexp-in-string "\\([^a-z0-9]\\|-\\)+" "-" (downcase raw) nil t))) (org-set-property "EXPORT_HUGO_BUNDLE" slug) (org-set-property "EXPORT_FILE_NAME" "index.zh") (message "生成成功:%s" slug))))) 使用方法: ...