Skip to content

Commit

Permalink
fix: [ST-2294] Hreflangs are inserted for pages that don't need trans…
Browse files Browse the repository at this point in the history
…lation (#234)

* fix: Hreflangs are inserted for pages that don't need translation

* chore: Bump version

* test: Minor refactor
  • Loading branch information
bryanzerrudo authored Aug 24, 2023
1 parent 498d61e commit 957a552
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/wovnrb/services/html_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def inject_lang_html_tag

def replace_hreflangs
strip_hreflang_tags
insert_hreflang_tags
insert_hreflang_tags if @store.settings['insert_hreflangs']
end

def strip_hreflang_tags
Expand Down
2 changes: 1 addition & 1 deletion lib/wovnrb/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wovnrb
VERSION = '3.10.0'.freeze
VERSION = '3.10.1'.freeze
end
29 changes: 20 additions & 9 deletions test/lib/services/html_converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,26 @@ class HtmlConverterTest < WovnMiniTest
assert(translated_html.include?(expected_html))
end

test 'build API compatible html - with insert_hreflangs: false - hreflangs are not added' do
settings = default_store_settings
settings['insert_hreflangs'] = false
converter = prepare_html_converter('<html><body><a>hello</a></body></html>', settings)
converted_html, = converter.build_api_compatible_html

expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"https://j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&amp;backend=true&amp;currentLang=en&amp;defaultLang=en&amp;urlPattern=query&amp;langCodeAliases={}&amp;langParamName=wovn&amp;version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body><a>hello</a></body></html>"
assert_equal(expected_html, converted_html)
end

test 'Transform HTML - with insert_hreflangs: false - hreflangs are not added' do
settings = default_store_settings
settings['insert_hreflangs'] = false
converter = prepare_html_converter('<html><body><a>hello</a></body></html>', settings)
translated_html = converter.build

expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"https://j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&amp;backend=true&amp;currentLang=en&amp;defaultLang=en&amp;urlPattern=query&amp;langCodeAliases={}&amp;langParamName=wovn&amp;version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body><a>hello</a></body></html>"
assert_equal(expected_html, translated_html)
end

private

def prepare_html_converter(input_html, store_options = {})
Expand All @@ -474,15 +494,6 @@ def store_headers_factory(setting_opts = {}, url = 'http://my-site.com')
[store, headers]
end

test 'build API compatible html - with insert_hreflangs: false' do
settings = { insert_hreflangs: false }
converter = prepare_html_converter('<html><body><a class="test">hello</a></body></html>', settings)
converted_html, = converter.build_api_compatible_html

expected_html = "<html lang=\"en\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><script src=\"https://j.wovn.io/1\" async=\"true\" data-wovnio=\"key=123456&amp;backend=true&amp;currentLang=en&amp;defaultLang=en&amp;urlPattern=query&amp;langCodeAliases={}&amp;langParamName=wovn&amp;version=WOVN.rb_#{VERSION}\" data-wovnio-type=\"fallback_snippet\"></script></head><body><a class=\"test\">hello</a></body></html>"
assert_equal(expected_html, converted_html)
end

def default_store_settings
{
'project_token' => '123456',
Expand Down

0 comments on commit 957a552

Please sign in to comment.