Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Add `v2` of `BakeOrderHeaders` that ensure header levels are not skipped
* Add post bake recipe that runs after the selected recipe
* Remove `BakeOrderHeaders` from web recipe
* Add `BakeOrderHeaders` to post bake recipe that runs for all books

## [v2.29.0] - 2025-09-16

* Create recipe for Polish Nursing book
Expand Down
4 changes: 4 additions & 0 deletions docker/run
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env bash

set -eo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

extra_args=()

# Environment variables we want to send to the container
env_names=(
UPDATE_SNAPSHOTS # rspec will update snapshots if this is set
TRACE_ON
PROFILE
)

for env_name in "${env_names[@]}"; do
Expand Down
17 changes: 17 additions & 0 deletions lib/kitchen/directions/bake_order_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ def self.v1(within:, top_header_value: 2)
header.name = header_map[header.name]
end
end

def self.v2(within:, top_header_value: 1)
last = -1
within.search('h1,h2,h3,h4,h5,h6').each do |header|
depth = header.name[-1].to_i
if last == -1
depth = top_header_value
elsif depth > last + 1
depth = last + 1
end
name = "h#{depth}"
header.name = name
# https://github.com/openstax/rex-web/blob/a3dd80667d6503d6b2eeea0d58c1b775c85b9500/src/app/content/components/Page/contentDOMTransformations.ts#L40
header['data-rex-keep'] = true if name == 'h2' && header['data-type'] == 'document-title'
last = depth
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/recipes/bake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ book_recipes = \

recipe_array = book_recipes
recipe_array.push(WEB_RECIPE) if opts[:platform] == 'web'
recipe_array.push(POST_BAKE)
recipe_array.push(VALIDATE_OUTPUT)

puts Kitchen::Oven.bake(
Expand Down
9 changes: 9 additions & 0 deletions lib/recipes/post_bake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require_relative '../kitchen/book_recipe'

POST_BAKE = Kitchen::BookRecipe.new(book_short_name: :post_bake) do |doc|
book = doc.book

BakeOrderHeaders.v2(within: book)
end
1 change: 1 addition & 0 deletions lib/recipes/recipes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative '../imports_for_recipes'
require 'slop'
require_relative 'validate'
require_relative 'post_bake'

# Takes a block and silences any `puts` from that block
def silenced
Expand Down
2 changes: 0 additions & 2 deletions lib/recipes/web-generic/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# Web directions
BakeImages.v1(book_pages: book_pages, resources: resources)
book_pages.each do |page_or_composite|
BakeOrderHeaders.v1(within: page_or_composite)

page_or_composite.search('[data-type="example"]').each do |example|
BakeExerciseWithTitle.v1(within: example)
end
Expand Down
30 changes: 30 additions & 0 deletions spec/kitchen_spec/directions/bake_order_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,38 @@
).pages.first
end

let(:page_with_random_headers) do
book_containing(html:
one_chapter_with_one_page_containing(
<<~HTML
<h3>The top title within the page</h3>
<div>Body of introduction
<h6>Subtitle</h6>
<p>a paragraph</p>
</div>
<h3 data-type="document-title">wow another header</h3>
<h5>subheader also</h5>
<div><h6>subtitle subtitle</h6><p>paragraph</p>
<h6>here we see a subtitle</h6>
</div>
<h1>The SS Morro Castle was</h1>
<h3>an inside job</h3>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sir we are a textbook company

<h6>(probably)</h6>
<h4>Like, there was a</h4>
<h5>CIA agent on board...</h5>
<h5>I'm just saying</h5>
HTML
)
).pages.first
end

it 'works' do
described_class.v1(within: page_with_headers)
expect(page_with_headers).to match_snapshot_auto
end

