迁移 Blog

| 分类 Blog  | 标签 blog  搬家  mwb 

将以前陆陆续续写的和收集的一些东西迁移到了 github 上来。Blog 主题 Copy 了 https://github.com/Linusp/Linusp.github.io

之前我的 Blog 都是通过 mwb 来管理,发布到了 cnblogsis-programmer 上。Blog 的迁移并不复杂:

  • 通过 mwb 获取所有已经发布的文章

    Emacs 中输入:

    M-x: mwb-get-recent-posts
    

    填写个数字之后将近期的 Blog 取下来。

  • 遍历所有取道的文章并更新到 Github 上

    这个可以用 elisp 来实现:

    ;;; -*- emacs-lisp -*- -*- coding: utf-8; -*-
    ;;;
    ;;; File: mwb-to-github.io
    ;;; Author: YangYingchao <yangyingchao@gmail.com>
    ;;;
    ;;;
    
    
    (defun yc/get-mwb-content (fn)
      "Get metadata of mwb"
      ;; Load variables if metadata exists.
      (message "Processing %s" fn)
      (let* ((content
              (with-temp-buffer
                (insert-file-contents fn)
                (read (set-marker (make-marker) 0 (current-buffer)))))
             (bfn (yc/string-replace
                   (yc/string-replace
                    (yc/string-replace
                     (yc/string-replace (cdr (assoc "title" content))
                                        " " "-")
                     "/" "_"
                     )")" "_")
                   "(" "_"))
             (date-cons (cadr (cdr (assoc "dateCreated" content))))
             (date (format-time-string   "%Y-%m-%d"  (list (car date-cons) (cadr date-cons) 0 0 )))
             )
    
        (with-temp-file (format
                         "/home/yyc/Work/yangyingchao.github.io/_posts/%s-%s.html"
                         date
                         bfn)
          (insert "---
    layout     : post
    ")
          (insert "title : "(or (cdr (assoc "title" content)) "Unamed?" ) "\n")
          (insert "categories : "(or (car (cdr (assoc "categories" content))) "未分类")  "\n")
          (insert (concat  "\n---\n" (cdr (assoc "description" content))) "\n")
          )
        )
      )
    
    ;; (yc/get-mwb-content "/home/yyc/Documents/MetaWebBlog/posts/68215")
    
    (dolist (var (directory-files "/home/yyc/Documents/MetaWebBlog/posts" t))
      (message "Processing %s" var)
      (if (not (file-directory-p var))
          (yc/get-mwb-content var)      )
    
      )
    

    Eval 上面的代码后,所有文章都更新到了 github.io 所在的 repository,之后全部添加并上传即可。

  • 简单测试下 ditaa

test_ditaa.png


上一篇     下一篇