Skip to content

Instantly share code, notes, and snippets.

@locona
Last active May 28, 2018 13:09
Show Gist options
  • Save locona/654be5e0c156a3479f097ff082096a60 to your computer and use it in GitHub Desktop.
Save locona/654be5e0c156a3479f097ff082096a60 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"text/template"
// "html/template"
)
var temp = `
<Card className={classes.card}>
<img
style={ImgStyle}
src={{ .Src | print }}
alt="{{.Alt}}" />
</Card>
`
func main() {
imports()
}
func card() {
path := "path"
files, err := ioutil.ReadDir(path)
if err != nil {
panic(err)
}
file, err := os.OpenFile("card", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
defer file.Close()
if err != nil {
panic(err)
}
for idx := range files {
fname := files[idx].Name()
parts := strings.Split(fname, ".")
t := template.New("card")
t, _ = t.Parse(temp)
value := struct {
Src string
Alt string
}{
fmt.Sprintf("{ %s }", parts[0]),
parts[0],
}
t.Execute(file, value)
}
}
func imports() {
path := "path"
files, err := ioutil.ReadDir(path)
if err != nil {
panic(err)
}
file, err := os.OpenFile("import", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
defer file.Close()
if err != nil {
panic(err)
}
for idx := range files {
fname := files[idx].Name()
parts := strings.Split(fname, ".")
l := fmt.Sprintf("import %s from './images/%s';\n", parts[0], fname)
file.WriteString(l)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment