Skip to content

Commit febfdde

Browse files
committed
fix iframes links for polish books
1 parent 3de85ef commit febfdde

File tree

6 files changed

+82246
-10376
lines changed

6 files changed

+82246
-10376
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
* Fix iframes links for Polish books
910

1011
## [v2.25.1] - 2025-02-25
1112

lib/kitchen/element_base.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,13 +936,13 @@ def rex_link
936936
page_title = ''
937937
page = element_with_ancestors.ancestor(:page) if element_with_ancestors.has_ancestor?(:page)
938938
if page&.is_introduction?
939-
page_title = page.first('[data-type="document-title"]').text.kebab_case
939+
page_title = page.first('[data-type="document-title"]').text.slugify
940940
elsif page
941941
page_string = "#{page.count_in(:chapter) - 1}-"
942-
page_title = page.title_text.kebab_case
942+
page_title = page.title_text.slugify
943943
else
944944
page = element_with_ancestors.ancestor(:composite_page)
945-
page_title = page.title.text.kebab_case
945+
page_title = page.title.text.slugify
946946
end
947947

948948
"https://openstax.org/books/#{book_slug}/pages/#{chapter_count}-#{page_string}#{page_title}"

lib/kitchen/patches/string.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def uncapitalize
1616
#
1717
# @return [String]
1818
#
19-
def kebab_case
20-
strip.downcase.gsub(/®/, ' r').gsub(/[^(\w\s)\-]/, '').gsub(/\s/, '-')
19+
def slugify
20+
I18n.transliterate(
21+
strip.downcase
22+
.gsub(/'/, '')
23+
.gsub(/®/, ' r')
24+
.gsub(/\u2014+/, '-')
25+
).gsub(/[^(\w\s)-]/, '').gsub(/[\s-]+/, '-')
2126
end
2227
end

spec/kitchen_spec/element_base_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,17 @@
656656
</h2>
657657
<div id="element2"></div>
658658
</div>
659+
<div data-type="page">
660+
<div data-type="metadata" style="display: none;">
661+
<h1 data-type="document-title" itemprop="name">I have hyphen — and latin letter ć</h1>
662+
</div>
663+
<h2 data-type="document-title">
664+
<span class="os-number">1.2</span>
665+
<span class="os-divider"> </span>
666+
<span data-type="" itemprop="" class="os-text">I have hyphen — and latin letter ć</span>
667+
</h2>
668+
<div id="element4"></div>
669+
</div>
659670
</div>
660671
<div data-type="chapter">
661672
<div class="os-eoc os-summary-container" data-type="composite-page" data-uuid-key=".summary" id="composite-page-1">
@@ -687,6 +698,11 @@
687698
eq('https://openstax.org/books/test-book-slug/pages/2-summary-or-something')
688699
end
689700

701+
it 'returns rex link for element with hyphen and latin letter' do
702+
expect(book_rex_linkable.first('div#element4').rex_link).to \
703+
eq('https://openstax.org/books/test-book-slug/pages/1-2-i-have-hyphen-and-latin-letter-c')
704+
end
705+
690706
it 'raises error when ancestors can\'t be found' do
691707
expect { book_rex_linkable.pages('$#not-in-chapter').first.rex_link }.to \
692708
raise_error(/Cannot create rex link to element[^>]+id="not-in-chapter"/)

0 commit comments

Comments
 (0)