feat: random source directory

master
xuthus5 4 months ago
parent ff5e291ad4
commit 548350ca15
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
  1. 13
      config.go
  2. 15
      output.go
  3. 8
      utils.go

@ -4,12 +4,13 @@ import "time"
// Config 配置文件
type Config struct {
Title string `yaml:"title"` // 网站标题
Seo SEO `yaml:"seo"` // seo相关信息
Person Person `yaml:"person"` // 博主个人信息
Theme string `yaml:"theme"` // 主题
Site Site `yaml:"site"` // 站点配置信息
Now time.Time // 当前时间
Title string `yaml:"title"` // 网站标题
Seo SEO `yaml:"seo"` // seo相关信息
Person Person `yaml:"person"` // 博主个人信息
Theme string `yaml:"theme"` // 主题
Site Site `yaml:"site"` // 站点配置信息
Now time.Time // 当前时间
SourceVersion string // 资源版本号
}
type Site struct {

@ -9,6 +9,7 @@ import (
"runtime"
"sort"
"text/template"
"time"
)
type Outter struct {
@ -40,6 +41,7 @@ type PostData struct {
// check 检测目标
func (o *Outter) check() {
o.Config.SourceVersion = Md5(time.Now().String())[:10]
var args []string
switch runtime.GOOS {
case "windows":
@ -60,6 +62,10 @@ func (o *Outter) check() {
sfault("create dist directory failed: %v", err)
}
}
if err := mkdir("./dist/" + o.Config.SourceVersion); err != nil {
sfault("create source directory failed: %v", err)
}
}
func (o *Outter) createDir(fp string) error {
@ -80,19 +86,20 @@ func (o *Outter) sourceCopy() {
default:
args = []string{"cp", "-r"}
}
themePath := slash(fmt.Sprintf("./themes/%s/", o.Config.Theme))
destPath := slash("./dist/")
cmd := exec.Command(args[0], append(args, themePath+"css", slash(destPath+"css/"))...)
destPath := slash(fmt.Sprintf("./dist/%s/", o.Config.SourceVersion))
cmd := exec.Command(args[0], append(args[1:], themePath+"css", slash(destPath+"css/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme css source failed: %v", err)
}
cmd = exec.Command(args[0], append(args, themePath+"js", slash(destPath+"js/"))...)
cmd = exec.Command(args[0], append(args[1:], themePath+"js", slash(destPath+"js/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme js source failed: %v", err)
}
cmd = exec.Command(args[0], append(args, themePath+"images", slash(destPath+"images/"))...)
cmd = exec.Command(args[0], append(args[1:], themePath+"images", slash(destPath+"images/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme images source failed: %v", err)

@ -1,6 +1,8 @@
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"os/exec"
@ -136,3 +138,9 @@ func slash(str string) string {
}
return str
}
func Md5(src string) string {
h := md5.New()
h.Write([]byte(src))
return hex.EncodeToString(h.Sum(nil))
}

Loading…
Cancel
Save