-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi.go
70 lines (59 loc) · 1.28 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"bufio"
"fmt"
"os"
"strings"
"regexp"
"os/exec"
"log"
)
func main() {
f, err := os.Open("config.toml")
if err != nil {
fmt.Println("Error reading config.toml") //return 0, err
}
// Splits on newlines by default.
scanner := bufio.NewScanner(f)
cont := 0
lang := make([]string, 0)
defaultLanguage := ""
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "DefaultContentLanguage") {
re := regexp.MustCompile(`(".*?")`)
defaultLanguage = re.FindString(line)
defaultLanguage = defaultLanguage[1:len(defaultLanguage)-1]
}
matched, _ := regexp.MatchString(`\[languages\..+\]`, line)
if matched {
lang = append(lang, line)
cont++
}
}
lv := len("languages") + 4
rv := ""
i := 0
source := ""
destiny := ""
for _, v := range lang {
long := len(v)
rv = v[lv:long-1]
i++
if (rv == defaultLanguage) {
source = "public/index.html"
destiny = "public/" + rv + ".tex"
} else {
source = "public/" + rv + "/index.html"
destiny = "public/" + rv + ".tex"
}
cmd := exec.Command("mv", source, destiny)
err5 := cmd.Run()
if err5 != nil {
log.Fatal(err5)
}
}
if err := scanner.Err(); err != nil {
// Handle the erro
}
}