-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |