You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.8 KiB
Go

package main
import (
"os"
"path/filepath"
)
func cleanUpPublicHTML(hugo *Hugo, hook *Hook) {
if hook.Publish {
if _, err := os.Stat(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName)); err == nil {
err := os.RemoveAll(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName))
check(err)
err = os.MkdirAll(hook.PublicHTMLPath, 0755)
check(err)
}
} else if _, err := os.Lstat(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview")); err == nil {
err := os.RemoveAll(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
check(err)
} else if _, err := os.Stat(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview")); err == nil {
err := os.RemoveAll(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
check(err)
}
}
func copyToPublicHTML(hugo *Hugo, hook *Hook) {
if hook.Publish {
err := os.Rename(hugo.DestinationDir, filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName))
check(err)
err = os.Symlink(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName), filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
check(err)
if hugo.CatalogPrefix != "" && hugo.CatalogName != "" {
err = os.Symlink(filepath.Join(hook.PublicHTMLPath, "libraries", hugo.CatalogName), filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, hugo.CatalogPrefix))
check(err)
}
} else {
err := os.MkdirAll(filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName), 0755)
check(err)
err = os.Rename(hugo.DestinationDir, filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
check(err)
if hugo.CatalogPrefix != "" && hugo.CatalogName != "" {
err = os.Symlink(filepath.Join(hook.PublicHTMLPath, "libraries", hugo.CatalogName), filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview", hugo.CatalogPrefix))
check(err)
}
}
}