master
xuthus5 4 months ago
commit 23136281f1
  1. 4
      .gitignore
  2. 21
      cmd.go
  3. 1
      deploy.go
  4. 10
      go.mod
  5. 25
      init.go
  6. 1
      page.go
  7. 1
      post.go
  8. 1
      serve.go
  9. 16
      utils.go

4
.gitignore vendored

@ -0,0 +1,4 @@
.vscode/
.idea/
*.exe
go.sum

@ -0,0 +1,21 @@
package main
import (
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "mder",
Short: "mder is a very fast static site generator",
}
)
func init() {
// create a new mder folder
rootCmd.AddCommand(initCmd())
}
func main() {
rootCmd.Execute()
}

@ -0,0 +1 @@
package main

@ -0,0 +1,10 @@
module mder
go 1.18
require github.com/spf13/cobra v1.5.0
require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)

@ -0,0 +1,25 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
func initCmd() *cobra.Command {
var name string
cmd := &cobra.Command{
Use: "init",
Short: "create a new mder folder",
Run: func(cmd *cobra.Command, args []string) {
if err := cloneTemplate(name); err != nil {
panic(err)
}
_, _ = fmt.Fprintf(os.Stdout, "create folder %s success.\n", name)
},
}
cmd.Flags().StringVar(&name, "name", "mder", "Name of the folder to create")
return cmd
}

@ -0,0 +1 @@
package main

@ -0,0 +1 @@
package main

@ -0,0 +1 @@
package main

@ -0,0 +1,16 @@
package main
import (
"fmt"
"os"
"os/exec"
)
func cloneTemplate(base string) error {
_, err := exec.Command("git", "clone", "https://gitter.top/mder/template", base).Output()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "get latest template failed: %v\n", err)
return err
}
return nil
}
Loading…
Cancel
Save