鍚堝苟鏈湴浠撳簱鍜岃繙绋嬩粨搴

This commit is contained in:
trogloxene
2026-03-17 22:32:09 +08:00
parent 3e2a7d8dd0
commit 279a050165
5 changed files with 96 additions and 4 deletions

View File

@@ -47,4 +47,84 @@
;; ...other commands here
))
;; hugo
(with-eval-after-load 'org-capture
(defun org-hugo-new-subtree-post-capture-template ()
"Returns `org-capture' template string for new Hugo post.
See `org-capture-templates' for more information."
(let* ((title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title
(fname (org-hugo-slug title)))
(mapconcat #'identity
`(
,(concat "* TODO " title)
":PROPERTIES:"
,(concat ":EXPORT_FILE_NAME: " fname)
":END:"
"\n\n") ;Place the cursor here finally
"\n")))
(add-to-list 'org-capture-templates
'("h" ;`org-capture' binding + h
"Hugo post"
entry
;; It is assumed that below file is present in `org-directory'
;; and that it has a "Blog Ideas" heading. It can even be a
;; symlink pointing to the actual location of all-posts.org!
(file+headline "d:/emacs/hugo/this-is-my-blog/all-blog.org" "Blog Ideas")
(function org-hugo-new-subtree-post-capture-template))))
;; 快速部署
(defun my-blog-publish ()
"publish blog , git add/commit/push , generate commit message"
(interactive)
(let* ((blog-dir "d:/emacs/hugo/this-is-my-blog/")
(timestamp (format-time-string "%Y-%m-%d %H:%M:%S"))
(default-directory blog-dir))
;; save buffer
(save-buffer)
;; git add
(message "Adding files...")
(eshell-command "git add .")
;; git commit with timestamp
(message "Committing: %s" timestamp)
(eshell-command (format "git commit -m \"Update: %s\"" timestamp))
;; git push
(message "Pushing to remote...")
(let ((exit-code (eshell-command "git push")))
(if (eq exit-code t)
(message "Push may have failed or nothing to push, check *Messages* buffer for details")
(message "Push successfully %s" timestamp)))))
(global-set-key (kbd "C-c o p") 'my-blog-publish)
;; 预览博客
(defun my-blog-preview ()
(interactive)
(save-buffer)
(let ((default-directory "d:/emacs/hugo/this-is-my-blog/"))
;; 启动 Hugo server
(start-process "hugo-server" "*hugo-server*"
"hugo" "server" "-D" "--bind" "0.0.0.0" "--port" "1313")
;; 等待服务器启动
(sleep-for 2)
;; 自动打开浏览器
(browse-url "http://localhost:1313")))
(global-set-key (kbd "C-c o v") 'my-blog-preview)
;; org tempo
;; (require 'org-tempo)
;; 批量调整表格
(defun org-table-align-all ()
"Ajust all org table in current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(org-table-map-tables 'org-table-align t)))
(provide 'init-org)