mirror of
https://gitlab.melroy.org/melroy/fediresolve.git
synced 2025-06-07 20:08:57 +00:00
Add poll results in case of a question type
This commit is contained in:
parent
7d49479cc6
commit
1a8bcb5bf9
1 changed files with 78 additions and 60 deletions
|
@ -32,25 +32,25 @@ func Format(data map[string]interface{}) (string, error) {
|
||||||
// createSummary generates a human-readable summary of the ActivityPub object
|
// createSummary generates a human-readable summary of the ActivityPub object
|
||||||
func createSummary(jsonStr string) string {
|
func createSummary(jsonStr string) string {
|
||||||
objectType := gjson.Get(jsonStr, "type").String()
|
objectType := gjson.Get(jsonStr, "type").String()
|
||||||
|
|
||||||
// Build a header with the object type
|
// Build a header with the object type
|
||||||
bold := color.New(color.Bold).SprintFunc()
|
bold := color.New(color.Bold).SprintFunc()
|
||||||
cyan := color.New(color.FgCyan).SprintFunc()
|
cyan := color.New(color.FgCyan).SprintFunc()
|
||||||
green := color.New(color.FgGreen).SprintFunc()
|
green := color.New(color.FgGreen).SprintFunc()
|
||||||
yellow := color.New(color.FgYellow).SprintFunc()
|
yellow := color.New(color.FgYellow).SprintFunc()
|
||||||
red := color.New(color.FgRed).SprintFunc()
|
red := color.New(color.FgRed).SprintFunc()
|
||||||
|
|
||||||
header := fmt.Sprintf("%s: %s\n", bold("Type"), cyan(objectType))
|
header := fmt.Sprintf("%s: %s\n", bold("Type"), cyan(objectType))
|
||||||
|
|
||||||
// Add common fields
|
// Add common fields
|
||||||
var summaryParts []string
|
var summaryParts []string
|
||||||
summaryParts = append(summaryParts, header)
|
summaryParts = append(summaryParts, header)
|
||||||
|
|
||||||
// Add ID if available
|
// Add ID if available
|
||||||
if id := gjson.Get(jsonStr, "id").String(); id != "" {
|
if id := gjson.Get(jsonStr, "id").String(); id != "" {
|
||||||
summaryParts = append(summaryParts, fmt.Sprintf("%s: %s", bold("ID"), green(id)))
|
summaryParts = append(summaryParts, fmt.Sprintf("%s: %s", bold("ID"), green(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process based on type
|
// Process based on type
|
||||||
switch objectType {
|
switch objectType {
|
||||||
case "Person", "Application", "Group", "Organization", "Service":
|
case "Person", "Application", "Group", "Organization", "Service":
|
||||||
|
@ -68,7 +68,7 @@ func createSummary(jsonStr string) string {
|
||||||
case "Tombstone":
|
case "Tombstone":
|
||||||
summaryParts = formatTombstone(jsonStr, summaryParts, bold, green)
|
summaryParts = formatTombstone(jsonStr, summaryParts, bold, green)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(summaryParts, "\n")
|
return strings.Join(summaryParts, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,31 +77,31 @@ func formatActor(jsonStr string, parts []string, bold, cyan, green, red, yellow
|
||||||
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), cyan(name)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), cyan(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if preferredUsername := gjson.Get(jsonStr, "preferredUsername").String(); preferredUsername != "" {
|
if preferredUsername := gjson.Get(jsonStr, "preferredUsername").String(); preferredUsername != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Username"), red(preferredUsername)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Username"), red(preferredUsername)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if url := gjson.Get(jsonStr, "url").String(); url != "" {
|
if url := gjson.Get(jsonStr, "url").String(); url != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("URL"), green(url)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("URL"), green(url)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if summary := gjson.Get(jsonStr, "summary").String(); summary != "" {
|
if summary := gjson.Get(jsonStr, "summary").String(); summary != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Summary"), summary))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Summary"), summary))
|
||||||
}
|
}
|
||||||
|
|
||||||
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), yellow(formatDate(published))))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), yellow(formatDate(published))))
|
||||||
}
|
}
|
||||||
|
|
||||||
if followers := gjson.Get(jsonStr, "followers").String(); followers != "" {
|
if followers := gjson.Get(jsonStr, "followers").String(); followers != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Followers"), green(followers)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Followers"), green(followers)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if following := gjson.Get(jsonStr, "following").String(); following != "" {
|
if following := gjson.Get(jsonStr, "following").String(); following != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Following"), green(following)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Following"), green(following)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func formatContent(jsonStr string, parts []string, bold, green func(a ...interfa
|
||||||
}
|
}
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Content"), content))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Content"), content))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for attachments (images, videos, etc.)
|
// Check for attachments (images, videos, etc.)
|
||||||
attachments := gjson.Get(jsonStr, "attachment").Array()
|
attachments := gjson.Get(jsonStr, "attachment").Array()
|
||||||
if len(attachments) > 0 {
|
if len(attachments) > 0 {
|
||||||
|
@ -125,12 +125,12 @@ func formatContent(jsonStr string, parts []string, bold, green func(a ...interfa
|
||||||
mediaType := attachment.Get("mediaType").String()
|
mediaType := attachment.Get("mediaType").String()
|
||||||
url := attachment.Get("url").String()
|
url := attachment.Get("url").String()
|
||||||
name := attachment.Get("name").String()
|
name := attachment.Get("name").String()
|
||||||
|
|
||||||
// Truncate long descriptions
|
// Truncate long descriptions
|
||||||
if len(name) > 100 {
|
if len(name) > 100 {
|
||||||
name = name[:97] + "..."
|
name = name[:97] + "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentInfo := fmt.Sprintf(" %d. %s", i+1, green(attachmentType))
|
attachmentInfo := fmt.Sprintf(" %d. %s", i+1, green(attachmentType))
|
||||||
if mediaType != "" {
|
if mediaType != "" {
|
||||||
attachmentInfo += fmt.Sprintf(" (%s)", mediaType)
|
attachmentInfo += fmt.Sprintf(" (%s)", mediaType)
|
||||||
|
@ -139,37 +139,55 @@ func formatContent(jsonStr string, parts []string, bold, green func(a ...interfa
|
||||||
attachmentInfo += fmt.Sprintf(": %s", name)
|
attachmentInfo += fmt.Sprintf(": %s", name)
|
||||||
}
|
}
|
||||||
parts = append(parts, attachmentInfo)
|
parts = append(parts, attachmentInfo)
|
||||||
|
|
||||||
if url != "" {
|
if url != "" {
|
||||||
parts = append(parts, fmt.Sprintf(" URL: %s", url))
|
parts = append(parts, fmt.Sprintf(" URL: %s", url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if updated := gjson.Get(jsonStr, "updated").String(); updated != "" {
|
if updated := gjson.Get(jsonStr, "updated").String(); updated != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Updated"), formatDate(updated)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Updated"), formatDate(updated)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if attributedTo := gjson.Get(jsonStr, "attributedTo").String(); attributedTo != "" {
|
if attributedTo := gjson.Get(jsonStr, "attributedTo").String(); attributedTo != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Author"), attributedTo))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Author"), attributedTo))
|
||||||
}
|
}
|
||||||
|
|
||||||
if to := gjson.Get(jsonStr, "to").Array(); len(to) > 0 {
|
if to := gjson.Get(jsonStr, "to").Array(); len(to) > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("To"), formatArray(to)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("To"), formatArray(to)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc := gjson.Get(jsonStr, "cc").Array(); len(cc) > 0 {
|
if cc := gjson.Get(jsonStr, "cc").Array(); len(cc) > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("CC"), formatArray(cc)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("CC"), formatArray(cc)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if inReplyTo := gjson.Get(jsonStr, "inReplyTo").String(); inReplyTo != "" {
|
if inReplyTo := gjson.Get(jsonStr, "inReplyTo").String(); inReplyTo != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("In Reply To"), inReplyTo))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("In Reply To"), inReplyTo))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include endTime for Question type
|
||||||
|
if endTime := gjson.Get(jsonStr, "endTime").String(); endTime != "" {
|
||||||
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("End Time"), formatDate(endTime)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include options (oneOf/anyOf) for Question type
|
||||||
|
options := gjson.Get(jsonStr, "oneOf").Array()
|
||||||
|
if len(options) == 0 {
|
||||||
|
options = gjson.Get(jsonStr, "anyOf").Array()
|
||||||
|
}
|
||||||
|
if len(options) > 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("%s:", bold("Poll Options")))
|
||||||
|
for i, opt := range options {
|
||||||
|
name := opt.Get("name").String()
|
||||||
|
parts = append(parts, fmt.Sprintf(" %d. %s", i+1, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,13 +196,13 @@ func formatActivity(jsonStr string, parts []string, bold, green, yellow func(a .
|
||||||
if actor := gjson.Get(jsonStr, "actor").String(); actor != "" {
|
if actor := gjson.Get(jsonStr, "actor").String(); actor != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Actor"), actor))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Actor"), actor))
|
||||||
}
|
}
|
||||||
|
|
||||||
if object := gjson.Get(jsonStr, "object").String(); object != "" {
|
if object := gjson.Get(jsonStr, "object").String(); object != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Object"), object))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Object"), object))
|
||||||
} else if gjson.Get(jsonStr, "object").IsObject() {
|
} else if gjson.Get(jsonStr, "object").IsObject() {
|
||||||
objectType := gjson.Get(jsonStr, "object.type").String()
|
objectType := gjson.Get(jsonStr, "object.type").String()
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Object Type"), yellow(objectType)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Object Type"), yellow(objectType)))
|
||||||
|
|
||||||
if content := gjson.Get(jsonStr, "object.content").String(); content != "" {
|
if content := gjson.Get(jsonStr, "object.content").String(); content != "" {
|
||||||
content = stripHTML(content)
|
content = stripHTML(content)
|
||||||
if len(content) > 300 {
|
if len(content) > 300 {
|
||||||
|
@ -192,7 +210,7 @@ func formatActivity(jsonStr string, parts []string, bold, green, yellow func(a .
|
||||||
}
|
}
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Content"), content))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Content"), content))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for attachments in the object
|
// Check for attachments in the object
|
||||||
attachments := gjson.Get(jsonStr, "object.attachment").Array()
|
attachments := gjson.Get(jsonStr, "object.attachment").Array()
|
||||||
if len(attachments) > 0 {
|
if len(attachments) > 0 {
|
||||||
|
@ -202,12 +220,12 @@ func formatActivity(jsonStr string, parts []string, bold, green, yellow func(a .
|
||||||
mediaType := attachment.Get("mediaType").String()
|
mediaType := attachment.Get("mediaType").String()
|
||||||
url := attachment.Get("url").String()
|
url := attachment.Get("url").String()
|
||||||
name := attachment.Get("name").String()
|
name := attachment.Get("name").String()
|
||||||
|
|
||||||
// Truncate long descriptions
|
// Truncate long descriptions
|
||||||
if len(name) > 100 {
|
if len(name) > 100 {
|
||||||
name = name[:97] + "..."
|
name = name[:97] + "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentInfo := fmt.Sprintf(" %d. %s", i+1, green(attachmentType))
|
attachmentInfo := fmt.Sprintf(" %d. %s", i+1, green(attachmentType))
|
||||||
if mediaType != "" {
|
if mediaType != "" {
|
||||||
attachmentInfo += fmt.Sprintf(" (%s)", mediaType)
|
attachmentInfo += fmt.Sprintf(" (%s)", mediaType)
|
||||||
|
@ -216,22 +234,22 @@ func formatActivity(jsonStr string, parts []string, bold, green, yellow func(a .
|
||||||
attachmentInfo += fmt.Sprintf(": %s", name)
|
attachmentInfo += fmt.Sprintf(": %s", name)
|
||||||
}
|
}
|
||||||
parts = append(parts, attachmentInfo)
|
parts = append(parts, attachmentInfo)
|
||||||
|
|
||||||
if url != "" {
|
if url != "" {
|
||||||
parts = append(parts, fmt.Sprintf(" URL: %s", url))
|
parts = append(parts, fmt.Sprintf(" URL: %s", url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if target := gjson.Get(jsonStr, "target").String(); target != "" {
|
if target := gjson.Get(jsonStr, "target").String(); target != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Target"), target))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Target"), target))
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,19 +258,19 @@ func formatCollection(jsonStr string, parts []string, bold, green func(a ...inte
|
||||||
if totalItems := gjson.Get(jsonStr, "totalItems").Int(); totalItems > 0 {
|
if totalItems := gjson.Get(jsonStr, "totalItems").Int(); totalItems > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %d", bold("Total Items"), totalItems))
|
parts = append(parts, fmt.Sprintf("%s: %d", bold("Total Items"), totalItems))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show first few items if available
|
// Show first few items if available
|
||||||
items := gjson.Get(jsonStr, "items").Array()
|
items := gjson.Get(jsonStr, "items").Array()
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
items = gjson.Get(jsonStr, "orderedItems").Array()
|
items = gjson.Get(jsonStr, "orderedItems").Array()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(items) > 0 {
|
if len(items) > 0 {
|
||||||
itemCount := len(items)
|
itemCount := len(items)
|
||||||
if itemCount > 3 {
|
if itemCount > 3 {
|
||||||
itemCount = 3
|
itemCount = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
parts = append(parts, fmt.Sprintf("%s:", bold("First Items")))
|
parts = append(parts, fmt.Sprintf("%s:", bold("First Items")))
|
||||||
for i := 0; i < itemCount; i++ {
|
for i := 0; i < itemCount; i++ {
|
||||||
item := items[i].String()
|
item := items[i].String()
|
||||||
|
@ -261,12 +279,12 @@ func formatCollection(jsonStr string, parts []string, bold, green func(a ...inte
|
||||||
}
|
}
|
||||||
parts = append(parts, fmt.Sprintf(" - %s", item))
|
parts = append(parts, fmt.Sprintf(" - %s", item))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(items) > 3 {
|
if len(items) > 3 {
|
||||||
parts = append(parts, fmt.Sprintf(" ... and %d more items", len(items)-3))
|
parts = append(parts, fmt.Sprintf(" ... and %d more items", len(items)-3))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,23 +293,23 @@ func formatMedia(jsonStr string, parts []string, bold, green func(a ...interface
|
||||||
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), name))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if url := gjson.Get(jsonStr, "url").String(); url != "" {
|
if url := gjson.Get(jsonStr, "url").String(); url != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("URL"), url))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("URL"), url))
|
||||||
}
|
}
|
||||||
|
|
||||||
if duration := gjson.Get(jsonStr, "duration").String(); duration != "" {
|
if duration := gjson.Get(jsonStr, "duration").String(); duration != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Duration"), duration))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Duration"), duration))
|
||||||
}
|
}
|
||||||
|
|
||||||
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
if published := gjson.Get(jsonStr, "published").String(); published != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Published"), formatDate(published)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if attributedTo := gjson.Get(jsonStr, "attributedTo").String(); attributedTo != "" {
|
if attributedTo := gjson.Get(jsonStr, "attributedTo").String(); attributedTo != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Author"), attributedTo))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Author"), attributedTo))
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +318,7 @@ func formatEvent(jsonStr string, parts []string, bold, green func(a ...interface
|
||||||
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
if name := gjson.Get(jsonStr, "name").String(); name != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), name))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Name"), name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if content := gjson.Get(jsonStr, "content").String(); content != "" {
|
if content := gjson.Get(jsonStr, "content").String(); content != "" {
|
||||||
content = stripHTML(content)
|
content = stripHTML(content)
|
||||||
if len(content) > 300 {
|
if len(content) > 300 {
|
||||||
|
@ -308,19 +326,19 @@ func formatEvent(jsonStr string, parts []string, bold, green func(a ...interface
|
||||||
}
|
}
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Description"), content))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Description"), content))
|
||||||
}
|
}
|
||||||
|
|
||||||
if startTime := gjson.Get(jsonStr, "startTime").String(); startTime != "" {
|
if startTime := gjson.Get(jsonStr, "startTime").String(); startTime != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Start Time"), formatDate(startTime)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Start Time"), formatDate(startTime)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if endTime := gjson.Get(jsonStr, "endTime").String(); endTime != "" {
|
if endTime := gjson.Get(jsonStr, "endTime").String(); endTime != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("End Time"), formatDate(endTime)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("End Time"), formatDate(endTime)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if location := gjson.Get(jsonStr, "location").String(); location != "" {
|
if location := gjson.Get(jsonStr, "location").String(); location != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Location"), location))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Location"), location))
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,11 +347,11 @@ func formatTombstone(jsonStr string, parts []string, bold, green func(a ...inter
|
||||||
if formerType := gjson.Get(jsonStr, "formerType").String(); formerType != "" {
|
if formerType := gjson.Get(jsonStr, "formerType").String(); formerType != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Former Type"), formerType))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Former Type"), formerType))
|
||||||
}
|
}
|
||||||
|
|
||||||
if deleted := gjson.Get(jsonStr, "deleted").String(); deleted != "" {
|
if deleted := gjson.Get(jsonStr, "deleted").String(); deleted != "" {
|
||||||
parts = append(parts, fmt.Sprintf("%s: %s", bold("Deleted"), formatDate(deleted)))
|
parts = append(parts, fmt.Sprintf("%s: %s", bold("Deleted"), formatDate(deleted)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +368,7 @@ func formatDate(isoDate string) string {
|
||||||
func stripHTML(html string) string {
|
func stripHTML(html string) string {
|
||||||
// Simple HTML tag stripping - in a real implementation, you might want to use a proper HTML parser
|
// Simple HTML tag stripping - in a real implementation, you might want to use a proper HTML parser
|
||||||
result := html
|
result := html
|
||||||
|
|
||||||
// Replace common HTML entities
|
// Replace common HTML entities
|
||||||
replacements := map[string]string{
|
replacements := map[string]string{
|
||||||
"&": "&",
|
"&": "&",
|
||||||
|
@ -360,29 +378,29 @@ func stripHTML(html string) string {
|
||||||
"'": "'",
|
"'": "'",
|
||||||
" ": " ",
|
" ": " ",
|
||||||
}
|
}
|
||||||
|
|
||||||
for entity, replacement := range replacements {
|
for entity, replacement := range replacements {
|
||||||
result = strings.ReplaceAll(result, entity, replacement)
|
result = strings.ReplaceAll(result, entity, replacement)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove HTML tags
|
// Remove HTML tags
|
||||||
for {
|
for {
|
||||||
startIdx := strings.Index(result, "<")
|
startIdx := strings.Index(result, "<")
|
||||||
if startIdx == -1 {
|
if startIdx == -1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
endIdx := strings.Index(result[startIdx:], ">")
|
endIdx := strings.Index(result[startIdx:], ">")
|
||||||
if endIdx == -1 {
|
if endIdx == -1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result[:startIdx] + result[startIdx+endIdx+1:]
|
result = result[:startIdx] + result[startIdx+endIdx+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize whitespace
|
// Normalize whitespace
|
||||||
result = strings.Join(strings.Fields(result), " ")
|
result = strings.Join(strings.Fields(result), " ")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,15 +409,15 @@ func formatArray(values []gjson.Result) string {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var items []string
|
var items []string
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
items = append(items, v.String())
|
items = append(items, v.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(items) == 1 {
|
if len(items) == 1 {
|
||||||
return items[0]
|
return items[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("[\n %s\n ]", strings.Join(items, ",\n "))
|
return fmt.Sprintf("[\n %s\n ]", strings.Join(items, ",\n "))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue