代码拉取完成,页面将自动刷新
同步操作将从 阿债/fountain 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"flag"
"fmt"
"os"
"plugin"
"runtime"
"fountain/article"
"fountain/utils"
bf2 "gopkg.in/russross/blackfriday.v2"
)
const VERSION = "0.41.2"
var (
serve bool //运行WEB服务
port uint //服务端口
root string //博客根目录
theme string //皮肤主题
clean bool //清理旧输出
verbose bool //输出详情
)
func init() {
flag.BoolVar(&serve, "s", false, "运行WEB服务")
flag.UintVar(&port, "p", 0, "服务端口")
flag.StringVar(&root, "r", "", "博客根目录")
flag.StringVar(&theme, "t", "", "皮肤主题")
flag.BoolVar(&clean, "c", false, "清理旧输出")
flag.BoolVar(&verbose, "v", false, "输出详情")
flag.Usage = usage
flag.Parse()
}
func usage() {
desc := `fountain version: v%s
Usage: fountain [-t theme] [-r root] [-p port] [-scv]
Options:
`
fmt.Fprintf(os.Stderr, desc, VERSION)
flag.PrintDefaults()
}
func main() {
if runtime.GOOS == "windows" {
name := "Fountain"
desc := "Fountain Static Blog Server"
utils.WinMain(name, desc, run)
} else {
run()
}
}
func run() {
site := article.NewWebsite(root)
site.LoadConfig("config.yml")
if theme != "" {
site.Conf.Theme = theme
}
site.Convert = Convert
site.Debug = func(data ...interface{}) {
if verbose {
fmt.Println(data...)
}
}
if serve || port > 0 {
if port == 0 || port > 65535 {
port = site.Conf.Port
}
fmt.Printf("Server at :%d\n", port)
} else {
if clean {
fmt.Println("Clean ...")
if len(site.Conf.Public) >= 3 {
pubDir := site.Root + site.Conf.Public
utils.CleanDir(pubDir)
}
}
fmt.Println("Build ...")
site.InitTheme()
site.BuildFiles()
}
}
func WithOptions(flags bf2.HTMLFlags) bf2.Option {
params := bf2.HTMLRendererParameters{Flags: flags}
renderer := bf2.NewHTMLRenderer(params)
return bf2.WithRenderer(renderer)
}
func Convert(source []byte, format string) []byte {
if format == "" {
return source
} else if format == "markdown" {
flags := bf2.CommonHTMLFlags | bf2.TOC
return bf2.Run(source, WithOptions(flags))
}
plug, err := plugin.Open("./" + format + ".so")
if err != nil {
panic(err)
}
symb, err := plug.Lookup("Convert")
if err != nil {
panic(err)
}
conv := symb.(func(source []byte) []byte)
return conv(source)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。