-
Notifications
You must be signed in to change notification settings - Fork 89
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
1 parent
bcf1ce3
commit 6d809fb
Showing
6 changed files
with
129 additions
and
78 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
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package chat_gpt_ppt | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type MarpRenderer struct { | ||
BinPath string | ||
Topics []*Topic | ||
} | ||
|
||
func NewMarpRenderer() Renderer { | ||
return &MarpRenderer{ | ||
BinPath: "", | ||
Topics: make([]*Topic, 0), | ||
} | ||
} | ||
|
||
func (m *MarpRenderer) SetBinPath(path string) { | ||
m.BinPath = path | ||
} | ||
|
||
func (m *MarpRenderer) AddTopic(topic *Topic) { | ||
m.Topics = append(m.Topics, topic) | ||
} | ||
|
||
func (m *MarpRenderer) RenderFile(outputPath string) error { | ||
parts := make([]string, 0) | ||
for _, each := range m.Topics { | ||
parts = append(parts, each.ToMarkdown()) | ||
} | ||
final := strings.Join(parts, "\n---\n") | ||
|
||
// call marp | ||
file, err := os.CreateTemp(os.TempDir(), "cgp*.md") | ||
if err != nil { | ||
return err | ||
} | ||
defer os.Remove(file.Name()) | ||
err = os.WriteFile(file.Name(), []byte(final), 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
command := exec.Command(m.BinPath, file.Name(), "-o", outputPath) | ||
err = command.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package chat_gpt_ppt | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const RemarkTemplate = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Title</title> | ||
<meta charset="utf-8"> | ||
<style> | ||
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz); | ||
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic); | ||
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic); | ||
body { font-family: 'Droid Serif'; } | ||
h1, h2, h3 { | ||
font-family: 'Yanone Kaffeesatz'; | ||
font-weight: normal; | ||
} | ||
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; } | ||
</style> | ||
</head> | ||
<body> | ||
<textarea id="source"> | ||
class: center, middle | ||
%s | ||
</textarea> | ||
<script src="https://remarkjs.com/downloads/remark-latest.min.js"> | ||
</script> | ||
<script> | ||
var slideshow = remark.create(); | ||
</script> | ||
</body> | ||
</html> | ||
` | ||
|
||
type RemarkRenderer struct { | ||
Topics []*Topic | ||
} | ||
|
||
func NewRemarkRenderer() Renderer { | ||
return &RemarkRenderer{ | ||
Topics: make([]*Topic, 0), | ||
} | ||
} | ||
|
||
func (r *RemarkRenderer) AddTopic(topic *Topic) { | ||
r.Topics = append(r.Topics, topic) | ||
} | ||
|
||
func (r *RemarkRenderer) RenderFile(outputPath string) error { | ||
parts := make([]string, 0) | ||
for _, each := range r.Topics { | ||
parts = append(parts, each.ToMarkdown()) | ||
} | ||
final := strings.Join(parts, "\n---\n") | ||
|
||
outputContent := fmt.Sprintf(RemarkTemplate, final) | ||
err := os.WriteFile(outputPath, []byte(outputContent), 0644) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (r *RemarkRenderer) SetBinPath(_ string) { | ||
} |