-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprocess.go
More file actions
107 lines (97 loc) · 2.76 KB
/
Copy pathprocess.go
File metadata and controls
107 lines (97 loc) · 2.76 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"bytes"
"net/http"
img "github.com/OhYee/goldmark-image"
"github.com/yuin/goldmark"
highlighting "github.com/yuin/goldmark-highlighting/v2"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
goldmarkHTML "github.com/yuin/goldmark/renderer/html"
)
var theme string
var md = goldmark.New()
var buf bytes.Buffer
func postToGhost(metadata map[string]interface{}, content string) {
injectMultiTitles(metadata)
if val, ok := metadata["code_hilite_theme"]; ok {
theme = val.(string)
log.Debug("Theme from markdown:", theme)
} else {
codeTheme := config.GetDefault("blog-configuration.CODE_HILITE_THEME", "").(string)
if codeTheme != "" {
theme = codeTheme
} else {
theme = "monokai" // Default theme if none is specified
}
log.Debug("Default/Global Configured theme:", theme)
}
md = goldmark.New(
goldmark.WithExtensions(
extension.GFM,
extension.Table,
img.NewImg("image", nil),
highlighting.NewHighlighting(
highlighting.WithStyle(theme),
),
),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
goldmarkHTML.WithHardWraps(),
goldmarkHTML.WithUnsafe(),
),
)
metadata = addBlogConfigurations(metadata)
metadata["html"] = toHTML(content)
token, err := getJWToken()
if err != nil {
log.Error("Failed generate jwt token: %v", err)
} else {
log.Debug("Generated jwt token")
}
headers := http.Header{}
headers.Set("Authorization", "Ghost "+token)
post, err := getPostId(metadata["slug"].(string), headers)
if err != nil {
log.Error("Error: Unable to communicate with the Ghost Admin API. Please verify your Ghost configurations: %v\n", err)
return
}
var pid, updated_at, htmlData, featureImage string
if post == nil {
log.Info("No post found for the given slug.")
} else {
pid, updated_at, htmlData, featureImage = post.ID, post.UpdatedAt, post.Mobiledoc, post.FeatureImage
}
if _, ok := metadata["feature_image"]; ok {
uploadFeatureImage(metadata, token, featureImage)
} else {
log.Fatal("Feature image not provided")
metadata["feature_image"] = ""
}
// Upload images
uploadedImages, err := uploadImages(token, htmlData)
if err != nil {
log.Error("Error uploading images:", err)
} else {
log.Info("Uploaded Blog Images")
}
// Upload Videos
uploadedVideos, err := uploadVideos(token, htmlData)
if err != nil {
log.Error("Error uploading videos:", err)
} else {
log.Info("Uploaded Blog Videos")
}
result, err := replaceMediaLinks(metadata, uploadedImages, uploadedVideos)
if err != nil {
log.Error("Error replacing image links:", err)
}
metadata["html"] = result
postObj := metadata
body := map[string]interface{}{
"posts": []map[string]interface{}{postObj},
}
makeRequest(headers, body, pid, updated_at)
}