Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ jobs:

- name: Docker Build and Stage
run: |
printf "TELEGRAM_ID: \"$TELEGRAM_ID\"\nADMIN_ID: \"$ADMIN_ID\"\nGCLOUD_PROJECT_ID: \"$GCLOUD_PROJECT_ID\"\n" >> secrets.yaml
cat secrets.yaml
docker build --build-arg GCLOUD_PROJECT_ID=$GCLOUD_PROJECT_ID -f Dockerfile -t $GCLOUD_REGION-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest .
docker push $GCLOUD_REGION-docker.pkg.dev/$GCLOUD_PROJECT_ID/$ARTIFACT_ID/root:latest

Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ FROM scratch AS runner
ARG GCLOUD_PROJECT_ID
ENV GCLOUD_PROJECT_ID=$GCLOUD_PROJECT_ID

COPY --from=builder /go/src/app/secrets.yaml /go/bin/secrets.yaml
COPY --from=builder /go/src/app/resource/* /go/bin/
COPY --from=builder /go/bin/main /go/bin/main
COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestGetBibleAsk(t *testing.T) {
env = GetBibleAsk(env)

// Expect fallback to search
expected := "Found 1 results for 'Question':\n- John 3:16\n"
expected := "Found 1 results for 'Question':\n- <a href=\"https://example.com/John3:16\">John 3:16</a>\n"
if env.Res.Message != expected {
t.Errorf("Expected search result message, got: %s", env.Res.Message)
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/app/passage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ func GetReference(doc *html.Node) string {
}


func isNextSiblingBr(node *html.Node) bool {
for next := node.NextSibling; next != nil; next = next.NextSibling {
if next.Type == html.TextNode {
if len(strings.TrimSpace(next.Data)) == 0 {
continue
}
return false
}
if next.Type == html.ElementNode && next.Data == "br" {
return true
}
return false
}
return false
}

func ParseNodesForPassage(node *html.Node) string {
var text string
var parts []string
Expand All @@ -53,7 +69,7 @@ func ParseNodesForPassage(node *html.Node) string {
case "span":
childText := ParseNodesForPassage(child)
parts = append(parts, childText)
if len(strings.TrimSpace(childText)) > 0 {
if len(strings.TrimSpace(childText)) > 0 && !isNextSiblingBr(child) {
parts = append(parts, "\n")
}
case "sup":
Expand Down
10 changes: 9 additions & 1 deletion pkg/app/passage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,20 @@ func TestParsePassageFromHtml(t *testing.T) {

t.Run("HTML with spans", func(t *testing.T) {
html := `<p><span>Line 1.</span><br><span> </span><span>Line 2.</span></p>`
expected := "Line 1.\n\n Line 2."
expected := "Line 1.\n Line 2."
if got := ParsePassageFromHtml("", html, ""); got != expected {
t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected)
}
})

t.Run("Poetry double newline check", func(t *testing.T) {
html := `<p><span>Line 1</span><br><span>Line 2</span></p>`
expected := "Line 1\nLine 2"
if got := ParsePassageFromHtml("", html, ""); got != expected {
t.Errorf("ParsePassageFromHtml() = %q, want %q", got, expected)
}
})

t.Run("HTML with line breaks", func(t *testing.T) {
html := `<p>Line 1.<br>Line 2.</p>`
expected := "Line 1.\nLine 2."
Expand Down
7 changes: 5 additions & 2 deletions pkg/app/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ func GetBibleSearch(env def.SessionData) def.SessionData {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("Found %d results for '%s':\n", len(resp), env.Msg.Message))
for _, res := range resp {
// Format: - Verse (URL)
sb.WriteString(fmt.Sprintf("- %s\n", res.Verse))
if res.URL != "" {
sb.WriteString(fmt.Sprintf("- <a href=\"%s\">%s</a>\n", res.URL, res.Verse))
} else {
sb.WriteString(fmt.Sprintf("- %s\n", res.Verse))
}
}
env.Res.Message = sb.String()
} else {
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,10 @@ func TestGetBibleSearch(t *testing.T) {
if !strings.Contains(env.Res.Message, "Found") && !strings.Contains(env.Res.Message, "No results") {
t.Errorf("Expected result count, got: %s", env.Res.Message)
}

expected := `- <a href="https://example.com/John3:16">John 3:16</a>`
if !strings.Contains(env.Res.Message, expected) {
t.Errorf("Expected HTML link in response, got: %s", env.Res.Message)
}
})
}
Loading