it 'works (v2)' do
described_class.v2(within: page_with_random_headers)
expect(page_with_random_headers).to match_snapshot_auto
end
end
84 changes: 42 additions & 42 deletions spec/recipes_spec/books/accounting/expected_output.xhtml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Introduction to Additive Manufacturing
</div>
<div class="intro-body">
<div class="os-chapter-outline">
<h3 class="os-title">Chapter Outline</h3>
<h2 class="os-title">Chapter Outline</h2>
<div class="os-chapter-objective">
<a class="os-chapter-objective" href="#page_b539408f-1736-49e0-b911-3ceaa39c4b4e">
<span class="os-number">1.1</span>
Expand Down Expand Up @@ -196,7 +196,7 @@ Introduction to Additive Manufacturing
</div>
</div>
<div class="intro-text">
<h2 data-type="document-title" data-sm="./modules/m00001/index.cnxml:2:3" id="page_12841ad6-9115-449b-99c2-f2cdf6621061_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00001/index.cnxml:2:3" id="page_12841ad6-9115-449b-99c2-f2cdf6621061_titlecreatedbycookbook" data-rex-keep="true">
<span data-type="" itemprop="" class="os-text">
<span data-type="" itemprop="" class="os-text">Introduction</span>
</span>
Expand Down Expand Up @@ -274,7 +274,7 @@ Introduction to Additive Manufacturing
<span data-type="canonical-book-uuid" data-value="851baf99-d993-44bf-8b4d-5b0cadfe2445"></span>
<span data-type="cnx-archive-uri" data-value="b539408f-1736-49e0-b911-3ceaa39c4b4e@"></span>
</div>
<h2 data-type="document-title" data-sm="./modules/m00002/index.cnxml:2:3" id="page_b539408f-1736-49e0-b911-3ceaa39c4b4e_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00002/index.cnxml:2:3" id="page_b539408f-1736-49e0-b911-3ceaa39c4b4e_titlecreatedbycookbook" data-rex-keep="true">
<span class="os-number">1.1</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">
Expand Down Expand Up @@ -455,7 +455,7 @@ Introduction to Additive Manufacturing
<span data-type="canonical-book-uuid" data-value="851baf99-d993-44bf-8b4d-5b0cadfe2445"></span>
<span data-type="cnx-archive-uri" data-value="ff1e599f-36e0-4276-9079-1f36a4591333@"></span>
</div>
<h2 data-type="document-title" data-sm="./modules/m00003/index.cnxml:2:3" id="page_ff1e599f-36e0-4276-9079-1f36a4591333_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00003/index.cnxml:2:3" id="page_ff1e599f-36e0-4276-9079-1f36a4591333_titlecreatedbycookbook" data-rex-keep="true">
<span class="os-number">1.2</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">
Expand Down Expand Up @@ -650,7 +650,7 @@ Introduction to Additive Manufacturing
<span data-type="canonical-book-uuid" data-value="851baf99-d993-44bf-8b4d-5b0cadfe2445"></span>
<span data-type="cnx-archive-uri" data-value="c2a83532-de3b-4068-848e-40af48db7389@"></span>
</div>
<h2 data-type="document-title" data-sm="./modules/m00004/index.cnxml:2:3" id="page_c2a83532-de3b-4068-848e-40af48db7389_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00004/index.cnxml:2:3" id="page_c2a83532-de3b-4068-848e-40af48db7389_titlecreatedbycookbook" data-rex-keep="true">
<span class="os-number">1.3</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">
Expand Down Expand Up @@ -743,7 +743,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
<span data-type="canonical-book-uuid" data-value="851baf99-d993-44bf-8b4d-5b0cadfe2445"></span>
<span data-type="cnx-archive-uri" data-value="0f704a0a-8ea4-4409-9af7-97f5734a547d@"></span>
</div>
<h2 data-type="document-title" data-sm="./modules/m00005/index.cnxml:2:3" id="page_0f704a0a-8ea4-4409-9af7-97f5734a547d_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00005/index.cnxml:2:3" id="page_0f704a0a-8ea4-4409-9af7-97f5734a547d_titlecreatedbycookbook" data-rex-keep="true">
<span class="os-number">1.4</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">
Expand Down Expand Up @@ -893,7 +893,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
<span data-type="canonical-book-uuid" data-value="851baf99-d993-44bf-8b4d-5b0cadfe2445"></span>
<span data-type="cnx-archive-uri" data-value="ea1fab58-2057-4c8f-b791-6d31e9b18ad4@"></span>
</div>
<h2 data-type="document-title" data-sm="./modules/m00006/index.cnxml:2:3" id="page_ea1fab58-2057-4c8f-b791-6d31e9b18ad4_titlecreatedbycookbook">
<h2 data-type="document-title" data-sm="./modules/m00006/index.cnxml:2:3" id="page_ea1fab58-2057-4c8f-b791-6d31e9b18ad4_titlecreatedbycookbook" data-rex-keep="true">
<span class="os-number">1.5</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">
Expand Down Expand Up @@ -1229,7 +1229,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
</section>
</div>
<div class="os-eoc os-free-response-container" data-type="composite-page" data-uuid-key=".free-response" id="composite-page-1">
<h2 data-type="document-title">
<h2 data-type="document-title" data-rex-keep="true">
<span class="os-text">Discussion Questions</span>
</h2>
<div data-type="metadata" style="display: none;">
Expand Down Expand Up @@ -1297,7 +1297,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
</section>
</div>
<div class="os-eoc os-solutions-container" data-type="composite-page" data-uuid-key="solutions" id="composite-page-2">
<h2 data-type="document-title">
<h2 data-type="document-title" data-rex-keep="true">
<span class="os-text">Solutions</span>
</h2>
<div data-type="metadata" style="display: none;">
Expand All @@ -1313,7 +1313,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
</div>
</div>
<div class="os-eoc os-summary-container" data-type="composite-page" data-uuid-key=".summary" id="composite-page-3">
<h2 data-type="document-title">
<h2 data-type="document-title" data-rex-keep="true">
<span class="os-text">Summary</span>
</h2>
<div data-type="metadata" style="display: none;">
Expand All @@ -1334,7 +1334,7 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
</section>
</div>
<div class="os-eoc os-key-terms-container" data-type="composite-page" data-uuid-key=".key-terms" id="composite-page-4">
<h2 data-type="document-title">
<h2 data-type="document-title" data-rex-keep="true">
<span class="os-text">Key Terms</span>
</h2>
<div data-type="metadata" style="display: none;">
Expand All @@ -1350,15 +1350,15 @@ Layer &#x2013; The layer is made by selectively and precisely depositing the mat
</div>
<section data-depth="2" class="key-terms" id="auto_b539408f-1736-49e0-b911-3ceaa39c4b4e_sect-00002" data-sm="./modules/m00002/index.cnxml:56:1">
<a href="#page_ff1e599f-36e0-4276-9079-1f36a4591333_titlecreatedbycookbook">
<h3 data-type="document-title">
<h2 data-type="document-title" data-rex-keep="true">
<span class="os-number">1.2</span>
<span class="os-divider"> </span>
<span class="os-text" data-type="" itemprop="">
<span class="os-number">1.2</span>
<span class="os-divider"> </span>
<span data-type="" itemprop="" class="os-text">Core AM Concepts</span>
</span>
</h3>
</h2>
</a>
<span data-type="list" data-list-type="bulleted" id="auto_b539408f-1736-49e0-b911-3ceaa39c4b4e_list-00002" data-display="inline" data-sm="./modules/m00002/index.cnxml:57:7">
<span data-type="item" data-sm="./modules/m00002/index.cnxml:57:46">STL</span>
Expand Down
Loading