Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
killers78 committed Mar 13, 2024
1 parent c6e29b0 commit 8a759ea
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions src/convert_md_2_html.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
package main

import (
"io/fs"
"io/ioutil"
"fmt"
"path/filepath"
"strings"
"github.com/russross/blackfriday/v2"
"io/fs"
"io/ioutil"
"fmt"
"path/filepath"
"strings"
"github.com/russross/blackfriday/v2"
)

func convertMarkdownToHTML(input string) (string, error) {
output := blackfriday.Run([]byte(input))
//fmt.Println("HTML: ", output)
return string(output), nil
output := blackfriday.Run([]byte(input))
//fmt.Println("HTML: ", output)
return string(output), nil
}

func processFile(path string, info fs.FileInfo, err error) error {
parts := strings.Split(path, "/")
parts := strings.Split(path, "/")

// Verifica se há pelo menos 3 partes (0-indexed)
if len(parts) >= 3 {
// Obtém o elemento na posição 2
platform := parts[2]
product := parts[3]
platform := parts[1]
product := parts[2]

fmt.Println("Segunda parte do caminho:", platform)
fmt.Println("Terceira parte do caminho:", product)

if strings.HasSuffix(path, ".md") {
input, err := ioutil.ReadFile(path)
if err != nil {
return err
}

htmlContent, err := convertMarkdownToHTML(string(input))
if err != nil {
return err
}

newPath := strings.TrimSuffix(path, ".md") + "-" + platform + "-" + product + ".html"
err = ioutil.WriteFile(newPath, []byte(htmlContent), info.Mode())
if err != nil {
return err
}
}
} else {
fmt.Println("O caminho não contém pelo menos 3 partes.")
}

if strings.HasSuffix(path, ".md") {
input, err := ioutil.ReadFile(path)
if err != nil {
return err
}

htmlContent, err := convertMarkdownToHTML(string(input))
if err != nil {
return err
}

newPath := strings.TrimSuffix(path, ".md") + "-" + platform + "-" + product + ".html"
err = ioutil.WriteFile(newPath, []byte(htmlContent), info.Mode())
if err != nil {
return err
}
}
return nil
return nil
}

func main() {
root := "./platforms" // Defina o diretório raiz conforme necessário
err := filepath.Walk(root, processFile)
if err != nil {
panic(err)
}
}

func main() {
root := "./platforms" // Defina o diretório raiz conforme necessário
err := filepath.Walk(root, processFile)
if err != nil {
panic(err)
}
}

0 comments on commit 8a759ea

Please sign in to comment.