编写生成CNAME的插件

写了个插件(plugin),在Publish编译并发布站点到github时,自动产生自定义的域名文件(CNAME),放在output目录下。

实现

import Foundation
import Publish

public extension Plugin {
    static func genCNAME(with name: String) -> Self {
        Plugin(name: "GenerateCNAME") { context in
            if !name.isEmpty {
                try context.createOutputFile(at: "CNAME").write("\(name)\n")
            }
        }
    }
}

调用

try ChengzhenyuBlog().publish(
    using: [
        // ...
        .installPlugin(.genCNAME(with: "chengzhenyu.com")),
        .unwrap(.gitHub("chengzhenyu/chengzhenyu.github.io"), PublishingStep.deploy)
    ]
)
学习插画实现播放音乐