diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index fbd2195..9341dce 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index a91057b..678b4da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/pkg/app/ask_test.go b/pkg/app/ask_test.go index 7630c4b..f1858fd 100644 --- a/pkg/app/ask_test.go +++ b/pkg/app/ask_test.go @@ -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- John 3:16\n" if env.Res.Message != expected { t.Errorf("Expected search result message, got: %s", env.Res.Message) } diff --git a/pkg/app/passage.go b/pkg/app/passage.go index c3065db..963c6f1 100644 --- a/pkg/app/passage.go +++ b/pkg/app/passage.go @@ -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 @@ -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": diff --git a/pkg/app/passage_test.go b/pkg/app/passage_test.go index 8496fce..13b8662 100644 --- a/pkg/app/passage_test.go +++ b/pkg/app/passage_test.go @@ -141,12 +141,20 @@ func TestParsePassageFromHtml(t *testing.T) { t.Run("HTML with spans", func(t *testing.T) { html := `

Line 1.
Line 2.

` - 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 := `

Line 1
Line 2

` + 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 := `

Line 1.
Line 2.

` expected := "Line 1.\nLine 2." diff --git a/pkg/app/search.go b/pkg/app/search.go index 383d410..c3f68db 100644 --- a/pkg/app/search.go +++ b/pkg/app/search.go @@ -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("- %s\n", res.URL, res.Verse)) + } else { + sb.WriteString(fmt.Sprintf("- %s\n", res.Verse)) + } } env.Res.Message = sb.String() } else { diff --git a/pkg/app/search_test.go b/pkg/app/search_test.go index acbf405..b37c842 100644 --- a/pkg/app/search_test.go +++ b/pkg/app/search_test.go @@ -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 := `- John 3:16` + if !strings.Contains(env.Res.Message, expected) { + t.Errorf("Expected HTML link in response, got: %s", env.Res.Message) + } }) }